Emacs mode
From CometPublic
Sebastien Mouthuy has provided an emacs mode for editing Comet code, based on Java mode. I have, alas, been unable to determine how MediaWiki handles attachments, so am simply incorporating the emacs-lisp code below:
(defconst opl-keywords
'( "notify" "do" "endl" "solve" "forall" "var" "search" "in" "with" "new"
"call" "continue" "select" "if" "else"
"break" "return" "while" "cout" "when" "whenever" "foreveron" "super" "instanceof")
"List of all OPL keywords with identifier syntax.")
(defconst opl-types
'("int" "set" "range" "tuple" "float" "ConstraintSystem"
"LocalSolver" "string" "bool" "dict" "all" )
"List of all OPL types with identifier syntax.")
(defconst comet-builtins
'( "inter" "union" "\\" "collect" "setof" "argMin" "argMax" "sum" "selectMin" "selectMax" "max" "min" )
"List of all COMET builtins with identifier syntax.")
(defconst opl-consts
'("null" )
"List of all OPL constants with identifier syntax.")
(defconst opl-keyword-matcher
(concat "\\<\\(" (regexp-opt opl-keywords ) "\\)\\>")
"Regular expression matching any keyword at the beginning of a
line.")
;;(regexp-opt opl-keywords )
(defconst opl-types-matcher
(concat "\\<\\(" (regexp-opt opl-types ) "\\)\\>")
"Regular expression matching any keyword at the beginning of a
line.")
(defconst comet-builtins-matcher
(concat "\\<\\(" (regexp-opt comet-builtins ) "\\)\\>")
"Regular expression matching any keyword at the beginning of a
line.")
(defconst opl-consts-matcher
(concat "\\<\\(" (regexp-opt opl-consts ) "\\)\\>")
"Regular expression matching any constants")
(defconst comet-font-lock-keywords
(eval-when-compile
(list
(cons opl-keyword-matcher
'(1 font-lock-keyword-face))
(cons opl-types-matcher
'(1 font-lock-type-face))
;; (cons opl-consts-matcher
;; '(1 font-lock-constant-face))
(cons comet-builtins-matcher
'(1 font-lock-builtin-face))
'("\\(function\\) \\(\\w+?\\) \\(\\w+\\)"
(1 font-lock-keyword-face)
(2 font-lock-type-face)
(3 font-lock-function-name-face)
)
'("\\(\\w+\\(\\.\\w+\\)*\\.\\.\\w+\\(\\.\\w+\\)*\\)"
(1 font-lock-constant-face)
)
'("\\(\\w+\\) \\(\\w+\\)"
(1 font-lock-type-face)
(2 font-lock-variable-name-face)
)
'("\\<\\(\\w+\\) *\\[.+?\\]"
(1 font-lock-variable-name-face)
)
'("\\w+\\(@\\w+\\)\\>"
(1 font-lock-function-name-face)
)
))
"Default expressions to highlight in COMET mode."
)
(define-derived-mode comet-mode java-mode "COMET"
"Major mode to edit COMET files."
;;(set (make-local-variable 'font-lock-keywords)
;; '(comet-mode-font-lock-keywords))
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults '(comet-font-lock-keywords nil nil ((?_ . "w"))))
;;(set (make-local-variable 'comment-start) "--"))
(setq c-basic-offset 2)
)
(add-hook 'comet-mode-hook 'hs-minor-mode)
(add-to-list 'auto-mode-alist '("\\.co\\'" . comet-mode))
(add-hook 'compilation-mode-hook '
(lambda ()(add-to-list 'compilation-error-regexp-alist
'("\\(\\w+.co\\)\\[\\([0-9]+\\)\\]" 1
2))))
(fset 'auto-cout
[?c ?o ?u ?t ? ?< ?< ? ? ?< ?< ?e ?n ?d ?l ?\; left left left left left left left
left])
(global-set-key "\C-co" 'auto-cout)

