GNU   davin.50webs.com/research
Bringing to you notes for the ages

       Main Menu          Research Projects         Photo Album            Curriculum Vitae      The Greatest Artists
    Email Address       Computer Games          Web Design          Java Training Wheels      The Fly (A Story)   
  Political Activism   Scruff the Cat       My Life Story          Smoking Cessation          Other Links      
Debugging Macros     String Class I     Linked List System I Java for C Programmers Naming Convention
    String Class II         How I use m4              Strings III                 Symmetrical I/O             Linked Lists II     
Run-Time Type Info   Virtual Methods      An Array System        Science & Religion            Submodes       
  Nested Packages      Memory Leaks    Garbage Collection      Internet & Poverty      What is Knowledge?
Limits of Evolution   Emacs Additions      Function Plotter           Romantic Love        The Next Big Thing
    Science Fiction     Faster Compilation Theory of Morality         Elisp Scoping               Elisp Advice      
  S.O.G.M. Pattern       Safe Properties         School Bullying          Charisma Control          Life and Death    
     Splitting Java          Multiple Ctors       Religious Beliefs         Conversation 1           Conversation 2    
   J.T.W. language    Emacs Additions II      Build Counter             Relation Plotter          Lisp++ Language  
  Memory Leaks II   Super Constructors CRUD Implementation Order a Website Form There Is An Afterlife
More Occam's Razor C to Java Translator Theory of Morality II


lisp++-mode.el

    








;;; lisp++-mode.el --- A new major mode for editing *.lisp++ files

;; Copyright (C) 2016 Davin Pearson

;; Maintainer: Davin Max Pearson <http://davin.50webs.com>
;; Keywords: Lisp++ major mode
;; Version: 2.0

;;; Commentary:

;; This program is part of the Lisp++ programming language.

