aboutsummaryrefslogtreecommitdiff
path: root/elisp
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 /elisp
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
Diffstat (limited to 'elisp')
-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 @@
+;;; mfl-mode.el --- major mode for editing MFL sources
+
+;; Authors: 2007 Sergey Poznyakoff
+;; Version: 0.1
+;; Keywords: mailfromd, MFL
+;; $Id$
+
+;; This file is part of mailfromd
+;; Copyright (C) 2007 Sergey Poznyakoff
+
+;; Mailfromd is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2 of the License, or
+;; (at your option) any later version.
+
+;; Mailfromd is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with mailfromd; if not, write to the Free Software Foundation,
+;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+;; Installation:
+;; You may wish to use precompiled version of the module. To create it
+;; run:
+;; emacs -batch -f batch-byte-compile mfl-mode.el
+;; Install the file mfl-mode.elc (and, optionally, mfl-mode.el) to
+;; any directory in your Emacs load-path.
+
+(eval-when-compile
+ ;; We use functions from these modules
+ (mapcar 'require '(font-lock)))
+
+(defvar mfl-mode-syntax-table nil
+ "Syntax table used in mfl-mode buffers.")
+
+(unless mfl-mode-syntax-table
+ (setq mfl-mode-syntax-table (make-syntax-table))
+; (modify-syntax-entry ?\# "<" mfl-mode-syntax-table)
+; (modify-syntax-entry ?\n ">" mfl-mode-syntax-table)
+ (modify-syntax-entry ?\t "-" mfl-mode-syntax-table)
+ (modify-syntax-entry ?\( "(" mfl-mode-syntax-table)
+ (modify-syntax-entry ?\) ")" mfl-mode-syntax-table)
+; (modify-syntax-entry ?\` "(" mfl-mode-syntax-table)
+; (modify-syntax-entry ?\' ")\"" mfl-mode-syntax-table)
+ (modify-syntax-entry ?\' "\"" mfl-mode-syntax-table)
+ (modify-syntax-entry ?\" "\"" mfl-mode-syntax-table)
+ (modify-syntax-entry ?\\ "\\" mfl-mode-syntax-table)
+ (modify-syntax-entry ?\/ ". 14" mfl-mode-syntax-table)
+ (modify-syntax-entry ?\* ". 23" mfl-mode-syntax-table))
+
+(defvar mfl-mode-map (make-sparse-keymap)
+ "Keymap used in MFL mode.")
+
+;(define-key mfl-mode-map [menu-bar] (make-sparse-keymap))
+;(define-key cflow-mode-map [menu-bar MFL]
+; (cons "MFL" (make-sparse-keymap "MFL")))
+
+
+(defconst mfl-keywords
+ (eval-when-compile
+ (regexp-opt '("add" "and" "begin" "break" "case"
+ "catch" "const" "continue" "default"
+ "delete" "discard" "do" "done"
+ "echo" "end" "elif" "else"
+ "fi" "fnmatches" "for" "func"
+ "if" "loop" "matches" "next"
+ "not" "on" "or" "pass"
+ "prog" "reject" "replace" "return"
+ "returns" "set" "switch" "tempfail"
+ "throw" "when" "while"
+ ;; FIXME: These are context-dependent
+ "as" "from" "host" "poll"))))
+
+(defconst mfl-constants
+ (eval-when-compile
+ (regexp-opt '("__file__" "__function__" "__line__" "__major__"
+ "__minor__" "__package__" "__patch__" "__preproc__"
+ "__version__"))))
+
+(defconst mfl-type-names
+ (eval-when-compile
+ (regexp-opt '("number" "string"))))
+
+(defconst mfl-preprocessor-directives
+ (eval-when-compile
+ (regexp-opt '("include" "include_once" "error" "line"
+ "pragma" "require" "warning"))))
+
+(defconst mfl-m4-keywords
+ (eval-when-compile
+ (regexp-opt '("m4_define" "m4_defn" "m4_undefconst" "m4_builtin"
+ "m4_changecom" "m4_changequote" "m4_debugfile" "m4_debugmode"
+ "m4_decr" "m4_divert" "m4_divnum" "m4_dumpdef"
+ "m4_errprint" "m4_esyscmd" "m4_eval" "m4_format"
+ "m4_ifdef" "m4_ifelse" "m4_include" "m4_incr"
+ "m4_index" "m4_indir" "m4_len" "m4_exit"
+ "m4_wrap" "m4_maketemp" "m4_patsubst" "m4_popdef"
+ "m4_pushdef" "m4_regexp" "m4_shift" "m4_sinclude"
+ "m4_substr" "m4_symbols" "m4_syscmd" "m4_sysval"
+ "m4_traceoff" "m4_traceon" "m4_translit" "m4_undivert"
+ "m4_dnl" "m4___line__" "m4___file__"))))
+
+(defconst mfl-macros
+ (eval-when-compile
+ (regexp-opt '("defined" "printf" "_" "N_"))))
+
+
+;; Font-lock stuff
+(defconst mfl-font-lock-keywords
+ (eval-when-compile
+ (list
+ ;; Fontify error and warning directives.
+ '("^#[ \t]*error[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend)
+ '("^#[ \t]*warning[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend)
+ ;;
+ ;; Fontify filenames in #include <...> preprocessor directives as strings.
+ '("^#[ \t]*\\(include\\|include_once\\)[ \t]*\\(<[^>\"\n]*>?\\)"
+ 2 font-lock-string-face)
+ ;; Fontify module names in #require directives as strings.
+ '("^#[ \t]*\\(require\\)[ \t]*\\(.[^\n]*\\)"
+ 2 font-lock-string-face)
+ ;; Fontify otherwise as symbol names, and the preprocessor directive
+ ;; names.
+ (list
+ (concat "^#[ \t]*\\(" mfl-preprocessor-directives
+ "\\)\\>[ \t!]*\\(\\sw+\\)?")
+ '(1 font-lock-builtin-face))
+ ;; Otherwise, fontify #...\n as comments:
+ (list
+ "^#\\(.*\\)\n" 1 font-lock-comment-face)
+
+ ;; Fontify all type names.
+ `(eval .
+ (cons (concat "\\<\\(" ,mfl-type-names "\\)\\>") 'font-lock-type-face))
+
+ ;;
+ ;; Fontify all builtin keywords
+ (concat "\\<\\(" mfl-keywords "\\)\\>")
+
+ ;; Fontify m4 keywords and macros
+ (list
+ (concat "\\<\\(" mfl-m4-keywords "\\)\\>")
+ 1 font-lock-builtin-face)
+
+ ;; Fontify variable names
+ (list
+ "%\\([a-zA-Z0-9_]+\\)"
+ 1 font-lock-variable-name-face)
+ (list
+ "set[ \t]+\\([a-zA-Z0-9_]+\\)"
+ 1 font-lock-variable-name-face)
+ (list
+ "defined[ \t]*([ \t]*\\([a-zA-Z0-9_]+\\)[ \t]*)"
+ 1 font-lock-variable-name-face)
+ (list
+ (concat "\\<\\(" mfl-type-names "\\)\\>[ \t]+\\([a-zA-Z0-9_]+\\)")
+ 2 font-lock-variable-name-face)
+
+ ;; Fontify macro names
+ (list
+ "${?\\([a-zA-Z0-9_]+\\)}?"
+ 1 font-lock-constant-face)
+ )))
+
+;;;###autoload
+(defun mfl-mode ()
+ "Major mode for viewing cflow output files
+
+Key bindings are:
+\\{mfl-mode-map}
+"
+ (interactive)
+ (kill-all-local-variables)
+ (use-local-map mfl-mode-map)
+ (setq major-mode 'mfl-mode
+ mode-name "MFL")
+
+ (set-syntax-table mfl-mode-syntax-table)
+
+ (make-local-variable 'font-lock-defaults)
+ (setq font-lock-defaults
+ '((mfl-font-lock-keywords) nil nil
+ nil
+ nil)))
+
+(provide 'mfl-mode)
+;;; mfl-mode ends

Return to:

Send suggestions and report system problems to the System administrator.