sieve-mode.el 7.8 KB

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