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   Bob Dylan Quotes+       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:

(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 ?\  " ")
  (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)
  ;;(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 ()

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

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

  (if (eq major-mode 'c++-mode)
      (d-font-lock-add-begin
        '(
          ;;("\\(\\<cpause\\);" 1 lisp++-keywords nil)
          ("\\<red_[a-zA-Z0-9_]*"       0 lisp++-face-lightred nil)
          ("\\<\\(cpause\\|cinline\\)"  1 lisp++-face-keywords nil)
         )
       ))

  (when (or (eq major-mode 'emacs-lisp-mode)
            (eq major-mode 'text-mode)
            (eq major-mode 'c++-mode)
            (eq major-mode 'lisp++-mode))
    (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 t)
        (2 fg:lightred t))

       ;;("(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\\).*(cret \\([^()]*\\)).*(cname \\([^()]*\\))"
        (1 lisp++-face-keywords         nil)
        (2 font-lock-type-face          nil)
        (3 font-lock-function-name-face nil)
        )

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

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

       ("^[ \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         t)
        (2 'font-lock-type-face          t)
        (3 'font-lock-variable-name-face t))

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

       (,(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)

       ("\\*[a-zA-Z][-a-zA-Z0-9 +<>:!]+\\*" 0 d-face-cc-global nil)

       (,(concat "\\(^\\|['() ]\\)\\(cautogc[-a-z]*\\|cdefine\\|"
                 "cbrackets\\|ccallback\\|ccomment\\|cfptr\\|cargs?\\|cassert\\|"
                 "cnamespace\\|cclass\\|CASSERT\\|chead\\|cbody\\|cdecl\\|cdo\\|"
                 "cenum\\|cinit\\|citems\\|citem\\|"
                 "cif[?]\\|cif\\|celseif\\|celse\\|cinclude\\|"
                 "cfor\\|cglobal\\|cequals\\|"
                 "carray\\|cred\\|cname\\|cpublic\\|"
                 "cprivate\\|cprotected\\|cprogn\\|cprogn[-a-z]*\\|"
                 "cstatic\\|cret\\|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 t)

       ;;("\\<c-static-property\\>" 0 lisp++-face-keywords nil)

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

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

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

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

       ("(cret \\(~?[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 t)

       ;;("\\(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 t)
        (2 font-lock-type-face    t))

       ("^\\(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
     '(
       ("[^a-zA-Z0-9_-]\\(s\\)[^a-zA-Z0-9_-]" 1 lisp++-face-keywords nil)
       ("[^a-zA-Z0-9_-]\\(f\\)[^a-zA-Z0-9_-]" 1 lisp++-face-keywords nil)
       )))

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

       ("\\<f\\>" 0 lisp++-face-keywords t)
       )))

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

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

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

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

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

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

  (if (string-match "\\.lisp\\+\\+$" (buffer-name))
      (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 'd-face-cc-digits t))))

  )

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

  (if (or (eq major-mode 'c++-mode)
          (eq major-mode 'emacs-lisp-mode))
      (d-font-lock-add-begin
       '(
         ("^[ \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)
         )
       )
    )
  (font-lock-fontify-buffer)
  )

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

(make-face 'lisp++-face-lightred)
(set-face-foreground 'lisp++-face-lightred "#f33")
(make-face-bold 'lisp++-face-lightred)
(setq lisp++-face-lightred 'lisp++-face-lightred)

(make-face 'lisp++-face-illegal-type)
(set-face-foreground 'lisp++-face-illegal-type "#f00")
(set-face-background 'lisp++-face-illegal-type "#0ff")
(make-face-bold 'lisp++-face-illegal-type)
(setq lisp++-face-illegal-type 'lisp++-face-illegal-type)

(make-face 'lisp++-face-keywords)
(set-face-foreground 'lisp++-face-keywords "#0c0")
;;(set-face-background 'lisp++-face-keywords bg-colour)
(make-face-bold 'lisp++-face-keywords)
(setq lisp++-face-keywords 'lisp++-face-keywords)

(make-face 'lisp++-face-ctor)
(set-face-foreground 'lisp++-face-ctor "#f0f")
(make-face-bold 'lisp++-face-ctor)
(setq lisp++-face-ctor 'lisp++-face-ctor)

(make-face 'lisp++-face-property)
(set-face-foreground 'lisp++-face-property "#f80")
(make-face-bold 'lisp++-face-property)
(setq lisp++-face-property 'lisp++-face-property)

(setq fg:lightred 'fg:lightred)
(setq d-face-cc-private 'd-face-cc-private)

;;(message "Farticus")

(setq auto-mode-alist (append '(("\\.lisp\\+\\+$" . lisp++-mode)
                                ("\\.temp$"       . lisp++-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 | Bob Dylan Quotes+ | 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: Sat Apr 29 18:35:59 NZST 2017
Best viewed at 800x600 or above resolution.
© Copyright 1999-2017 Davin Pearson.
Please report any broken links to