]> Pileus Git - ~andy/fetchmail/blob - contrib/fetchmail-mode.el
Minor bug fixes for socket.c
[~andy/fetchmail] / contrib / fetchmail-mode.el
1 ;; fetchmail-mode.el        -*- Emacs-Lisp -*-
2 ;;
3 ;; Mode for editing .fetchmailrc files
4 ;;
5 ;; Created:    <Mon Oct 30 20:13:15 EST 2000>
6 ;; Time-stamp: <17.02.2001 17:59:43>
7 ;; Version:    0.1
8 ;; Keywords:   fetchmail,config
9 ;; Author:     Alex Shinn <foof@debian.org>
10 ;;
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2 of
14 ;; the License, or (at your option) any later version.
15 ;;
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20 ;;
21 ;; You should have received a copy of the GNU General Public
22 ;; License along with this program; if not, write to the Free
23 ;; Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 ;; MA 02111-1307 USA
25
26 ;; Commentary:
27 ;;
28 ;; This file provides a major mode for editing .fetchmailrc files.
29 ;; It offers syntax highlighting and indentation.
30 ;;
31 ;; To use it, put the following in your .emacs:
32 ;;
33 ;; (autoload 'fetchmail-mode "fetchmail-mode.el" "Mode for editing .fetchmailrc files" t)
34 ;;
35 ;; You may also want something like:
36 ;;
37 ;; (setq auto-mode-alist
38 ;;       (append '(("\..fetchmailrc$" . fetchmail-mode))
39 ;;               auto-mode-alist))
40
41 ;; Create mode-specific tables.
42 (defvar fetchmail-mode-syntax-table nil
43   "Syntax table used while in fetchmail-mode" )
44 (if fetchmail-mode-syntax-table
45     ()              ; Do not change the table if it is already set up.
46   (setq fetchmail-mode-syntax-table (make-syntax-table))
47   (modify-syntax-entry ?\\ "\\   " fetchmail-mode-syntax-table)
48   (modify-syntax-entry ?\,  "." fetchmail-mode-syntax-table)
49   (modify-syntax-entry ?\:  "." fetchmail-mode-syntax-table)
50   (modify-syntax-entry ?\;  "." fetchmail-mode-syntax-table)
51   (modify-syntax-entry ?\"  "\"" fetchmail-mode-syntax-table)
52   (modify-syntax-entry ?\'  "\"" fetchmail-mode-syntax-table)
53   (modify-syntax-entry ?\n  "> " fetchmail-mode-syntax-table)
54   (modify-syntax-entry ?\#  "< " fetchmail-mode-syntax-table)
55   (modify-syntax-entry ?\( "()   " fetchmail-mode-syntax-table)
56   (modify-syntax-entry ?\) ")(   " fetchmail-mode-syntax-table)
57   (modify-syntax-entry ?\[ "(]   " fetchmail-mode-syntax-table)
58   (modify-syntax-entry ?\] ")[   " fetchmail-mode-syntax-table)
59   (modify-syntax-entry ?\{ "(}   " fetchmail-mode-syntax-table)
60   (modify-syntax-entry ?\} "){   " fetchmail-mode-syntax-table)
61   )
62
63 (defvar fetchmail-mode-map nil
64   "Keymap used in fetchmail-mode" )
65
66 (if fetchmail-mode-map nil
67   (setq fetchmail-mode-map (make-sparse-keymap))
68   (define-key fetchmail-mode-map "\t" 'fetchmail-complete)
69   (define-key fetchmail-mode-map "\C-c\C-c" 'comment-region) )
70 (defvar fetchmail-mode-hook nil
71   "Hooks to run in fetchmail-mode" )
72
73 (defvar fetchmail-keywords nil
74   "Keywords used for fetchmail-mode" )
75
76 (unless fetchmail-keywords
77    (setq fetchmail-keywords
78           '("poll" "skip" "via" "in" "proto" "protocol" "uidl" "no" "port" "auth" "authenticate" "timeout" "envelope" "qvirtual" "envelope" "aka" "localdomains" "interface" "monitor" "dns" "user" "username" "is" "folder" "pass" "password" "smtp" "smtphost" "smtpaddress" "antispam" "mda" "pre" "preconnect" "post" "postconnect" "keep" "flush" "fetchall" "rewrite" "forcecr" "stripcr" "pass8bits" "dropstatus" "limit" "fetchlimit" "batchlimit" "expunge" "pop2" "POP2" "pop3" "POP3" "imap" "IMAP" "imap-k4" "IMAP-K4" "apop" "APOP" "rpop" "RPOP" "kpop" "KPOP" "etrn" "ETRN" "login" "kerberos" "kerberos_v5" "logfile" "daemon" "syslog" "invisible" "and" "with" "has" "wants" "options" "here" "there" "aka" "set")))
79
80 (defvar fetchmail-keyword-table nil
81   "Completion table for fetchmail-mode" )
82 (unless fetchmail-keyword-table
83   (setq fetchmail-keyword-table (make-vector 8 0))
84   (mapcar (lambda (x) (intern x fetchmail-keyword-table))
85           fetchmail-keywords))
86
87 (defvar fetchmail-font-lock-keywords nil
88   "Default expressions to highlight in fetchmail-mode" )
89
90 (unless fetchmail-font-lock-keywords
91   (setq fetchmail-font-lock-keywords
92         (list (list (concat "\\b" (regexp-opt
93                                    fetchmail-keywords t) "\\b")
94                     0 'font-lock-keyword-face ))))
95
96 (defun fetchmail-complete ()
97   "Tab completion for fetchmail-mode"
98   (interactive)
99   (let* ((end (point))
100          (beg (save-excursion
101                 (skip-syntax-backward "w")
102                 (point)))
103          (pattern (buffer-substring beg end))
104          (table fetchmail-keyword-table)
105          (completion (try-completion pattern table)))
106     (cond ((eq completion t))
107           ((null completion)
108            (error "Can't find completion for \"%s\"" pattern))
109           ((not (string-equal pattern completion))
110            (delete-region beg end)
111            (insert completion))
112           (t
113            (message "Making completion list...")
114            (let ((list (all-completions pattern table)))
115              (if (fboundp 'prettify)
116                  (setq list (funcall 'prettify list)))
117              (with-output-to-temp-buffer "*Help*"
118                (display-completion-list list)))
119            (message "Making completion list...%s" "done")))))
120
121
122 (defun fetchmail-mode ()
123   "Mode for editing .fetchmailrc files"
124   (interactive)
125   (kill-all-local-variables)
126   (use-local-map fetchmail-mode-map)    ; This provides the local keymap.
127   (setq mode-name "Fetchmail")          ; This name goes into the modeline.
128   (setq major-mode 'fetchmail-mode)     ; Used by `describe-mode'
129   (run-hooks 'fetchmail-mode-hook)      ; Run each time mode is called
130   (set-syntax-table fetchmail-mode-syntax-table)
131
132   ;; -cc-
133   ;; Font lock support
134   (make-local-variable 'font-lock-defaults)
135   (setq font-lock-defaults '(fetchmail-font-lock-keywords nil t))
136
137   (setq comment-start "#")
138   )
139
140
141
142 (provide 'fetchmail-mode)