;;; Limitation of Warranty

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or (at
;; your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more detail.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs, see the file COPYING.  If not, see:
;;
;; <http://www.gnu.org/licenses/gpl-3.0.txt>.


;;; Install Instructions:
;; See the following URL for the latest info and a tarball:
;;
;; <http://davin.50webs.com/research/2010/mopa2e2.html#lisp++-mode>
;;
;; Then untar the tarball to a folder pointed to by the Emacs variable
;; load-path and add the following line to your ~/.emacs file.
;;
;; (require 'lisp++-mode)

;;; Code:

(require 'early-bindings)
(require 'cc-mode)

(d-assert (boundp 'c++-mode-syntax-table))

(defvar lisp++-mode-syntax-table
  (make-syntax-table (copy-syntax-table c++-mode-syntax-table)))

(defvar lisp++-mode-map
  (make-keymap))

(defun lisp++-mode ()
  (interactive)
  ;;(message "Entering lisp++-mode")
  (kill-all-local-variables)
  (c++-mode)
  (setq major-mode 'lisp++-mode)
  (setq mode-name "Lisp++")
  (set-syntax-table lisp++-mode-syntax-table)
  (modify-syntax-entry ?_ "w")
  (modify-syntax-entry ?- "w")
  (modify-syntax-entry ?* "w")
  (use-local-map lisp++-mode-map)
  ;;(message "cp1")
  (modify-syntax-entry ?\  " ")
  (when prefs-davins-keybindings-online-p
    (local-set-key "\t"                'lisp++-tab)
    (local-set-key "\r"                'd-indent-new-comment-line)
    (local-set-key [(meta control \\)] 'indent-region)
    (local-set-key "\C-c\C-c"          'd-cc--comment-region))
  ;;(message "cp3")
  (abbrev-mode 1)
  (setq local-abbrev-table c++-mode-abbrev-table)
  (make-local-variable 'font-lock-keywords)
  (font-lock-mode 1)
  (when prefs-davins-keybindings-online-p
    (local-set-key [delete] 'delete-char)
    ;;(message "Leaving lisp++-mode")
    ))

(add-hook 'font-lock-mode-hook 'lisp++-font-lock-mode-hook)

(defun lisp++-tab ()
  (interactive)
  (indent-for-tab-command))

(defun lisp++-font-lock-mode-hook ()

(when prefs-maximal-syntax-highlighting-p

(when (eq major-mode 'lisp++-mode)
      (d-font-lock-add-begin
       '(
         ("(\\(cnamespace\\) \\([a-zA-Z0-9_]+\\)"
          (1 'lisp++-face-keywords nil)
          (2 'fg:lightred          nil)
          )
         ("(\\(getter\\|setter\\|foreach\\|singleton_design_pattern\\)\\>"
          (1 'fg:orange nil))
         )))

(when (or (eq major-mode 'c++-mode)
              (eq major-mode 'lisp++-mode))
      (d-font-lock-add-end
       '(
         ("^[ \t]+.*\\<[A-Z][a-zA-Z0-9_]*::\\([a-z][a-zA-Z0-9_]*\\)(" 1 default nil)
         ("::\\(ctor\\)(" 1 fg:lightmagenta t)
         )))

(when (or (eq major-mode 'emacs-lisp-mode)
              (eq major-mode 'lisp++-mode)
              (eq major-mode 'text-mode))
      (d-font-lock-add-end
       '(
         ("\\(\\<cpause\\);"              1 'lisp++-face-keywords nil)
         ("\\<red[-a-zA-Z0-9_]*"          0 'lisp++-face-red nil)
         ("\\<\\(cpause\\|cinline\\)\\>"  1 'lisp++-face-keywords t)
         )
       ))

(when (or (eq major-mode 'emacs-lisp-mode)
              (eq major-mode 'lisp++-mode)
              (eq major-mode 'text-mode)
              (eq major-mode 'c++-mode)
              )
      (modify-syntax-entry ?_ "w")
      (modify-syntax-entry ?- "w")
      (modify-syntax-entry ?+ "w")
      (d-font-lock-add-begin
       `(
         ("(\\(cfunction\\).*(cname \\([^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-function-name-face nil)
          )

;;("(\\(cnamespace\\) \\([A-Za-z][a-zA-Z0-9_]*\\)"
         ;; (1 lisp++-face-keywords nil)
         ;; (2 fg:lightred nil))

         ;;("(cname \\(operator\\)[ \t]*\\([^ ]*\\))"
         ;; (1 bold t)
         ;; (2 font-lock-function-name-face t))
         ;;("(cname \\([^_][^()]+\\))"          1 font-lock-function-name-face t)
         ;;("(cname \\(_[a-z][a-zA-Z0-9_]*\\))" 1 d-face-cc-private t)

         ("\\<debug-[a-z-]*\\>"               0 lisp++-face-illegal-type nil)

("^[ \t]*(\\(cmethod\\).*(ctype \\([^()]*\\)).*(cname \\([^_][^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-type-face          nil)
          (3 font-lock-function-name-face nil)
          )

("^[ \t]*(\\(cmethod\\).*(ctype \\([^()]*\\)).*(cname \\(_[^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-type-face          nil)
          (3 d-face-cc-private            nil)
          )

("^[ \t]*(\\(c-static-method\\).*(ctype \\([a-zA-Z0-9_<>]+[&*]*\\)).*(cname \\([^_][^()]+\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-type-face          nil)
          (3 font-lock-function-name-face nil)
          )

("^[ \t]*(\\(c-static-method\\).*(ctype \\([a-zA-Z0-9_<>]+[&*]*\\)).*(cname \\(_[^()]+\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-type-face          nil)
          (3 d-face-cc-private            nil)
          )

("^[ \t]*(\\(cfriend\\).*(cname \\([^_][^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-function-name-face nil)
          )

("^[ \t]*(\\(cfriend\\).*(cname \\(_[^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 d-face-cc-private            nil)
          )

("^[ \t]*(\\(c-constructor-method\\).*(cname \\([^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-function-name-face nil)
          )

("^[ \t]*(\\(c-destructor-method\\).*(cname \\([^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-function-name-face nil)
          )

("^[ \t]*(\\(cproperty\\).*(ctype \\([^()]*\\)).*(cname \\([^_][^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-type-face          nil)
          (3 font-lock-variable-name-face nil))

("^[ \t]*(\\(cproperty\\).*(ctype \\([^()]*\\)).*(cname \\(_[^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-type-face          nil)
          (3 d-face-cc-private            nil)
          )

("^[ \t]*(\\(c-static-property\\).*(ctype \\([^()]*\\)).*(cname \\([^_][^()]*\\))"
          (1 'lisp++-face-keywords         nil)
          (2 'font-lock-type-face          nil)
          (3 'font-lock-variable-name-face nil))

("^[ \t]*(\\(c-static-property\\).*(ctype \\([^()]*\\)).*(cname \\(_[^()]*\\))"
          (1 'lisp++-face-keywords         nil)
          (2 'font-lock-type-face          nil)
          (3 'd-face-cc-private            nil))

("^[ \t]*(\\(cglobal\\).*(ctype \\([^()]*\\)).*(cname \\([^_][^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-type-face          nil)
          (3 font-lock-variable-name-face nil))

("^[ \t]*(\\(cglobal\\).*(ctype \\([^()]*\\)).*(cname \\(_[^()]*\\))"
          (1 lisp++-face-keywords         nil)
          (2 font-lock-type-face          nil)
          (3 d-face-cc-private            nil))

(,(concat "\\<\\(c-public-extends\\|"
                   "c-private-extends\\|"
                   "c-protected-extends\\)\\>;?"
                   "\\([^()\t\r\n]*\\))")
          (1 lisp++-face-keywords nil)
          (2 font-lock-type-face  nil))

("\\<slot[a-zA-Z0-9-]*" 0 'lisp++-face-property nil)

("\\<\\(cstr\\|cstr-reduced\\|cstr-new\\|cstr-progn\\)\\>"
          0 'lisp++-face-property nil)

("\\<c-[-a-zA-Z0-9_+]+" 0 lisp++-face-keywords nil)

("(carg .* \\([a-zA-Z_][a-zA-Z0-9_<>]*\\))"
          1 font-lock-variable-name-face nil)

("\\(c-basic-offset\\|c-mode\\|c-call\\|c-mode-syntax-table\\)" 0 default t)

(,(concat "\\(^\\|[]['() ]\\)\\(cautogc[-a-z]*\\|cdefine\\|"
                   "cbrackets\\|ccallback\\|ccomment\\|cfptr\\|cargs?\\|cassert\\|"
                   "cclass\\|CASSERT\\|chead\\|cbody\\|cdecl\\|cdo\\|"
                   "cenum\\|cinit\\|citems\\|citem\\|"
                   "cif[?]\\|cif\\|celseif\\|celse\\|cinclude\\|"
                   "cfor\\|cglobal\\|cequals\\|cmodifier\\|"
                   "carray\\|cred\\|cname\\|cpublic\\|cnamespace\\|clet\\*?\\|"
                   "cprivate\\|cprotected\\|cprogn\\|cprogn[-a-z]*\\|"
                   "cstatic\\|ctype\\|cabstract\\|cvirtual\\(-dtor\\)?\\|"
                   "cforever\\|c-raw-c\\+\\+\\|c-raw-h\\+\\+\\|"
                   "cmethod\\|cfunction\\|cglobal\\|c-raw-global-h\\+\\+\\|"
                   "ctypedef\\|cswitch\\|cvariable\\|cwhile\\)\\>")
          2 lisp++-face-keywords nil)

("\\<clet[*]*[ \t]+" 0 lisp++-face-keywords nil)
         ("\\<sc\\>"          0 lisp++-face-keywords nil)
         ("\\<nl\\>"          0 lisp++-face-keywords nil)

("(ctype[ \t]*[a-zA-Z0-9_ &*<>]* \\([a-zA-Z_][a-zA-Z0-9_]*\\))"
          1 font-lock-type-face nil)

("(ctype\\([^()]*\\))" 1 font-lock-type-face nil)

(,(concat "(ctype[^()]*)[ \t]*\\([a-zA-Z_][a-zA-Z0-9_]*::\\)?"
                   "\\(~?[A-Z][a-zA-Z0-9_:]+\\)")
          2 font-lock-type-face nil)

("(ctype \\(~?[A-Za-z0-9_]*\\))" 1 font-lock-type-face nil)

("(\\(cclass\\)[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
          (1 lisp++-face-keywords nil)
          (2 font-lock-type-face  nil))

("\\([a-zA-Z_][a-zA-Z0-9_]*\\)(carg" 1 font-lock-function-name-face nil)

;;("\\(operator\\)[ \t]*\\([^ ]*\\)(carg"
         ;; (1 font-lock-keyword-face nil)
         ;; (2 font-lock-function-name-face nil))

         ;;("(\\(cproperty\\|c-static-property\\).* \\([a-zA-Z_][a-zA-Z0-9_]*\\))"
         ;; (1 lisp++-face-keywords         t)
         ;; (2 font-lock-variable-name-face t))

         ("<\\(class\\) \\([a-zA-Z_][a-zA-Z0-9_]*\\)>"
          (1 font-lock-keyword-face nil)
          (2 font-lock-type-face    nil))

("^\\(cinclude\\)(\\([^()]*\\))"
          (1 font-lock-function-name-face t)
          (2 bold t))

("\\<char[&*]*[ \t]"   0 font-lock-type-face nil)
         ("\\<int[&*]*[ \t]"    0 font-lock-type-face nil)
         ("\\<double[&*]*[ \t]" 0 font-lock-type-face nil)
         ("\\<float[&*]*[ \t]"  0 font-lock-type-face nil)
         ("\\([ :]\\|[^a-zA-Z0-9_]\\)\\(ctor[a-zA-Z0-9_]*\\)(" 2 lisp++-face-ctor nil)
         ("\\<null\\>"             0 fg:lightred nil)
         ("\\<casto_[a-zA-Z0-9_]*" 0 fg:lightred nil)
         )))

(when (or (eq major-mode 'emacs-lisp-mode)
              (eq major-mode 'lisp++-mode))
      (d-font-lock-add-begin
       '(
         ;;("[ \t\r\n()]\\(s\\)[ \t\r\n]" 1 lisp++-face-keywords nil)
         ;;("[ \t\r\n()]\\(f\\)[ \t\r\n]" 1 lisp++-face-keywords nil)
         ("\\<\\(s\\)\\>" 1 lisp++-face-keywords nil)
         ("\\<\\(f\\)\\>" 1 lisp++-face-keywords nil)
         )))

(when (or (eq major-mode 'emacs-lisp-mode)
              (eq major-mode 'lisp++-mode))
      (d-font-lock-add-end
       `(
         (,(concat "\\(\\<\\(bool\\|v3d\\|v3i\\|xyd\\|xyi\\|int\\|float\\|double\\|"
                   "ptr<[a-zA-Z0-9_<]+[ >]*\\)[&*]*\\) \\([a-zA-Z0-9_]*\\)")
          (1 font-lock-type-face          nil)
          (3 font-lock-variable-name-face nil))
         )))

(when (or (eq major-mode 'emacs-lisp-mode)
              (eq major-mode 'lisp++-mode)
              (eq major-mode 'c++-mode))
      (d-font-lock-add-end
       '(
         ;;("(\\(cfunction\\) (ctype .*) (cname \\([a-zA-Z_][a-zA-Z0-9_]*\\))"
         ;; (1 lisp++-face-keywords         nil)
         ;; (2 font-lock-function-name-face t)
         ;;)

         ;;("(\\(cmethod\\) (ctype .*) (cname \\([a-zA-Z_][a-zA-Z0-9_]*\\))"
         ;;   (1 lisp++-face-keywords nil)
         ;;   (2 font-lock-function-name-face nil)
         ;;   )

         ;;("(\\(c-static-method\\) (ctype .*) (cname \\([a-zA-Z_][a-zA-Z0-9_]*\\))"
         ;;   (1 lisp++-face-keywords nil)
         ;;   (2 font-lock-function-name-face nil)
         ;;   )
         ;;("(\\(cfriend\\) (ctype .*) (cname \\([a-zA-Z_][a-zA-Z0-9_]*\\))"
         ;;   (1 lisp++-face-keywords nil)
         ;;   (2 font-lock-function-name-face nil)
         ;;   )

         ;;("\\<\\(cproperty\\|c-static-property\\|cmethod\\|c-static-method\\|c-super-for\\)\\>" 1 lisp++-face-keywords nil)
         ("\\(c-raw-global-h\\+\\+\\)"                                             1 lisp++-face-keywords nil)
         ("(\\(cargs\\|cinit\\|ctype\\|cname\\)\\>"                                1 lisp++-face-keywords nil)
         ("\\<\\(s\\) .*)"                                                         1 lisp++-face-keywords nil)
         ("\\<\\(cpublic\\|cprotected\\|cprivate\\)\\>"                            1 lisp++-face-keywords nil)
         ("\\<\\(c-public-extends\\|c-private-extends\\|c-protected-extends\\)\\>" 1 lisp++-face-keywords nil)
         ("\\(cclass\\)[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\>"
          (1 lisp++-face-keywords nil)
          (2 font-lock-type-face  nil))
         ("\\<class-[a-z-]*\\>"          0 'lisp++-face-keywords nil)
         ("\\<meth\\(od\\)?-[a-z-]*\\>"  0 'lisp++-face-keywords nil)
         ("\\<cinline\\>"                0 lisp++-face-keywords nil)
         )))

(if (or (eq major-mode 'c++-mode)
            (eq major-mode 'lisp++-mode))
        (d-font-lock-add-end
         '(
           ("^[ \t]*//.*$" 0 font-lock-comment-face t))))

(if (or (eq major-mode 'lisp++-mode)
            (eq major-mode 'emacs-lisp-mode))
        (d-font-lock-add-end
         `(
           (, (format "^[ \t]*%c%c.*$" ?\; ?\;) 0 font-lock-comment-face t))))

(if (eq major-mode 'lisp++-mode)
        (d-font-lock-add-end
         '(
           ("\\<\\(downto\\|to\\|step\\)\\>" 1 lisp++-face-keywords nil)
           )))

(if (eq major-mode 'emacs-lisp-mode)
        (d-font-lock-add-end
         `(
           (, (format "^[ \t]*%c%c%c.*$" ?\; ?\; ?\;) d-face-super-comment t))))

(if (eq major-mode 'lisp++-mode)
        (d-font-lock-add-end
         '(
           ("\\<[0-9]+\\>" 0 'dc-face-cc-digits nil))))

)
  )

(defun lisp++-font-lock-mode-hook-2 ()
  (when prefs-maximal-syntax-highlighting-p
    (if (or (eq major-mode 'c++-mode)
            (eq major-mode 'lisp++-mode)
            (eq major-mode 'emacs-lisp-mode))
        (d-font-lock-add-end
         '(
           ("^[ \t]*//.*$"                    0 font-lock-comment-face nil)
           ("^[ \t]*///.*$"                   0 d-face-super-comment   nil)
           ("\\<c-super-for\\>"               0 lisp++-face-keywords   nil)
           ("\\<c-for-each\\>"                0 lisp++-face-keywords   nil)
           ("\\<c-for-list\\>"                0 lisp++-face-keywords   nil)
           ("\\<c-for-list-backwards\\>"      0 lisp++-face-keywords   nil)
           ("\\<\\(cproperty\\|cfriend\\)\\>" 0 lisp++-face-keywords   nil)
           ("(\\([a-z_]*_design_pattern\\)"   1 'd-face-defmacro nil)
           )
         )
      )
    )
  (font-lock-fontify-buffer)
  )

(add-hook 'font-lock-mode-hook 'lisp++-font-lock-mode-hook-2)

(require 'd-make-face)

(defun lisp++-mode-syntax-highlighting ()
  (d-make-face lisp++-face-red bg-colour  "#f33" :bold)
  (d-make-face lisp++-face-illegal-type "#0ff" "#f00" :bold)
  (d-make-face lisp++-face-keywords bg-colour  "#0c0" :bold)
  (d-make-face lisp++-face-ctor bg-colour      "#f0f" :bold)
  (d-make-face lisp++-face-property bg-colour  "#f80" :bold)
  (d-make-face fg:lightred bg-colour           "#f00")
  (d-make-face d-face-cc-private        "#f00" "#fff")
  (d-make-face d-face-cc-global nil (if prefs-bg-black-p "#0c0" "#0c0") :bold)
  )

(setq auto-mode-alist (append '(("\\.lisp\\+\\+$" . lisp++-mode)
                                ("\\.temp$"       . c++-mode))
                            auto-mode-alist))

(provide 'lisp++-mode)
Back
| Main Menu | Research Projects | Photo Album | Curriculum Vitae | The Greatest Artists |
| Email Address | Computer Games | Web Design | Java Training Wheels | The Fly (A Story) |
| Political Activism | Scruff the Cat | My Life Story | Smoking Cessation | Other Links |
| Debugging Macros | String Class I | Linked List System I | Java for C Programmers | Naming Convention |
| String Class II | How I use m4 | Strings III | Symmetrical I/O | Linked Lists II |
| Run-Time Type Info | Virtual Methods | An Array System | Science & Religion | Submodes |
| Nested Packages | Memory Leaks | Garbage Collection | Internet & Poverty | What is Knowledge? |
| Limits of Evolution | Emacs Additions | Function Plotter | Romantic Love | The Next Big Thing |
| Science Fiction | Faster Compilation | Theory of Morality | Elisp Scoping | Elisp Advice |
| S.O.G.M. Pattern | Safe Properties | School Bullying | Charisma Control | Life and Death |
| Splitting Java | Multiple Ctors | Religious Beliefs | Conversation 1 | Conversation 2 |
| J.T.W. language | Emacs Additions II | Build Counter | Relation Plotter | Lisp++ Language |
| Memory Leaks II | Super Constructors | CRUD Implementation | Order a Website Form | There Is An Afterlife |
| More Occam's Razor | C to Java Translator | Theory of Morality II
Last modified: Mon May 6 01:57:11 NZST 2019
Best viewed at 800x600 or above resolution.
© Copyright 1999-2019 Davin Pearson.
Please report any broken links to