aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-05-26 13:04:56 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-05-26 13:04:56 +0000
commite3b13bbba66a92a75ac73d3ab50bca45d69c7c0d (patch)
tree2a35a0fd76b8db730535df533349bf9d68295e97
parentfc98f567cb8cd3113404b09b70e59e246119e7bb (diff)
downloadmailfromd-e3b13bbba66a92a75ac73d3ab50bca45d69c7c0d.tar.gz
mailfromd-e3b13bbba66a92a75ac73d3ab50bca45d69c7c0d.tar.bz2
Initial implementation
git-svn-id: file:///svnroot/mailfromd/trunk@1478 7a8a7f39-df28-0410-adc6-e0d955640f24
-rw-r--r--elisp/mfl-mode.el190
1 files changed, 190 insertions, 0 deletions
diff --git a/elisp/mfl-mode.el b/elisp/mfl-mode.el
index e69de29b..5c66edc6 100644
--- a/elisp/mfl-mode.el
+++ b/elisp/mfl-mode.el
@@ -0,0 +1,190 @@
1;;; mfl-mode.el --- major mode for editing MFL sources
2
3;; Authors: 2007 Sergey Poznyakoff
4;; Version: 0.1
5;; Keywords: mailfromd, MFL
6;; $Id$
7
8;; This file is part of mailfromd
9;; Copyright (C) 2007 Sergey Poznyakoff
10
11;; Mailfromd 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
16;; Mailfromd is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with mailfromd; if not, write to the Free Software Foundation,
23;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24
25;; Installation:
26;; You may wish to use precompiled version of the module. To create it
27;; run:
28;; emacs -batch -f batch-byte-compile mfl-mode.el
29;; Install the file mfl-mode.elc (and, optionally, mfl-mode.el) to
30;; any directory in your Emacs load-path.
31
32(eval-when-compile
33 ;; We use functions from these modules
34 (mapcar 'require '(font-lock)))
35
36(defvar mfl-mode-syntax-table nil
37 "Syntax table used in mfl-mode buffers.")
38
39(unless mfl-mode-syntax-table
40 (setq mfl-mode-syntax-table (make-syntax-table))
41; (modify-syntax-entry ?\# "<" mfl-mode-syntax-table)
42; (modify-syntax-entry ?\n ">" mfl-mode-syntax-table)
43 (modify-syntax-entry ?\t "-" mfl-mode-syntax-table)
44 (modify-syntax-entry ?\( "(" mfl-mode-syntax-table)
45 (modify-syntax-entry ?\) ")" mfl-mode-syntax-table)
46; (modify-syntax-entry ?\` "(" mfl-mode-syntax-table)
47; (modify-syntax-entry ?\' ")\"" mfl-mode-syntax-table)
48 (modify-syntax-entry ?\' "\"" mfl-mode-syntax-table)
49 (modify-syntax-entry ?\" "\"" mfl-mode-syntax-table)
50 (modify-syntax-entry ?\\ "\\" mfl-mode-syntax-table)
51 (modify-syntax-entry ?\/ ". 14" mfl-mode-syntax-table)
52 (modify-syntax-entry ?\* ". 23" mfl-mode-syntax-table))
53
54(defvar mfl-mode-map (make-sparse-keymap)
55 "Keymap used in MFL mode.")
56
57;(define-key mfl-mode-map [menu-bar] (make-sparse-keymap))
58;(define-key cflow-mode-map [menu-bar MFL]
59; (cons "MFL" (make-sparse-keymap "MFL")))
60
61
62(defconst mfl-keywords
63 (eval-when-compile
64 (regexp-opt '("add" "and" "begin" "break" "case"
65 "catch" "const" "continue" "default"
66 "delete" "discard" "do" "done"
67 "echo" "end" "elif" "else"
68 "fi" "fnmatches" "for" "func"
69 "if" "loop" "matches" "next"
70 "not" "on" "or" "pass"
71 "prog" "reject" "replace" "return"
72 "returns" "set" "switch" "tempfail"
73 "throw" "when" "while"
74 ;; FIXME: These are context-dependent
75 "as" "from" "host" "poll"))))
76
77(defconst mfl-constants
78 (eval-when-compile
79 (regexp-opt '("__file__" "__function__" "__line__" "__major__"
80 "__minor__" "__package__" "__patch__" "__preproc__"
81 "__version__"))))
82
83(defconst mfl-type-names
84 (eval-when-compile
85 (regexp-opt '("number" "string"))))
86
87(defconst mfl-preprocessor-directives
88 (eval-when-compile
89 (regexp-opt '("include" "include_once" "error" "line"
90 "pragma" "require" "warning"))))
91
92(defconst mfl-m4-keywords
93 (eval-when-compile
94 (regexp-opt '("m4_define" "m4_defn" "m4_undefconst" "m4_builtin"
95 "m4_changecom" "m4_changequote" "m4_debugfile" "m4_debugmode"
96 "m4_decr" "m4_divert" "m4_divnum" "m4_dumpdef"
97 "m4_errprint" "m4_esyscmd" "m4_eval" "m4_format"
98 "m4_ifdef" "m4_ifelse" "m4_include" "m4_incr"
99 "m4_index" "m4_indir" "m4_len" "m4_exit"
100 "m4_wrap" "m4_maketemp" "m4_patsubst" "m4_popdef"
101 "m4_pushdef" "m4_regexp" "m4_shift" "m4_sinclude"
102 "m4_substr" "m4_symbols" "m4_syscmd" "m4_sysval"
103 "m4_traceoff" "m4_traceon" "m4_translit" "m4_undivert"
104 "m4_dnl" "m4___line__" "m4___file__"))))
105
106(defconst mfl-macros
107 (eval-when-compile
108 (regexp-opt '("defined" "printf" "_" "N_"))))
109
110
111;; Font-lock stuff
112(defconst mfl-font-lock-keywords
113 (eval-when-compile
114 (list
115 ;; Fontify error and warning directives.
116 '("^#[ \t]*error[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend)
117 '("^#[ \t]*warning[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend)
118 ;;
119 ;; Fontify filenames in #include <...> preprocessor directives as strings.
120 '("^#[ \t]*\\(include\\|include_once\\)[ \t]*\\(<[^>\"\n]*>?\\)"
121 2 font-lock-string-face)
122 ;; Fontify module names in #require directives as strings.
123 '("^#[ \t]*\\(require\\)[ \t]*\\(.[^\n]*\\)"
124 2 font-lock-string-face)
125 ;; Fontify otherwise as symbol names, and the preprocessor directive
126 ;; names.
127 (list
128 (concat "^#[ \t]*\\(" mfl-preprocessor-directives
129 "\\)\\>[ \t!]*\\(\\sw+\\)?")
130 '(1 font-lock-builtin-face))
131 ;; Otherwise, fontify #...\n as comments:
132 (list
133 "^#\\(.*\\)\n" 1 font-lock-comment-face)
134
135 ;; Fontify all type names.
136 `(eval .
137 (cons (concat "\\<\\(" ,mfl-type-names "\\)\\>") 'font-lock-type-face))
138
139 ;;
140 ;; Fontify all builtin keywords
141 (concat "\\<\\(" mfl-keywords "\\)\\>")
142
143 ;; Fontify m4 keywords and macros
144 (list
145 (concat "\\<\\(" mfl-m4-keywords "\\)\\>")
146 1 font-lock-builtin-face)
147
148 ;; Fontify variable names
149 (list
150 "%\\([a-zA-Z0-9_]+\\)"
151 1 font-lock-variable-name-face)
152 (list
153 "set[ \t]+\\([a-zA-Z0-9_]+\\)"
154 1 font-lock-variable-name-face)
155 (list
156 "defined[ \t]*([ \t]*\\([a-zA-Z0-9_]+\\)[ \t]*)"
157 1 font-lock-variable-name-face)
158 (list
159 (concat "\\<\\(" mfl-type-names "\\)\\>[ \t]+\\([a-zA-Z0-9_]+\\)")
160 2 font-lock-variable-name-face)
161
162 ;; Fontify macro names
163 (list
164 "${?\\([a-zA-Z0-9_]+\\)}?"
165 1 font-lock-constant-face)
166 )))
167
168;;;###autoload
169(defun mfl-mode ()
170 "Major mode for viewing cflow output files
171
172Key bindings are:
173\\{mfl-mode-map}
174"
175 (interactive)
176 (kill-all-local-variables)
177 (use-local-map mfl-mode-map)
178 (setq major-mode 'mfl-mode
179 mode-name "MFL")
180
181 (set-syntax-table mfl-mode-syntax-table)
182
183 (make-local-variable 'font-lock-defaults)
184 (setq font-lock-defaults
185 '((mfl-font-lock-keywords) nil nil
186 nil
187 nil)))
188
189(provide 'mfl-mode)
190;;; mfl-mode ends

Return to:

Send suggestions and report system problems to the System administrator.