/[anubis]/anubis/elisp/anubis-mode.el
ViewVC logotype

Diff of /anubis/elisp/anubis-mode.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by gray, Wed Aug 6 11:21:00 2003 UTC revision 1.3 by gray, Fri Aug 8 20:47:47 2003 UTC
# Line 49  Line 49 
49    
50  (eval-when-compile  (eval-when-compile
51    ;; We use functions from these modules    ;; We use functions from these modules
52    (mapcar 'require '(info)))    (mapcar 'require '(info compile font-lock)))
53    
54  (defvar anubis-mode-syntax-table nil  (defvar anubis-mode-syntax-table nil
55    "Syntax table used in anubis-mode buffers.")    "Syntax table used in anubis-mode buffers.")
56  (if anubis-mode-syntax-table  
57      ()  (unless anubis-mode-syntax-table
58    (setq anubis-mode-syntax-table (make-syntax-table))    (setq anubis-mode-syntax-table (make-syntax-table))
59    (modify-syntax-entry ?\# "<" anubis-mode-syntax-table)    (modify-syntax-entry ?\# "<" anubis-mode-syntax-table)
60    (modify-syntax-entry ?\n ">" anubis-mode-syntax-table)    (modify-syntax-entry ?\n ">" anubis-mode-syntax-table)
# Line 75  Line 75 
75  (defvar anubis-mode-map ()  (defvar anubis-mode-map ()
76    "Keymap used in anubis-mode buffers.")    "Keymap used in anubis-mode buffers.")
77    
78  (if anubis-mode-map  (unless anubis-mode-map
     ()  
79    (setq anubis-mode-map (make-sparse-keymap))    (setq anubis-mode-map (make-sparse-keymap))
80    
81    (define-key anubis-mode-map "\t" 'anubis-complete-or-indent)    (define-key anubis-mode-map "\t" 'anubis-complete-or-indent)
82    (define-key anubis-mode-map "\e\t" 'anubis-indent-line)    (define-key anubis-mode-map "\e\t" 'anubis-indent-line)
83    (define-key anubis-mode-map "\e?" 'anubis-describe-keywords))    (define-key anubis-mode-map "\e?" 'anubis-describe-keywords)
84      (define-key anubis-mode-map "\C-c\C-c" 'anubis-check-syntax)
85    
86      (define-key anubis-mode-map [menu-bar] (make-sparse-keymap))
87      (define-key anubis-mode-map [menu-bar Anubis]
88        (cons "Anubis" anubis-mode-map))
89      (define-key anubis-mode-map [anubis-check-syntax]
90        '("Check syntax" . anubis-check-syntax)))
91    
92    (defvar anubis-path nil
93      "Path to the anubis executable")
94    
95  (defvar anubis-section-body-indent 0  (defvar anubis-section-body-indent 0
96    "Indent of a section body in an Anubis rc file")    "Indent of a section body in an Anubis rc file")
97  (defvar anubis-level-indent 2  (defvar anubis-level-indent 2
98    "Amount of additional indentation per nesting level of statements")    "Amount of additional indentation per nesting level of statements")
99    
100    
101    ;; Font lock stuff
102    
103    (defconst anubis-font-lock-keywords
104      (eval-when-compile
105        (list
106         (list "\\(BEGIN\\)[ \t]+\\(\\sw+\\)"
107               '(1 font-lock-keyword-face)
108               '(2 font-lock-function-name-face))
109         (cons "^\\s *\\(---\\)?\\s *END\\s *\\(---\\)?" font-lock-keyword-face)
110         (cons (regexp-opt
111                '("if" "else" "fi" "rule" "trigger" "done")
112                'words)
113               font-lock-keyword-face)
114         (cons (regexp-opt
115                '("stop" "call" "add" "remove" "modify" "regexp") 'words)
116               font-lock-keyword-face)
117         (cons (regexp-opt
118                '("and" "or" "not") 'words)
119               font-lock-keyword-face)
120         (cons (regexp-opt
121                 '("header" "body" "command") 'words)
122               font-lock-type-face)
123         (cons (regexp-opt
124                '("bind"
125                  "rule-priority"
126                  "control-priority"
127                  "termlevel"
128                  "allow-local-mta"
129                  "user-notprivileged"
130                  "drop-unknown-user"
131                  "loglevel"
132                  "logfile"
133                  "remote-mta"
134                  "local-mta"
135                  "esmtp-auth"
136                  "socks-proxy"
137                  "socks-v4"
138                  "socks-auth"
139                  "read-entire-body"
140                  "ssl"
141                  "ssl-oneway"
142                  "ssl-cert"
143                  "ssl-key"
144                  "ssl-cafile"
145                  "signature-file-append"
146                  "body-append"
147                  "body-clear-append"
148                  "body-clear"
149                  "external-body-processor"
150                  "gpg-passphrase"
151                  "gpg-encrypt"
152                  "gpg-sign"
153                  "gpg-home"
154                  "guile-output"
155                  "guile-debug"
156                  "guile-load-path-append"
157                  "guile-load-program"
158                  "guile-debug"          
159                  "guile-load-path-append"
160                  "guile-load-program"
161                  "guile-rewrite-line"    
162                  "guile-process") 'words)
163               font-lock-keyword-face)
164    
165         (list (concat ":"
166                       (regexp-opt
167                        '("re" "regex"
168                          "perl" "perlre"
169                          "ex" "exact"
170                          "scase"
171                          "icase"
172                          "basic"
173                          "extended") t)) ; FIXME: 'words does not work
174               1 font-lock-builtin-face)
175        
176         (list "#:\\(\\sw+\\)" 1 font-lock-constant-face 'prepend)
177    
178         (cons "\\[\\sw+\\]" font-lock-string-face) ) )
179        
180      "Expressions to highlight in Anubis mode.")
181    
182    
183    
184    
185  ;; A list of keywords allowed in each section  ;; A list of keywords allowed in each section
186    
187  (defconst anubis-keyword-dict  (defconst anubis-keyword-dict
# Line 292  Line 387 
387    (let ((dict anubis-keyword-dict)    (let ((dict anubis-keyword-dict)
388          (ctx (anubis-locate-context anubis-block-dict)))          (ctx (anubis-locate-context anubis-block-dict)))
389      (if (not (car ctx))      (if (not (car ctx))
390          f          nil
391        (let ((dict (assoc (cadr ctx) dict)))        (let ((dict (assoc (cadr ctx) dict)))
392          (if dict          (if dict
393              (let ((compl (completing-read (or prompt "what? ")              (let ((compl (completing-read (or prompt "what? ")
# Line 370  Line 465 
465            (goto-char (+ here off)) )            (goto-char (+ here off)) )
466        (anubis-indent-line) )))        (anubis-indent-line) )))
467    
468    
469    (defun anubis-check-syntax (arg)
470      "Checks the syntax of the current Anubis RC buffer. Optional argument
471    specifies the detail level (from 0 to 3)."
472      (interactive "p")
473      (let ((compile-command compile-command))
474        (compile (concat
475                  (if anubis-path anubis-path "anubis")
476                  " --check="
477                  (number-to-string (or current-prefix-arg 0))
478                  " --norc --relax --altrc "
479                       (buffer-file-name)))))
480    
481    
482    
483  ;;;###autoload  ;;;###autoload
484  (defun anubis-mode ()  (defun anubis-mode ()
485    "Major mode for editing GNU Anubis configuration files.    "Major mode for editing GNU Anubis configuration files.
# Line 387  Key bindings: Line 497  Key bindings:
497          indent-line-function 'anubis-indent-line          indent-line-function 'anubis-indent-line
498          completion-ignore-case t)          completion-ignore-case t)
499    
500    (use-local-map anubis-mode-map))    (use-local-map anubis-mode-map)
501      
502      (make-local-variable 'font-lock-defaults)
503      (setq font-lock-defaults
504            '((anubis-font-lock-keywords)
505              nil t (("+-*/.<>=!?$%_&~^:" . "w")) beginning-of-defun
506              (font-lock-mark-block-function . mark-defun)))
507      )
508    
509  (require 'info)  (require 'info)
510  (provide 'anubis-mode)  (provide 'anubis-mode)

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26