source: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp/site-lisp/kpp.el @ 2852

Last change on this file since 2852 was 2696, checked in by kanani, 7 years ago

Merge of branch palm4u into trunk

File size: 5.0 KB
Line 
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>
4 
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
7
8;; known problem:
9;; ":" inside comments between reaction products confuses font-lock
10 
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.
19
20;; start kpp-mode automatically when loading a *.eqn, *.spc, or *.kpp file
21(setq auto-mode-alist
22  (cons '("\\.eqn\\'" . kpp-mode) auto-mode-alist))
23(setq auto-mode-alist
24  (cons '("\\.spc\\'" . kpp-mode) auto-mode-alist))
25(setq auto-mode-alist
26  (cons '("\\.kpp\\'" . kpp-mode) auto-mode-alist))
27
28(setq kpp-font-lock-keywords
29 (list
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)
43  (cons (concat
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
58  )
59)
60
61; comment a region (adopted from wave-comment-region)
62
63(defvar kpp-comment-region "// "
64  "*String inserted by \\[kpp-comment-region] at start of each line in region.")
65
66(defun kpp-comment-region (beg-region end-region arg)
67  "Comments every line in the region.
68Puts kpp-comment-region at the beginning of every line in the region.
69BEG-REGION and END-REGION are args which specify the region boundaries.
70With non-nil ARG, uncomments the region."
71  (interactive "*r\nP")
72  (let ((end-region-mark (make-marker)) (save-point (point-marker)))
73    (set-marker end-region-mark end-region)
74    (goto-char beg-region)
75    (beginning-of-line)
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
82        (if (looking-at com)
83            (delete-region (point) (match-end 0)))
84        (while (and  (= (forward-line 1) 0)
85                     (< (point) end-region-mark))
86          (if (looking-at com)
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)))
91
92(defvar kpp-mode-map ()
93  "Keymap used in kpp mode.")
94
95(if kpp-mode-map
96    ()
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 "        ")))
102)
103
104(defun kpp-mode ()
105  "Major mode for editing kpp code.
106Turning on kpp mode calls the value of the variable `kpp-mode-hook'
107with no args, if that value is non-nil.
108
109Command Table:
110\\{kpp-mode-map}"
111  (interactive)
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)
121  (turn-on-font-lock)
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)
126)
127
128(provide 'kpp)
129
130;; kpp.el ends here
Note: See TracBrowser for help on using the repository browser.