(latexenc-find-file-coding-system): Don't inherit the EOL part of the
[emacs.git] / lisp / gnus / sieve-mode.el
blobc4d019da6dfedaad50b5a7de1d74b4ca3de770d1
1 ;;; sieve-mode.el --- Sieve code editing commands for Emacs
2 ;; Copyright (C) 2001, 2002, 2003, 2005 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)
11 ;; any later version.
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.
23 ;;; Commentary:
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))
35 ;; References:
37 ;; RFC 3028,
38 ;; "Sieve: A Mail Filtering Language",
39 ;; by Tim Showalter.
41 ;; Release history:
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
48 ;;; Code:
50 (autoload 'sieve-manage "sieve")
51 (autoload 'sieve-upload "sieve")
52 (autoload 'c-mode "cc-mode")
53 (require 'easymenu)
54 (eval-when-compile
55 (require 'font-lock))
57 (defgroup sieve nil
58 "Sieve."
59 :group 'languages)
61 (defcustom sieve-mode-hook nil
62 "Hook run in sieve mode buffers."
63 :group 'sieve
64 :type 'hook)
66 ;; Font-lock
68 (defvar sieve-control-commands-face 'sieve-control-commands-face
69 "Face name used for Sieve Control Commands.")
71 (defface sieve-control-commands-face
72 '((((type tty) (class color)) (:foreground "blue" :weight light))
73 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
74 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
75 (((class color) (background light)) (:foreground "Orchid"))
76 (((class color) (background dark)) (:foreground "LightSteelBlue"))
77 (t (:bold t)))
78 "Face used for Sieve Control Commands."
79 :group 'sieve)
81 (defvar sieve-action-commands-face 'sieve-action-commands-face
82 "Face name used for Sieve Action Commands.")
84 (defface sieve-action-commands-face
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)))
89 "Face used for Sieve Action Commands."
90 :group 'sieve)
92 (defvar sieve-test-commands-face 'sieve-test-commands-face
93 "Face name used for Sieve Test Commands.")
95 (defface sieve-test-commands-face
96 '((((type tty) (class color)) (:foreground "magenta"))
97 (((class grayscale) (background light))
98 (:foreground "LightGray" :bold t :underline t))
99 (((class grayscale) (background dark))
100 (:foreground "Gray50" :bold t :underline t))
101 (((class color) (background light)) (:foreground "CadetBlue"))
102 (((class color) (background dark)) (:foreground "Aquamarine"))
103 (t (:bold t :underline t)))
104 "Face used for Sieve Test Commands."
105 :group 'sieve)
107 (defvar sieve-tagged-arguments-face 'sieve-tagged-arguments-face
108 "Face name used for Sieve Tagged Arguments.")
110 (defface sieve-tagged-arguments-face
111 '((((type tty) (class color)) (:foreground "cyan" :weight bold))
112 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
113 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
114 (((class color) (background light)) (:foreground "Purple"))
115 (((class color) (background dark)) (:foreground "Cyan"))
116 (t (:bold t)))
117 "Face used for Sieve Tagged Arguments."
118 :group 'sieve)
121 (defconst sieve-font-lock-keywords
122 (eval-when-compile
123 (list
124 ;; control commands
125 (cons (regexp-opt '("require" "if" "else" "elsif" "stop"))
126 'sieve-control-commands-face)
127 ;; action commands
128 (cons (regexp-opt '("fileinto" "redirect" "reject" "keep" "discard"))
129 'sieve-action-commands-face)
130 ;; test commands
131 (cons (regexp-opt '("address" "allof" "anyof" "exists" "false"
132 "true" "header" "not" "size" "envelope"))
133 'sieve-test-commands-face)
134 (cons "\\Sw+:\\sw+"
135 'sieve-tagged-arguments-face))))
137 ;; Syntax table
139 (defvar sieve-mode-syntax-table nil
140 "Syntax table in use in sieve-mode buffers.")
142 (if sieve-mode-syntax-table
144 (setq sieve-mode-syntax-table (make-syntax-table))
145 (modify-syntax-entry ?\\ "\\" sieve-mode-syntax-table)
146 (modify-syntax-entry ?\n "> " sieve-mode-syntax-table)
147 (modify-syntax-entry ?\f "> " 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)
156 (modify-syntax-entry ?> "." 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))
162 ;; Key map definition
164 (defvar sieve-mode-map
165 (let ((map (make-sparse-keymap)))
166 (define-key map "\C-c\C-l" 'sieve-upload)
167 (define-key map "\C-c\C-c" 'sieve-upload-and-bury)
168 (define-key map "\C-c\C-m" 'sieve-manage)
169 map)
170 "Key map used in sieve mode.")
172 ;; Menu definition
174 (defvar sieve-mode-menu nil
175 "Menubar used in sieve mode.")
177 ;; Code for Sieve editing mode.
179 ;;;###autoload
180 (define-derived-mode sieve-mode c-mode "Sieve"
181 "Major mode for editing Sieve code.
182 This is much like C mode except for the syntax of comments. Its keymap
183 inherits from C mode's and it has the same variables for customizing
184 indentation. It has its own abbrev table and its own syntax table.
186 Turning on Sieve mode runs `sieve-mode-hook'."
187 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
188 (set (make-local-variable 'paragraph-separate) paragraph-start)
189 (set (make-local-variable 'comment-start) "#")
190 (set (make-local-variable 'comment-end) "")
191 ;;(set (make-local-variable 'comment-start-skip) "\\(^\\|\\s-\\);?#+ *")
192 (set (make-local-variable 'comment-start-skip) "#+ *")
193 (unless (featurep 'xemacs)
194 (set (make-local-variable 'font-lock-defaults)
195 '(sieve-font-lock-keywords nil nil ((?_ . "w")))))
196 (easy-menu-add-item nil nil sieve-mode-menu))
198 ;; Menu
200 (easy-menu-define sieve-mode-menu sieve-mode-map
201 "Sieve Menu."
202 '("Sieve"
203 ["Upload script" sieve-upload t]
204 ["Manage scripts on server" sieve-manage t]))
206 (provide 'sieve-mode)
208 ;;; arch-tag: 3b8ab76d-065d-4c52-b1e8-ab2ec21f2ace
209 ;; sieve-mode.el ends here