1 ;;; sieve-mode.el --- Sieve code editing commands for Emacs
2 ;; Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
4 ;; Author: Simon Josefsson <simon@josefsson.org>
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
25 ;; This file contain editing mode functions and font-lock support for
26 ;; editing Sieve scripts. It sets up C-mode with support for
27 ;; sieve-style #-comments and a lightly hacked syntax table. It was
28 ;; strongly influenced by awk-mode.el.
30 ;; Put something similar to the following in your .emacs to use this file:
32 ;; (load "~/lisp/sieve")
33 ;; (setq auto-mode-alist (cons '("\\.siv\\'" . sieve-mode) auto-mode-alist))
38 ;; "Sieve: A Mail Filtering Language",
43 ;; 2001-03-02 version 1.0 posted to gnu.emacs.sources
44 ;; version 1.1 change file extension into ".siv" (official one)
45 ;; added keymap and menubar to hook into sieve-manage
46 ;; 2001-10-31 version 1.2 committed to Oort Gnus
50 (autoload 'sieve-manage "sieve")
51 (autoload 'sieve-upload "sieve")
60 (defcustom sieve-mode-hook nil
61 "Hook run in sieve mode buffers."
67 (defvar sieve-control-commands-face 'sieve-control-commands-face
68 "Face name used for Sieve Control Commands.")
70 (defface sieve-control-commands-face
71 '((((type tty) (class color)) (:foreground "blue" :weight light))
72 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
73 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
74 (((class color) (background light)) (:foreground "Orchid"))
75 (((class color) (background dark)) (:foreground "LightSteelBlue"))
77 "Face used for Sieve Control Commands.")
79 (defvar sieve-action-commands-face 'sieve-action-commands-face
80 "Face name used for Sieve Action Commands.")
82 (defface sieve-action-commands-face
83 '((((type tty) (class color)) (:foreground "blue" :weight bold))
84 (((class color) (background light)) (:foreground "Blue"))
85 (((class color) (background dark)) (:foreground "LightSkyBlue"))
86 (t (:inverse-video t :bold t)))
87 "Face used for Sieve Action Commands.")
89 (defvar sieve-test-commands-face 'sieve-test-commands-face
90 "Face name used for Sieve Test Commands.")
92 (defface sieve-test-commands-face
93 '((((type tty) (class color)) (:foreground "magenta"))
94 (((class grayscale) (background light))
95 (:foreground "LightGray" :bold t :underline t))
96 (((class grayscale) (background dark))
97 (:foreground "Gray50" :bold t :underline t))
98 (((class color) (background light)) (:foreground "CadetBlue"))
99 (((class color) (background dark)) (:foreground "Aquamarine"))
100 (t (:bold t :underline t)))
101 "Face used for Sieve Test Commands.")
103 (defvar sieve-tagged-arguments-face 'sieve-tagged-arguments-face
104 "Face name used for Sieve Tagged Arguments.")
106 (defface sieve-tagged-arguments-face
107 '((((type tty) (class color)) (:foreground "cyan" :weight bold))
108 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
109 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
110 (((class color) (background light)) (:foreground "Purple"))
111 (((class color) (background dark)) (:foreground "Cyan"))
113 "Face used for Sieve Tagged Arguments.")
116 (defconst sieve-font-lock-keywords
120 (cons (regexp-opt '("require" "if" "else" "elsif" "stop"))
121 'sieve-control-commands-face)
123 (cons (regexp-opt '("fileinto" "redirect" "reject" "keep" "discard"))
124 'sieve-action-commands-face)
126 (cons (regexp-opt '("address" "allof" "anyof" "exists" "false"
127 "true" "header" "not" "size" "envelope"))
128 'sieve-test-commands-face)
130 'sieve-tagged-arguments-face))))
134 (defvar sieve-mode-syntax-table nil
135 "Syntax table in use in sieve-mode buffers.")
137 (if sieve-mode-syntax-table
139 (setq sieve-mode-syntax-table (make-syntax-table))
140 (modify-syntax-entry ?\\ "\\" sieve-mode-syntax-table)
141 (modify-syntax-entry ?\n "> " sieve-mode-syntax-table)
142 (modify-syntax-entry ?\f "> " sieve-mode-syntax-table)
143 (modify-syntax-entry ?\# "< " sieve-mode-syntax-table)
144 (modify-syntax-entry ?/ "." sieve-mode-syntax-table)
145 (modify-syntax-entry ?* "." sieve-mode-syntax-table)
146 (modify-syntax-entry ?+ "." sieve-mode-syntax-table)
147 (modify-syntax-entry ?- "." sieve-mode-syntax-table)
148 (modify-syntax-entry ?= "." sieve-mode-syntax-table)
149 (modify-syntax-entry ?% "." sieve-mode-syntax-table)
150 (modify-syntax-entry ?< "." sieve-mode-syntax-table)
151 (modify-syntax-entry ?> "." sieve-mode-syntax-table)
152 (modify-syntax-entry ?& "." sieve-mode-syntax-table)
153 (modify-syntax-entry ?| "." sieve-mode-syntax-table)
154 (modify-syntax-entry ?_ "_" sieve-mode-syntax-table)
155 (modify-syntax-entry ?\' "\"" sieve-mode-syntax-table))
157 ;; Key map definition
159 (defvar sieve-mode-map
160 (let ((map (make-sparse-keymap)))
161 (define-key map "\C-c\C-l" 'sieve-upload)
162 (define-key map "\C-c\C-c" 'sieve-upload-and-bury)
163 (define-key map "\C-c\C-m" 'sieve-manage)
165 "Key map used in sieve mode.")
169 (defvar sieve-mode-menu nil
170 "Menubar used in sieve mode.")
172 ;; Code for Sieve editing mode.
175 (define-derived-mode sieve-mode c-mode "Sieve"
176 "Major mode for editing Sieve code.
177 This is much like C mode except for the syntax of comments. Its keymap
178 inherits from C mode's and it has the same variables for customizing
179 indentation. It has its own abbrev table and its own syntax table.
181 Turning on Sieve mode runs `sieve-mode-hook'."
182 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
183 (set (make-local-variable 'paragraph-separate) paragraph-start)
184 (set (make-local-variable 'comment-start) "#")
185 (set (make-local-variable 'comment-end) "")
186 ;;(set (make-local-variable 'comment-start-skip) "\\(^\\|\\s-\\);?#+ *")
187 (set (make-local-variable 'comment-start-skip) "#+ *")
188 (unless (featurep 'xemacs)
189 (set (make-local-variable 'font-lock-defaults)
190 '(sieve-font-lock-keywords nil nil ((?_ . "w")))))
191 (easy-menu-add-item nil nil sieve-mode-menu))
195 (easy-menu-define sieve-mode-menu sieve-mode-map
198 ["Upload script" sieve-upload t]
199 ["Manage scripts on server" sieve-manage t]))
201 (provide 'sieve-mode)
203 ;; sieve-mode.el ends here