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