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