1 ;; kpp.el --- kpp mode for GNU Emacs 21
2 ;; (c) Rolf Sander <sander@mpch-mainz.mpg.de>
3 ;; Time-stamp: <2005-02-15 15:18:42 sander>
5 ;; to activate it copy kpp.el to a place where emacs can find it and then
6 ;; add "(require 'kpp)" to your .emacs startup file
9 ;; ":" inside comments between reaction products confuses font-lock
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2 of the License, or
14 ;; (at your option) any later version.
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; start kpp-mode automatically when loading a *.eqn, *.spc, or *.kpp file
22 (cons '("\\.eqn\\'" . kpp-mode
) auto-mode-alist
))
24 (cons '("\\.spc\\'" . kpp-mode
) auto-mode-alist
))
26 (cons '("\\.kpp\\'" . kpp-mode
) auto-mode-alist
))
28 (setq kpp-font-lock-keywords
30 '("^\\([^=\n]*=[^:\n]*\\):[^;\n]*;" 1 font-lock-constant-face
) ; reaction
31 ;; alternatively, use another color for rate constant:
32 ;; '("^\\([^=\n]*=[^:\n]*\\):\\([^;\n]*\\);"
33 ;; (1 font-lock-constant-face) (2 font-lock-keyword-face))
34 '("<[A-z0-9_#]+>" 0 font-lock-variable-name-face t
) ; equation tag
35 '("{[^}\n]*}" 0 font-lock-comment-face t
) ; comment
36 '("!.*" 0 font-lock-comment-face t
) ; f90 comment
37 '("{@[^}]+}" 0 font-lock-doc-face t
) ; alternative LaTeX text
38 '("{$[^}]+}" 0 font-lock-string-face t
) ; alternative LaTeX text
39 '("{&[^}]+}" 0 font-lock-builtin-face t
) ; BibTeX reference
40 '("{%[A-z0-9#]+}" 0 font-lock-type-face t
) ; marker
41 ;; KPP sections (Tab. 3 in thesis), commands (Tab. 13 in thesis), and
42 ;; fragments (Tab. 17 in thesis)
44 "\\(#ATOMS\\|#CHECKALL\\|#CHECK\\|#DEFFIX\\|#DEFRAD"
45 "\\|#DEFVAR\\|#DOUBLE\\|#DRIVER\\|#DUMMYINDEX"
46 "\\|#ENDINLINE\\|#EQNTAGS\\|#EQUATIONS\\|#FUNCTION"
47 "\\|#HESSIAN\\|#INCLUDE\\|#INITIALIZE"
48 "\\|#INITVALUES\\|#INLINE\\|#INTEGRATOR\\|#INTFILE"
49 "\\|#JACOBIAN\\|#LANGUAGE\\|#LOOKATALL"
50 "\\|#LOOKAT\\|#LUMP\\|#MEX\\|#MODEL\\|#MONITOR"
51 "\\|#REORDER\\|#RUN\\|#SETFIX\\|#SETRAD\\|#SETVAR"
52 "\\|#SPARSEDATA\\|#STOCHASTIC\\|#STOICMAT\\|#TRANSPORTALL"
53 "\\|#TRANSPORT\\|#USE\\|#USES\\|#WRITE_ATM"
54 "\\|#WRITE_MAT\\|#WRITE_OPT\\|#WRITE_SPC"
55 "\\|#XGRID\\|#YGRID\\|#ZGRID\\)"
56 ) 'font-lock-keyword-face
)
57 '("^//.*" 0 font-lock-comment-face t
) ; comment
61 ; comment a region (adopted from wave-comment-region)
63 (defvar kpp-comment-region
"// "
64 "*String inserted by \\[kpp-comment-region] at start of each line in region.")
66 (defun kpp-comment-region (beg-region end-region arg
)
67 "Comments every line in the region.
68 Puts kpp-comment-region at the beginning of every line in the region.
69 BEG-REGION and END-REGION are args which specify the region boundaries.
70 With non-nil ARG, uncomments the region."
72 (let ((end-region-mark (make-marker)) (save-point (point-marker)))
73 (set-marker end-region-mark end-region
)
74 (goto-char beg-region
)
76 (if (not arg
) ;comment the region
77 (progn (insert kpp-comment-region
)
78 (while (and (= (forward-line 1) 0)
79 (< (point) end-region-mark
))
80 (insert kpp-comment-region
)))
81 (let ((com (regexp-quote kpp-comment-region
))) ;uncomment the region
83 (delete-region (point) (match-end 0)))
84 (while (and (= (forward-line 1) 0)
85 (< (point) end-region-mark
))
87 (delete-region (point) (match-end 0))))))
88 (goto-char save-point
)
89 (set-marker end-region-mark nil
)
90 (set-marker save-point nil
)))
92 (defvar kpp-mode-map
()
93 "Keymap used in kpp mode.")
97 (setq kpp-mode-map
(make-sparse-keymap))
98 (define-key kpp-mode-map
"\C-c;" 'kpp-comment-region
)
99 ;; TAB inserts 8 spaces, not the TAB character
100 (define-key kpp-mode-map
(kbd "TAB")
101 '(lambda () (interactive) (insert " ")))
105 "Major mode for editing kpp code.
106 Turning on kpp mode calls the value of the variable `kpp-mode-hook'
107 with no args, if that value is non-nil.
112 (make-local-variable 'font-lock-defaults
)
113 (setq font-lock-defaults
'((kpp-font-lock-keywords) t t
))
114 (make-local-variable 'comment-start
)
115 (setq comment-start
"{")
116 (make-local-variable 'comment-end
)
117 (setq comment-end
"}")
118 (use-local-map kpp-mode-map
)
119 (setq mode-name
"kpp")
120 (setq major-mode
'kpp-mode
)
122 (set-syntax-table (copy-syntax-table))
123 (modify-syntax-entry ?_
"w") ; the underscore can be part of a word
124 (auto-fill-mode 0) ; no automatic line breaks
125 (run-hooks 'kpp-mode-hook
)