]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/mailabbrev.el
(mail-extr-disable-voodoo): New variable.
[gnu-emacs] / lisp / mail / mailabbrev.el
index f57141dcb0ec96e6d5496b5eed692b4eb7f1489d..1b94f179f949624dda5be9214b1d05fd393fc174 100644 (file)
@@ -1,6 +1,6 @@
 ;;; mailabbrev.el --- abbrev-expansion of mail aliases
 
-;; Copyright (C) 1985, 86, 87, 92, 93, 96, 1997, 2000, 2002
+;; Copyright (C) 1985, 86, 87, 92, 93, 96, 1997, 2000, 2002, 2003
 ;;     Free Software Foundation, Inc.
 
 ;; Author: Jamie Zawinski <jwz@lucid.com>, now <jwz@jwz.org>
@@ -30,7 +30,7 @@
 ;; This file ensures that, when the point is in a To:, CC:, BCC:, or From:
 ;; field, word-abbrevs are defined for each of your mail aliases.  These
 ;; aliases will be defined from your .mailrc file (or the file specified by
-;; the MAILRC environment variable) if it exists.  Your mail aliases will
+;; `mail-personal-alias-file') if it exists.  Your mail aliases will
 ;; expand any time you type a word-delimiter at the end of an abbreviation.
 ;;
 ;; What you see is what you get: if mailabbrev is in use when you type
@@ -42,7 +42,7 @@
 ;; Your mail alias abbrevs will be in effect only when the point is in an
 ;; appropriate header field.  When in the body of the message, or other
 ;; header fields, the mail aliases will not expand.  Rather, the normal
-;; mode-specific abbrev table (mail-mode-abbrev-table) will be used if
+;; mode-specific abbrev table will be used if
 ;; defined.  So if you use mail-mode specific abbrevs, this code will not
 ;; adversely affect you.  You can control which header fields the abbrevs
 ;; are used in by changing the variable mail-abbrev-mode-regexp.
 ;;  (add-hook
 ;;   'mail-mode-hook
 ;;   (lambda ()
-;;      (substitute-key-definition 'next-line 'mail-abbrev-next-line
-;;                              mail-mode-map global-map)
-;;      (substitute-key-definition 'end-of-buffer 'mail-abbrev-end-of-buffer
-;;                              mail-mode-map global-map)))
+;;      (define-key mail-mode-map [remap next-line] 'mail-abbrev-next-line)
+;;      (define-key mail-mode-map [remap end-of-buffer] 'mail-abbrev-end-of-buffer)))
 ;;
 ;; If you want multiple addresses separated by a string other than ", " then
 ;; you can set the variable mail-alias-separator-string to it.  This has to
@@ -163,12 +161,13 @@ no aliases, which is represented by this being a table with no entries.)")
   "The modification time of your mail alias file when it was last examined.")
 
 (defun mail-abbrevs-sync-aliases ()
-  (if (file-exists-p mail-personal-alias-file)
-      (let ((modtime (nth 5 (file-attributes mail-personal-alias-file))))
-       (if (not (equal mail-abbrev-modtime modtime))
-           (progn
-             (setq mail-abbrev-modtime modtime)
-             (build-mail-abbrevs))))))
+  (when mail-personal-alias-file
+    (if (file-exists-p mail-personal-alias-file)
+       (let ((modtime (nth 5 (file-attributes mail-personal-alias-file))))
+         (if (not (equal mail-abbrev-modtime modtime))
+             (progn
+               (setq mail-abbrev-modtime modtime)
+               (build-mail-abbrevs)))))))
 
 ;;;###autoload
 (defun mail-abbrevs-setup ()
@@ -317,7 +316,7 @@ If DEFINITION contains multiple addresses, separate them with commas."
   (setq name (downcase name))
   ;; use an abbrev table instead of an alist for mail-abbrevs.
   (let ((abbrevs-changed abbrevs-changed))  ; protect this from being changed.
-    (define-abbrev mail-abbrevs name definition 'mail-abbrev-expand-hook)))
+    (define-abbrev mail-abbrevs name definition 'mail-abbrev-expand-hook 0 t)))
 
 
 (defun mail-resolve-all-aliases ()
@@ -405,6 +404,27 @@ This is not actually made the current syntax table of the buffer, but
 simply controls the set of characters which may be a part of the name
 of a mail alias.  The value is set up, buffer-local, when first needed.")
 
+(defun mail-abbrev-make-syntax-table ()
+  (make-local-variable 'mail-abbrev-syntax-table)
+  (unless mail-abbrev-syntax-table
+    (let ((tab (copy-syntax-table (syntax-table)))
+         (_ (aref (standard-syntax-table) ?_))
+         (w (aref (standard-syntax-table) ?w)))
+      (map-char-table
+       (function (lambda (key value)
+                  (if (null value)
+                      ;; Fetch the inherited value
+                      (setq value (aref tab key)))
+                  (if (equal value _)
+                      (set-char-table-range tab key w))))
+       tab)
+      (modify-syntax-entry ?@ "w" tab)
+      (modify-syntax-entry ?% "w" tab)
+      (modify-syntax-entry ?! "w" tab)
+      (modify-syntax-entry ?. "w" tab)
+      (modify-syntax-entry ?_ "w" tab)
+      (modify-syntax-entry ?- "w" tab)
+      (setq mail-abbrev-syntax-table tab))))
 
 (defun mail-abbrev-in-expansion-header-p ()
   "Whether point is in a mail-address header field."
@@ -418,9 +438,12 @@ of a mail alias.  The value is set up, buffer-local, when first needed.")
        (looking-at mail-abbrev-mode-regexp))
      ;;
      ;; ...and are we in the headers?
-     (< (point) (mail-header-end)))))
-
-(defvar mail-mode-abbrev-table) ; quiet the compiler
+     (< (point)
+       (save-restriction
+         (widen)
+         (save-excursion
+           (rfc822-goto-eoh)
+           (point)))))))
 
 (defun sendmail-pre-abbrev-expand-hook ()
   (and (and mail-abbrevs (not (eq mail-abbrevs t)))
@@ -454,17 +477,7 @@ of a mail alias.  The value is set up, buffer-local, when first needed.")
             ;;      expand-abbrev, and not as a result of the call to
             ;;      expand-abbrev which invoked *us*.
 
-            (make-local-variable 'mail-abbrev-syntax-table)
-            (unless mail-abbrev-syntax-table
-              (let ((tab (copy-syntax-table old-syntax-table))
-                    (_ (aref (standard-syntax-table) ?_))
-                    (w (aref (standard-syntax-table) ?w)))
-                (map-char-table
-                 (function (lambda (key value)
-                             (if (equal value _)
-                                 (set-char-table-range tab key w))))
-                 tab)
-                (setq mail-abbrev-syntax-table tab)))
+            (mail-abbrev-make-syntax-table)
 
             ;; If the character just typed was non-alpha-symbol-syntax,
             ;; then don't expand the abbrev now (that is, don't expand
@@ -540,6 +553,7 @@ of a mail alias.  The value is set up, buffer-local, when first needed.")
   "Perform completion on alias preceding point."
   ;; Based on lisp.el:lisp-complete-symbol
   (interactive)
+  (mail-abbrev-make-syntax-table)
   (let* ((end (point))
         (syntax-table (syntax-table))
         (beg (unwind-protect
@@ -598,9 +612,11 @@ Don't use this command in Lisp programs!
   (setq this-command 'end-of-buffer)
   (end-of-buffer arg))
 
-(define-key mail-mode-map "\C-c\C-a" 'mail-abbrev-insert-alias)
-(define-key mail-mode-map "\e\t"       ; like lisp-complete-symbol
-  'mail-abbrev-complete-alias) 
+(eval-after-load "sendmail"
+  '(progn
+     (define-key mail-mode-map "\C-c\C-a" 'mail-abbrev-insert-alias)
+     (define-key mail-mode-map "\e\t"  ; like lisp-complete-symbol
+       'mail-abbrev-complete-alias)))
 
 ;;(define-key mail-mode-map "\C-n" 'mail-abbrev-next-line)
 ;;(define-key mail-mode-map "\M->" 'mail-abbrev-end-of-buffer)
@@ -610,4 +626,5 @@ Don't use this command in Lisp programs!
 (if mail-abbrevs-mode
     (mail-abbrevs-enable))
 
+;;; arch-tag: 5aa2d901-73f8-4ad7-b73c-4802282ad2ff
 ;;; mailabbrev.el ends here