]> code.delx.au - gnu-emacs/blobdiff - lisp/mh-e/mh-alias.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / mh-e / mh-alias.el
index a1bafb3ec5188348dabb545d2a6f4ca0f8d761c9..bb427ef889e73e744f0c78f8a36b1be66dc69303 100644 (file)
@@ -1,7 +1,7 @@
 ;;; mh-alias.el --- MH-E mail alias completion and expansion
-;;
+
 ;; Copyright (C) 1994, 1995, 1996, 1997,
-;;  2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+;;  2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author: Peter S. Galbraith <psg@debian.org>
 ;; Maintainer: Bill Wohler <wohler@newt.com>
@@ -12,7 +12,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 
 ;;; Code:
 
-(eval-when-compile (require 'mh-acros))
-(mh-require-cl)
 (require 'mh-e)
-(load "cmr" t t)                        ; Non-fatal dependency for
-                                       ; completing-read-multiple.
-(eval-when-compile (defvar mail-abbrev-syntax-table))
-
-\f
 
-;;; Autoloads
+(mh-require-cl)
 
-(eval-when (compile load eval)
-  (ignore-errors
-    (require 'mailabbrev)
-    (require 'multi-prompt)))
+(require 'goto-addr)
 
 (defvar mh-alias-alist 'not-read
   "Alist of MH aliases.")
@@ -58,7 +48,7 @@
 (defvar mh-alias-read-address-map nil)
 (unless mh-alias-read-address-map
   (setq mh-alias-read-address-map
-       (copy-keymap minibuffer-local-completion-map))
+        (copy-keymap minibuffer-local-completion-map))
   (define-key mh-alias-read-address-map
     "," 'mh-alias-minibuffer-confirm-address)
   (define-key mh-alias-read-address-map " " 'self-insert-command))
@@ -132,10 +122,10 @@ COMMA-SEPARATOR is non-nil."
         (setq res (match-string 1 res)))
     ;; Replace "&" with capitalized username
     (if (string-match "&" res)
-        (setq res (mh-replace-in-string "&" (capitalize username) res)))
+        (setq res (mh-replace-regexp-in-string "&" (capitalize username) res)))
     ;; Remove " character
     (if (string-match "\"" res)
-        (setq res (mh-replace-in-string "\"" "" res)))
+        (setq res (mh-replace-regexp-in-string "\"" "" res)))
     ;; If empty string, use username instead
     (if (string-equal "" res)
         (setq res username))
@@ -176,13 +166,12 @@ Exclude all aliases already in `mh-alias-alist' from \"ali\""
                     (if (string-equal username realname)
                         (concat "<" username ">")
                       (concat realname " <" username ">"))))
-              (when (not (mh-assoc-ignore-case alias-name mh-alias-alist))
+              (when (not (mh-assoc-string alias-name mh-alias-alist t))
                 (setq passwd-alist (cons (list alias-name alias-translation)
                                          passwd-alist)))))))
         (forward-line 1)))
     passwd-alist))
 
-;;;###mh-autoload
 (defun mh-alias-reload ()
   "Reload MH aliases.
 
@@ -206,12 +195,12 @@ been loaded."
       (cond
        ((looking-at "^[ \t]"))          ;Continuation line
        ((looking-at "\\(.+\\): .+: .*$") ; A new -blind- MH alias
-        (when (not (mh-assoc-ignore-case (match-string 1) mh-alias-blind-alist))
+        (when (not (mh-assoc-string (match-string 1) mh-alias-blind-alist t))
           (setq mh-alias-blind-alist
                 (cons (list (match-string 1)) mh-alias-blind-alist))
           (setq mh-alias-alist (cons (list (match-string 1)) mh-alias-alist))))
        ((looking-at "\\(.+\\): .*$")    ; A new MH alias
-        (when (not (mh-assoc-ignore-case (match-string 1) mh-alias-alist))
+        (when (not (mh-assoc-string (match-string 1) mh-alias-alist t))
           (setq mh-alias-alist
                 (cons (list (match-string 1)) mh-alias-alist)))))
       (forward-line 1)))
@@ -222,7 +211,7 @@ been loaded."
           user)
       (while local-users
         (setq user (car local-users))
-        (if (not (mh-assoc-ignore-case (car user) mh-alias-alist))
+        (if (not (mh-assoc-string (car user) mh-alias-alist t))
             (setq mh-alias-alist (append mh-alias-alist (list user))))
         (setq local-users (cdr local-users)))))
   (run-hooks 'mh-alias-reloaded-hook)
@@ -255,22 +244,26 @@ returns the string unchanged if not defined. The same is done here."
              (message "%s" (error-message-string err))
              alias))))
 
+;;;###mh-autoload
 (defun mh-alias-expand (alias)
   "Return expansion for ALIAS.
 Blind aliases or users from /etc/passwd are not expanded."
   (cond
-   ((mh-assoc-ignore-case alias mh-alias-blind-alist)
+   ((mh-assoc-string alias mh-alias-blind-alist t)
     alias)                              ; Don't expand a blind alias
-   ((mh-assoc-ignore-case alias mh-alias-passwd-alist)
-    (cadr (mh-assoc-ignore-case alias mh-alias-passwd-alist)))
+   ((mh-assoc-string alias mh-alias-passwd-alist t)
+    (cadr (mh-assoc-string alias mh-alias-passwd-alist t)))
    (t
     (mh-alias-ali alias))))
 
+(mh-require 'crm nil t)                 ; completing-read-multiple
+(mh-require 'multi-prompt nil t)
+
 ;;;###mh-autoload
 (defun mh-read-address (prompt)
   "Read an address from the minibuffer with PROMPT."
   (mh-alias-reload-maybe)
-  (if (not mh-alias-alist)             ; If still no aliases, just prompt
+  (if (not mh-alias-alist)              ; If still no aliases, just prompt
       (read-string prompt)
     (let* ((minibuffer-local-completion-map mh-alias-read-address-map)
            (completion-ignore-case mh-alias-completion-ignore-case-flag)
@@ -297,7 +290,7 @@ Blind aliases or users from /etc/passwd are not expanded."
       (let* ((case-fold-search t)
              (beg (mh-beginning-of-word))
              (the-name (buffer-substring-no-properties beg (point))))
-        (if (mh-assoc-ignore-case the-name mh-alias-alist)
+        (if (mh-assoc-string the-name mh-alias-alist t)
             (message "%s -> %s" the-name (mh-alias-expand the-name))
           ;; Check if if was a single word likely to be an alias
           (if (and (equal mh-alias-flash-on-comma 1)
@@ -305,8 +298,6 @@ Blind aliases or users from /etc/passwd are not expanded."
               (message "No alias for %s" the-name))))))
   (self-insert-command 1))
 
-(mh-do-in-xemacs (defvar mail-abbrevs))
-
 ;;;###mh-autoload
 (defun mh-alias-letter-expand-alias ()
   "Expand mail alias before point."
@@ -320,9 +311,10 @@ Blind aliases or users from /etc/passwd are not expanded."
              (expansion (mh-alias-expand (buffer-substring begin end))))
         (delete-region begin end)
         (insert expansion)))))
+
 \f
 
-;;; Adding addresses to alias file.
+;;; Alias File Updating
 
 (defun mh-alias-suggest-alias (string &optional no-comma-swap)
   "Suggest an alias for STRING.
@@ -349,7 +341,7 @@ NO-COMMA-SWAP is non-nil."
    ((string-match "^\\(.*\\) +<.*>$" string)
     ;; Some name <somename@foo.bar>  -> recurse -> Some name
     (mh-alias-suggest-alias (match-string 1 string) no-comma-swap))
-   ((string-match (concat mh-address-mail-regexp " +(\\(.*\\))$") string)
+   ((string-match (concat goto-address-mail-regexp " +(\\(.*\\))$") string)
     ;; somename@foo.bar (Some name)  -> recurse -> Some name
     (mh-alias-suggest-alias (match-string 1 string) no-comma-swap))
    ((string-match "^\\(Dr\\|Prof\\)\\.? +\\(.*\\)" string)
@@ -448,8 +440,8 @@ contains it."
                                      (mh-alias-filenames t)))))
       (cond
        ((not autolist)
-        (error "No writable alias file.
-Set `mh-alias-insert-file' or the \"Aliasfile:\" profile component"))
+        (error "No writable alias file;
+set `mh-alias-insert-file' or the \"Aliasfile:\" profile component"))
        ((not (elt autolist 1))        ; Only one entry, use it
         (car autolist))
        ((or (not alias)
@@ -546,7 +538,6 @@ folder name hint when filing messages."
     (insert (format "%s: %s\n" alias address))
     (save-buffer)))
 
-;;;###mh-autoload
 (defun mh-alias-add-alias (alias address)
   "Add ALIAS for ADDRESS in personal alias file.
 
@@ -599,16 +590,14 @@ filing messages."
            (alias (mh-alias-suggest-alias address)))
       (mh-alias-add-alias alias address))))
 
-;;;###mh-autoload
 (defun mh-alias-add-address-under-point ()
   "Insert an alias for address under point."
   (interactive)
-  (let ((address (mh-goto-address-find-address-at-point)))
+  (let ((address (goto-address-find-address-at-point)))
     (if address
         (mh-alias-add-alias nil address)
       (message "No email address found under point"))))
 
-;;;###mh-autoload
 (defun mh-alias-apropos (regexp)
   "Show all aliases or addresses that match a regular expression REGEXP."
   (interactive "sAlias regexp: ")
@@ -665,6 +654,21 @@ filing messages."
           (princ "\nLocal User Aliases:\n\n")
           (princ passwd-matches))))))
 
+(defun mh-folder-line-matches-show-buffer-p ()
+  "Return t if the message under point in folder-mode is in the show buffer.
+Return nil in any other circumstance (no message under point, no
+show buffer, the message in the show buffer doesn't match."
+  (and (eq major-mode 'mh-folder-mode)
+       (mh-get-msg-num nil)
+       mh-show-buffer
+       (get-buffer mh-show-buffer)
+       (buffer-file-name (get-buffer mh-show-buffer))
+       (string-match ".*/\\([0-9]+\\)$"
+                     (buffer-file-name (get-buffer mh-show-buffer)))
+       (string-equal
+        (match-string 1 (buffer-file-name (get-buffer mh-show-buffer)))
+        (int-to-string (mh-get-msg-num nil)))))
+
 (provide 'mh-alias)
 
 ;; Local Variables: