Move lisp/emacs-lisp/authors.el to admin/
[bpt/emacs.git] / lisp / gnus / sieve-mode.el
CommitLineData
23f87bed 1;;; sieve-mode.el --- Sieve code editing commands for Emacs
e84b4b86 2
ba318903 3;; Copyright (C) 2001-2014 Free Software Foundation, Inc.
23f87bed
MB
4
5;; Author: Simon Josefsson <simon@josefsson.org>
6
7;; This file is part of GNU Emacs.
8
5e809f55 9;; GNU Emacs is free software: you can redistribute it and/or modify
23f87bed 10;; it under the terms of the GNU General Public License as published by
5e809f55
GM
11;; the Free Software Foundation, either version 3 of the License, or
12;; (at your option) any later version.
23f87bed
MB
13
14;; GNU Emacs is distributed in the hope that it will be useful,
15;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5e809f55 16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23f87bed
MB
17;; GNU General Public License for more details.
18
19;; You should have received a copy of the GNU General Public License
5e809f55 20;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23f87bed
MB
21
22;;; Commentary:
23
24;; This file contain editing mode functions and font-lock support for
25;; editing Sieve scripts. It sets up C-mode with support for
26;; sieve-style #-comments and a lightly hacked syntax table. It was
27;; strongly influenced by awk-mode.el.
28;;
29;; Put something similar to the following in your .emacs to use this file:
30;;
31;; (load "~/lisp/sieve")
32;; (setq auto-mode-alist (cons '("\\.siv\\'" . sieve-mode) auto-mode-alist))
33;;
34;; References:
35;;
36;; RFC 3028,
37;; "Sieve: A Mail Filtering Language",
38;; by Tim Showalter.
39;;
40;; Release history:
41;;
42;; 2001-03-02 version 1.0 posted to gnu.emacs.sources
43;; version 1.1 change file extension into ".siv" (official one)
44;; added keymap and menubar to hook into sieve-manage
45;; 2001-10-31 version 1.2 committed to Oort Gnus
46
47;;; Code:
48
49(autoload 'sieve-manage "sieve")
50(autoload 'sieve-upload "sieve")
23f87bed
MB
51(eval-when-compile
52 (require 'font-lock))
53
54(defgroup sieve nil
55 "Sieve."
56 :group 'languages)
57
58(defcustom sieve-mode-hook nil
59 "Hook run in sieve mode buffers."
60 :group 'sieve
61 :type 'hook)
62
63;; Font-lock
64
0f49874b 65(defvar sieve-control-commands-face 'sieve-control-commands
23f87bed
MB
66 "Face name used for Sieve Control Commands.")
67
0f49874b 68(defface sieve-control-commands
23f87bed
MB
69 '((((type tty) (class color)) (:foreground "blue" :weight light))
70 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
71 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
72 (((class color) (background light)) (:foreground "Orchid"))
73 (((class color) (background dark)) (:foreground "LightSteelBlue"))
74 (t (:bold t)))
d0859c9a
MB
75 "Face used for Sieve Control Commands."
76 :group 'sieve)
0f49874b
MB
77;; backward-compatibility alias
78(put 'sieve-control-commands-face 'face-alias 'sieve-control-commands)
3d493bef 79(put 'sieve-control-commands-face 'obsolete-face "22.1")
23f87bed 80
0f49874b 81(defvar sieve-action-commands-face 'sieve-action-commands
23f87bed
MB
82 "Face name used for Sieve Action Commands.")
83
0f49874b 84(defface sieve-action-commands
23f87bed
MB
85 '((((type tty) (class color)) (:foreground "blue" :weight bold))
86 (((class color) (background light)) (:foreground "Blue"))
87 (((class color) (background dark)) (:foreground "LightSkyBlue"))
88 (t (:inverse-video t :bold t)))
d0859c9a
MB
89 "Face used for Sieve Action Commands."
90 :group 'sieve)
0f49874b
MB
91;; backward-compatibility alias
92(put 'sieve-action-commands-face 'face-alias 'sieve-action-commands)
3d493bef 93(put 'sieve-action-commands-face 'obsolete-face "22.1")
23f87bed 94
0f49874b 95(defvar sieve-test-commands-face 'sieve-test-commands
23f87bed
MB
96 "Face name used for Sieve Test Commands.")
97
0f49874b 98(defface sieve-test-commands
23f87bed
MB
99 '((((type tty) (class color)) (:foreground "magenta"))
100 (((class grayscale) (background light))
101 (:foreground "LightGray" :bold t :underline t))
102 (((class grayscale) (background dark))
103 (:foreground "Gray50" :bold t :underline t))
104 (((class color) (background light)) (:foreground "CadetBlue"))
105 (((class color) (background dark)) (:foreground "Aquamarine"))
106 (t (:bold t :underline t)))
d0859c9a
MB
107 "Face used for Sieve Test Commands."
108 :group 'sieve)
0f49874b
MB
109;; backward-compatibility alias
110(put 'sieve-test-commands-face 'face-alias 'sieve-test-commands)
3d493bef 111(put 'sieve-test-commands-face 'obsolete-face "22.1")
23f87bed 112
0f49874b 113(defvar sieve-tagged-arguments-face 'sieve-tagged-arguments
23f87bed
MB
114 "Face name used for Sieve Tagged Arguments.")
115
0f49874b 116(defface sieve-tagged-arguments
23f87bed
MB
117 '((((type tty) (class color)) (:foreground "cyan" :weight bold))
118 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
119 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
120 (((class color) (background light)) (:foreground "Purple"))
121 (((class color) (background dark)) (:foreground "Cyan"))
122 (t (:bold t)))
d0859c9a
MB
123 "Face used for Sieve Tagged Arguments."
124 :group 'sieve)
0f49874b
MB
125;; backward-compatibility alias
126(put 'sieve-tagged-arguments-face 'face-alias 'sieve-tagged-arguments)
3d493bef 127(put 'sieve-tagged-arguments-face 'obsolete-face "22.1")
23f87bed
MB
128
129
130(defconst sieve-font-lock-keywords
131 (eval-when-compile
132 (list
133 ;; control commands
fd1b1e2e
AM
134 (cons (regexp-opt '("require" "if" "else" "elsif" "stop")
135 'words)
23f87bed
MB
136 'sieve-control-commands-face)
137 ;; action commands
fd1b1e2e
AM
138 (cons (regexp-opt '("fileinto" "redirect" "reject" "keep" "discard")
139 'words)
23f87bed
MB
140 'sieve-action-commands-face)
141 ;; test commands
142 (cons (regexp-opt '("address" "allof" "anyof" "exists" "false"
fd1b1e2e
AM
143 "true" "header" "not" "size" "envelope")
144 'words)
23f87bed
MB
145 'sieve-test-commands-face)
146 (cons "\\Sw+:\\sw+"
147 'sieve-tagged-arguments-face))))
148
149;; Syntax table
150
151(defvar sieve-mode-syntax-table nil
152 "Syntax table in use in sieve-mode buffers.")
153
154(if sieve-mode-syntax-table
155 ()
156 (setq sieve-mode-syntax-table (make-syntax-table))
157 (modify-syntax-entry ?\\ "\\" sieve-mode-syntax-table)
158 (modify-syntax-entry ?\n "> " sieve-mode-syntax-table)
159 (modify-syntax-entry ?\f "> " sieve-mode-syntax-table)
160 (modify-syntax-entry ?\# "< " sieve-mode-syntax-table)
161 (modify-syntax-entry ?/ "." sieve-mode-syntax-table)
162 (modify-syntax-entry ?* "." sieve-mode-syntax-table)
163 (modify-syntax-entry ?+ "." sieve-mode-syntax-table)
164 (modify-syntax-entry ?- "." sieve-mode-syntax-table)
165 (modify-syntax-entry ?= "." sieve-mode-syntax-table)
166 (modify-syntax-entry ?% "." sieve-mode-syntax-table)
167 (modify-syntax-entry ?< "." sieve-mode-syntax-table)
168 (modify-syntax-entry ?> "." sieve-mode-syntax-table)
169 (modify-syntax-entry ?& "." sieve-mode-syntax-table)
170 (modify-syntax-entry ?| "." sieve-mode-syntax-table)
171 (modify-syntax-entry ?_ "_" sieve-mode-syntax-table)
172 (modify-syntax-entry ?\' "\"" sieve-mode-syntax-table))
173
174;; Key map definition
175
176(defvar sieve-mode-map
177 (let ((map (make-sparse-keymap)))
178 (define-key map "\C-c\C-l" 'sieve-upload)
a4acb88d 179 (define-key map "\C-c\C-c" 'sieve-upload-and-kill)
23f87bed
MB
180 (define-key map "\C-c\C-m" 'sieve-manage)
181 map)
182 "Key map used in sieve mode.")
183
184;; Menu definition
185
186(defvar sieve-mode-menu nil
187 "Menubar used in sieve mode.")
188
189;; Code for Sieve editing mode.
aa8f8277 190(autoload 'easy-menu-add-item "easymenu")
23f87bed
MB
191
192;;;###autoload
193(define-derived-mode sieve-mode c-mode "Sieve"
194 "Major mode for editing Sieve code.
195This is much like C mode except for the syntax of comments. Its keymap
196inherits from C mode's and it has the same variables for customizing
197indentation. It has its own abbrev table and its own syntax table.
198
199Turning on Sieve mode runs `sieve-mode-hook'."
200 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
201 (set (make-local-variable 'paragraph-separate) paragraph-start)
202 (set (make-local-variable 'comment-start) "#")
203 (set (make-local-variable 'comment-end) "")
204 ;;(set (make-local-variable 'comment-start-skip) "\\(^\\|\\s-\\);?#+ *")
205 (set (make-local-variable 'comment-start-skip) "#+ *")
206 (unless (featurep 'xemacs)
207 (set (make-local-variable 'font-lock-defaults)
208 '(sieve-font-lock-keywords nil nil ((?_ . "w")))))
209 (easy-menu-add-item nil nil sieve-mode-menu))
210
211;; Menu
212
213(easy-menu-define sieve-mode-menu sieve-mode-map
214 "Sieve Menu."
215 '("Sieve"
216 ["Upload script" sieve-upload t]
217 ["Manage scripts on server" sieve-manage t]))
218
219(provide 'sieve-mode)
220
23f87bed 221;; sieve-mode.el ends here