[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/lisp/mail/mailabbrev.el,v
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] Changes to emacs/lisp/mail/mailabbrev.el,v |
Date: |
Wed, 31 Oct 2007 20:30:30 +0000 |
CVSROOT: /sources/emacs
Module name: emacs
Changes by: Stefan Monnier <monnier> 07/10/31 20:30:29
Index: mail/mailabbrev.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/mail/mailabbrev.el,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -b -r1.86 -r1.87
--- mail/mailabbrev.el 31 Oct 2007 06:28:08 -0000 1.86
+++ mail/mailabbrev.el 31 Oct 2007 20:30:27 -0000 1.87
@@ -133,19 +133,16 @@
"Expand mail aliases as abbrevs, in certain mail headers."
:group 'abbrev-mode)
-(defcustom mail-abbrevs-mode nil
- "*Non-nil means expand mail aliases as abbrevs, in certain message headers."
- :type 'boolean
+;;;###autoload
+(define-minor-mode mail-abbrevs-mode
+ "Non-nil means expand mail aliases as abbrevs, in certain message headers."
+ :global t
:group 'mail-abbrev
- :require 'mailabbrev
- :set (lambda (symbol value)
- (setq mail-abbrevs-mode value)
- (if value (mail-abbrevs-enable) (mail-abbrevs-disable)))
- :initialize 'custom-initialize-default
- :version "20.3")
+ :version "20.3"
+ (if mail-abbrevs-mode (mail-abbrevs-enable) (mail-abbrevs-disable)))
(defcustom mail-abbrevs-only nil
- "*Non-nil means only mail abbrevs should expand automatically.
+ "Non-nil means only mail abbrevs should expand automatically.
Other abbrevs expand only when you explicitly use `expand-abbrev'."
:type 'boolean
:group 'mail-abbrev)
@@ -179,8 +176,7 @@
(nth 5 (file-attributes mail-personal-alias-file)))
(build-mail-abbrevs)))
(mail-abbrevs-sync-aliases)
- (add-hook 'pre-abbrev-expand-hook 'sendmail-pre-abbrev-expand-hook
- nil t)
+ (add-hook 'abbrev-expand-functions 'mail-abbrev-expand-wrapper nil t)
(abbrev-mode 1))
(defun mail-abbrevs-enable ()
@@ -201,16 +197,10 @@
(setq mail-abbrevs nil)
(define-abbrev-table 'mail-abbrevs '()))
(message "Parsing %s..." file)
- (let ((buffer nil)
- (obuf (current-buffer)))
- (unwind-protect
- (progn
- (setq buffer (generate-new-buffer " mailrc"))
- (buffer-disable-undo buffer)
- (set-buffer buffer)
+ (with-temp-buffer
+ (buffer-disable-undo)
(cond ((get-file-buffer file)
- (insert (save-excursion
- (set-buffer (get-file-buffer file))
+ (insert (with-current-buffer (get-file-buffer file)
(buffer-substring (point-min) (point-max)))))
((not (file-exists-p file)))
(t (insert-file-contents file)))
@@ -246,7 +236,7 @@
(match-beginning 1) (match-end 1)))
(start (progn (skip-chars-forward " \t") (point))))
(end-of-line)
-; (message "** %s \"%s\"" name (buffer-substring start
(point)))(sit-for 1)
+ ;; (message "** %s \"%s\"" name (buffer-substring start
(point)))(sit-for 1)
(define-mail-abbrev
name
(buffer-substring start (point))
@@ -256,8 +246,6 @@
;; expanded, but why not do it now.
(or recursivep (mail-resolve-all-aliases))
mail-abbrevs)
- (if buffer (kill-buffer buffer))
- (set-buffer obuf)))
(message "Parsing %s... done" file))
(defvar mail-alias-separator-string ", "
@@ -280,12 +268,7 @@
;; true, and we do some evil space->comma hacking like /bin/mail does.
(interactive "sDefine mail alias: \nsDefine %s as mail alias for: ")
;; Read the defaults first, if we have not done so.
- (if (vectorp mail-abbrevs)
- nil
- (setq mail-abbrevs nil)
- (define-abbrev-table 'mail-abbrevs '())
- (if (file-exists-p mail-personal-alias-file)
- (build-mail-abbrevs)))
+ (unless (vectorp mail-abbrevs) (build-mail-abbrevs))
;; strip garbage from front and end
(if (string-match "\\`[ \t\n,]+" definition)
(setq definition (substring definition (match-end 0))))
@@ -454,14 +437,13 @@
(rfc822-goto-eoh)
(point)))))))
-(defun sendmail-pre-abbrev-expand-hook ()
- (and (and mail-abbrevs (not (eq mail-abbrevs t)))
+(defun mail-abbrev-expand-wrapper (expand)
+ (if (and mail-abbrevs (not (eq mail-abbrevs t)))
(if (mail-abbrev-in-expansion-header-p)
;; We are in a To: (or CC:, or whatever) header, and
;; should use word-abbrevs to expand mail aliases.
- (let ((local-abbrev-table mail-abbrevs)
- (old-syntax-table (syntax-table)))
+ (let ((local-abbrev-table mail-abbrevs))
;; Before anything else, resolve aliases if they need it.
(and mail-abbrev-aliases-need-to-be-resolved
@@ -476,15 +458,8 @@
;; because the C code for expand-abbrev only works on words,
;; and we want these characters to be considered words for
;; the purpose of abbrev expansion.
- ;; - Then we call expand-abbrev again, recursively, to do
+ ;; - Then we call the expand function, to do
;; the abbrev expansion with the above syntax table.
- ;; - Restore the previous syntax table.
- ;; - Then we do a trick which tells the expand-abbrev frame
- ;; which invoked us to not continue (and thus not
- ;; expand twice.) This means that any abbrev expansion
- ;; will happen as a result of this function's call to
- ;; expand-abbrev, and not as a result of the call to
- ;; expand-abbrev which invoked *us*.
(mail-abbrev-make-syntax-table)
@@ -499,27 +474,21 @@
(or (eq (char-syntax last-command-char) ?_)
;; Don't expand on @.
(memq last-command-char '(?@ ?. ?% ?! ?_ ?-))))
- (let ((pre-abbrev-expand-hook nil)) ; That's us; don't loop.
;; Use this table so that abbrevs can have hyphens in them.
- (set-syntax-table mail-abbrev-syntax-table)
- (unwind-protect
- (expand-abbrev)
- ;; Now set it back to what it was before.
- (set-syntax-table old-syntax-table))))
- (setq abbrev-start-location (point-max) ; This is the trick.
- abbrev-start-location-buffer (current-buffer)))
+ (with-syntax-table mail-abbrev-syntax-table
+ (funcall expand))))
(if (or (not mail-abbrevs-only)
(eq this-command 'expand-abbrev))
;; We're not in a mail header where mail aliases should
;; be expanded, then use the normal mail-mode abbrev table
;; (if any) and the normal mail-mode syntax table.
- nil
+ (funcall expand)
;; This is not a mail abbrev, and we should not expand it.
- ;; This kludge stops expand-abbrev from doing anything.
- (setq abbrev-start-location (point-max)
- abbrev-start-location-buffer (current-buffer))))
- ))
+ ;; Don't expand anything.
+ nil))
+ ;; No mail-abbrevs at all, do the normal thing.
+ (funcall expand)))
;;; utilities
@@ -568,13 +537,10 @@
(interactive)
(mail-abbrev-make-syntax-table)
(let* ((end (point))
- (syntax-table (syntax-table))
- (beg (unwind-protect
+ (beg (with-syntax-table mail-abbrev-syntax-table
(save-excursion
- (set-syntax-table mail-abbrev-syntax-table)
(backward-word 1)
- (point))
- (set-syntax-table syntax-table)))
+ (point))))
(alias (buffer-substring beg end))
(completion (try-completion alias mail-abbrevs)))
(cond ((eq completion t)
@@ -638,8 +604,5 @@
(provide 'mailabbrev)
-(if mail-abbrevs-mode
- (mail-abbrevs-enable))
-
-;;; arch-tag: 5aa2d901-73f8-4ad7-b73c-4802282ad2ff
+;; arch-tag: 5aa2d901-73f8-4ad7-b73c-4802282ad2ff
;;; mailabbrev.el ends here