From: carlisle@cs.man.ac.uk (David Carlisle)
Newsgroups: gnu.emacs.help
Subject: Re: mail alias chooser???
Date: 7 Sep 92 16:27:42 GMT
Organization: Department of Computer Science, University of Manchester
In-reply-to: dsmith@mailhost.aa.cad.slb.com's message of 3 Sep 92 03:10:54 GMT

>>>>> On 3 Sep 92 03:10:54 GMT, dsmith@mailhost.aa.cad.slb.com (J. Daniel Smith) said:

JDS> Does have ELISP code that implements an "ispell"-like chooser for mail
JDS> aliases?

JDS> What I am looking for is an interactive way to select mail aliases
JDS> that are defined in my ~/.mailrc file when composing a message.  A way
JDS> I thought would work well is to present a list of mail aliases in a
JDS> way similiar to what "ispell" does for word choices...

What I use is this. It puts makes M-Tab complete a partially typed
mailalias and C-x C-e  expand all aliases in the To and CC fields.
(These keybindings are only suggestions)

Not quite like ispell but try it and see...

David


;;;
;;; mail alias functions
;;;
;;;
;;; David Carlisle 26 August 1992

;;; To get this to work you need to bind them to keys in you mail-mode hook
;;;
;;; add the lines
;;;  (define-key mail-mode-map "\C-c\C-e" 'my-expand-mailalias)
;;;  (define-key mail-mode-map "\M-\t" 'mailalias-complete)

;;; you also need to load the file by adding
;;; (load "mail-alias" nil t)
;;; to your .emacs.

;;; Then C-e should expand a mail alias.
;;; M-TAB should complete a partly typed alias.

(defun mailalias-complete ( )
  "Attempts to complete a partially typed mail alias
  Displays possible completions in the help buffer if no
  unique completion can be done."
  (interactive)
  (forward-word -1)
    (let* ((c-begin (point))
          (word (buffer-substring c-begin 
				  (progn   (forward-word 1) (point))))
          (comp (try-completion word mail-aliases)))
;; The 3 possible outcomes of completion:
     (cond 
;; (1)   Already complete.
        ((eq comp t) (if (get-buffer "*Completions*") 
                        (delete-windows-on "*Completions*"))
                      (message "%s is complete" word))
;; (2)   Not found. 
        ((eq comp nil) (message "No Match found"))
;; (3)  Some extension to the word possible.
        (t
          (if (not(string= comp word))
;;     Add any unique extension to the mail buffer.
           (progn (delete-region c-begin (point))(insert comp)))
          (if (eq t (try-completion comp mail-aliases))
;;     If the extended word is definitely complete, remove the help window
             (progn 
               (if (get-buffer "*Completions*") (delete-windows-on "*Completions*"))
               (message "%s is complete" comp))
;;     else display all possible completions.
          (with-output-to-temp-buffer "*Completions*"
           (display-completion-list (all-completions word mail-aliases ))))))))

(defun my-expand-mailalias ()
  "Expands any mail alias appearing in the header lines.
   They may be folded back using undo"
  (interactive)
  (switch-to-buffer "*mail*")
  (save-excursion 
    (goto-char (point-min))
    (expand-mail-aliases (point) 
      (progn (search-forward "--text") (point)))))

--
                           David Carlisle
                                    JANET: carlisle@uk.ac.man.cs

                                    Computer Science Department
                                    Manchester University
                                    Oxford Road
                                    Manchester
                                    England
                                    M13 9PL
Newsgroups: gnu.emacs.help