]> code.delx.au - gnu-emacs/blob - lisp/gnus/sieve-mode.el
(rfc2231-encode-string): Use mm-disable-multibyte
[gnu-emacs] / lisp / gnus / sieve-mode.el
1 ;;; sieve-mode.el --- Sieve code editing commands for Emacs
2
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005,
4 ;; 2006 Free Software Foundation, Inc.
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
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
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
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")
54 (autoload 'c-mode "cc-mode")
55 (require 'easymenu)
56 (eval-when-compile
57 (require 'font-lock))
58
59 (defgroup sieve nil
60 "Sieve."
61 :group 'languages)
62
63 (defcustom sieve-mode-hook nil
64 "Hook run in sieve mode buffers."
65 :group 'sieve
66 :type 'hook)
67
68 ;; Font-lock
69
70 (defvar sieve-control-commands-face 'sieve-control-commands
71 "Face name used for Sieve Control Commands.")
72
73 (defface sieve-control-commands
74 '((((type tty) (class color)) (:foreground "blue" :weight light))
75 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
76 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
77 (((class color) (background light)) (:foreground "Orchid"))
78 (((class color) (background dark)) (:foreground "LightSteelBlue"))
79 (t (:bold t)))
80 "Face used for Sieve Control Commands."
81 :group 'sieve)
82 ;; backward-compatibility alias
83 (put 'sieve-control-commands-face 'face-alias 'sieve-control-commands)
84
85 (defvar sieve-action-commands-face 'sieve-action-commands
86 "Face name used for Sieve Action Commands.")
87
88 (defface sieve-action-commands
89 '((((type tty) (class color)) (:foreground "blue" :weight bold))
90 (((class color) (background light)) (:foreground "Blue"))
91 (((class color) (background dark)) (:foreground "LightSkyBlue"))
92 (t (:inverse-video t :bold t)))
93 "Face used for Sieve Action Commands."
94 :group 'sieve)
95 ;; backward-compatibility alias
96 (put 'sieve-action-commands-face 'face-alias 'sieve-action-commands)
97
98 (defvar sieve-test-commands-face 'sieve-test-commands
99 "Face name used for Sieve Test Commands.")
100
101 (defface sieve-test-commands
102 '((((type tty) (class color)) (:foreground "magenta"))
103 (((class grayscale) (background light))
104 (:foreground "LightGray" :bold t :underline t))
105 (((class grayscale) (background dark))
106 (:foreground "Gray50" :bold t :underline t))
107 (((class color) (background light)) (:foreground "CadetBlue"))
108 (((class color) (background dark)) (:foreground "Aquamarine"))
109 (t (:bold t :underline t)))
110 "Face used for Sieve Test Commands."
111 :group 'sieve)
112 ;; backward-compatibility alias
113 (put 'sieve-test-commands-face 'face-alias 'sieve-test-commands)
114
115 (defvar sieve-tagged-arguments-face 'sieve-tagged-arguments
116 "Face name used for Sieve Tagged Arguments.")
117
118 (defface sieve-tagged-arguments
119 '((((type tty) (class color)) (:foreground "cyan" :weight bold))
120 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
121 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
122 (((class color) (background light)) (:foreground "Purple"))
123 (((class color) (background dark)) (:foreground "Cyan"))
124 (t (:bold t)))
125 "Face used for Sieve Tagged Arguments."
126 :group 'sieve)
127 ;; backward-compatibility alias
128 (put 'sieve-tagged-arguments-face 'face-alias 'sieve-tagged-arguments)
129
130
131 (defconst sieve-font-lock-keywords
132 (eval-when-compile
133 (list
134 ;; control commands
135 (cons (regexp-opt '("require" "if" "else" "elsif" "stop"))
136 'sieve-control-commands-face)
137 ;; action commands
138 (cons (regexp-opt '("fileinto" "redirect" "reject" "keep" "discard"))
139 'sieve-action-commands-face)
140 ;; test commands
141 (cons (regexp-opt '("address" "allof" "anyof" "exists" "false"
142 "true" "header" "not" "size" "envelope"))
143 'sieve-test-commands-face)
144 (cons "\\Sw+:\\sw+"
145 'sieve-tagged-arguments-face))))
146
147 ;; Syntax table
148
149 (defvar sieve-mode-syntax-table nil
150 "Syntax table in use in sieve-mode buffers.")
151
152 (if sieve-mode-syntax-table
153 ()
154 (setq sieve-mode-syntax-table (make-syntax-table))
155 (modify-syntax-entry ?\\ "\\" sieve-mode-syntax-table)
156 (modify-syntax-entry ?\n "> " sieve-mode-syntax-table)
157 (modify-syntax-entry ?\f "> " 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 (modify-syntax-entry ?\' "\"" sieve-mode-syntax-table))
171
172 ;; Key map definition
173
174 (defvar sieve-mode-map
175 (let ((map (make-sparse-keymap)))
176 (define-key map "\C-c\C-l" 'sieve-upload)
177 (define-key map "\C-c\C-c" 'sieve-upload-and-bury)
178 (define-key map "\C-c\C-m" 'sieve-manage)
179 map)
180 "Key map used in sieve mode.")
181
182 ;; Menu definition
183
184 (defvar sieve-mode-menu nil
185 "Menubar used in sieve mode.")
186
187 ;; Code for Sieve editing mode.
188
189 ;;;###autoload
190 (define-derived-mode sieve-mode c-mode "Sieve"
191 "Major mode for editing Sieve code.
192 This is much like C mode except for the syntax of comments. Its keymap
193 inherits from C mode's and it has the same variables for customizing
194 indentation. It has its own abbrev table and its own syntax table.
195
196 Turning on Sieve mode runs `sieve-mode-hook'."
197 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
198 (set (make-local-variable 'paragraph-separate) paragraph-start)
199 (set (make-local-variable 'comment-start) "#")
200 (set (make-local-variable 'comment-end) "")
201 ;;(set (make-local-variable 'comment-start-skip) "\\(^\\|\\s-\\);?#+ *")
202 (set (make-local-variable 'comment-start-skip) "#+ *")
203 (unless (featurep 'xemacs)
204 (set (make-local-variable 'font-lock-defaults)
205 '(sieve-font-lock-keywords nil nil ((?_ . "w")))))
206 (easy-menu-add-item nil nil sieve-mode-menu))
207
208 ;; Menu
209
210 (easy-menu-define sieve-mode-menu sieve-mode-map
211 "Sieve Menu."
212 '("Sieve"
213 ["Upload script" sieve-upload t]
214 ["Manage scripts on server" sieve-manage t]))
215
216 (provide 'sieve-mode)
217
218 ;;; arch-tag: 3b8ab76d-065d-4c52-b1e8-ab2ec21f2ace
219 ;; sieve-mode.el ends here