home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / gnu / emacs / help / 4028 < prev    next >
Encoding:
Text File  |  1992-09-08  |  3.7 KB  |  103 lines

  1. Path: sparky!uunet!mcsun!uknet!mucs!m1!carlisle
  2. From: carlisle@cs.man.ac.uk (David Carlisle)
  3. Newsgroups: gnu.emacs.help
  4. Subject: Re: mail alias chooser???
  5. Message-ID: <CARLISLE.92Sep7172742@r8d.cs.man.ac.uk>
  6. Date: 7 Sep 92 16:27:42 GMT
  7. References: <dsmith.715489854@aa.cad.slb.com>
  8. Sender: news@cs.man.ac.uk
  9. Organization: Department of Computer Science, University of Manchester
  10. Lines: 90
  11. In-reply-to: dsmith@mailhost.aa.cad.slb.com's message of 3 Sep 92 03:10:54 GMT
  12.  
  13. >>>>> On 3 Sep 92 03:10:54 GMT, dsmith@mailhost.aa.cad.slb.com (J. Daniel Smith) said:
  14.  
  15. JDS> Does have ELISP code that implements an "ispell"-like chooser for mail
  16. JDS> aliases?
  17.  
  18. JDS> What I am looking for is an interactive way to select mail aliases
  19. JDS> that are defined in my ~/.mailrc file when composing a message.  A way
  20. JDS> I thought would work well is to present a list of mail aliases in a
  21. JDS> way similiar to what "ispell" does for word choices...
  22.  
  23. What I use is this. It puts makes M-Tab complete a partially typed
  24. mailalias and C-x C-e  expand all aliases in the To and CC fields.
  25. (These keybindings are only suggestions)
  26.  
  27. Not quite like ispell but try it and see...
  28.  
  29. David
  30.  
  31.  
  32. ;;;
  33. ;;; mail alias functions
  34. ;;;
  35. ;;;
  36. ;;; David Carlisle 26 August 1992
  37.  
  38. ;;; To get this to work you need to bind them to keys in you mail-mode hook
  39. ;;;
  40. ;;; add the lines
  41. ;;;  (define-key mail-mode-map "\C-c\C-e" 'my-expand-mailalias)
  42. ;;;  (define-key mail-mode-map "\M-\t" 'mailalias-complete)
  43.  
  44. ;;; you also need to load the file by adding
  45. ;;; (load "mail-alias" nil t)
  46. ;;; to your .emacs.
  47.  
  48. ;;; Then C-e should expand a mail alias.
  49. ;;; M-TAB should complete a partly typed alias.
  50.  
  51. (defun mailalias-complete ( )
  52.   "Attempts to complete a partially typed mail alias
  53.   Displays possible completions in the help buffer if no
  54.   unique completion can be done."
  55.   (interactive)
  56.   (forward-word -1)
  57.     (let* ((c-begin (point))
  58.           (word (buffer-substring c-begin 
  59.                   (progn   (forward-word 1) (point))))
  60.           (comp (try-completion word mail-aliases)))
  61. ;; The 3 possible outcomes of completion:
  62.      (cond 
  63. ;; (1)   Already complete.
  64.         ((eq comp t) (if (get-buffer "*Completions*") 
  65.                         (delete-windows-on "*Completions*"))
  66.                       (message "%s is complete" word))
  67. ;; (2)   Not found. 
  68.         ((eq comp nil) (message "No Match found"))
  69. ;; (3)  Some extension to the word possible.
  70.         (t
  71.           (if (not(string= comp word))
  72. ;;     Add any unique extension to the mail buffer.
  73.            (progn (delete-region c-begin (point))(insert comp)))
  74.           (if (eq t (try-completion comp mail-aliases))
  75. ;;     If the extended word is definitely complete, remove the help window
  76.              (progn 
  77.                (if (get-buffer "*Completions*") (delete-windows-on "*Completions*"))
  78.                (message "%s is complete" comp))
  79. ;;     else display all possible completions.
  80.           (with-output-to-temp-buffer "*Completions*"
  81.            (display-completion-list (all-completions word mail-aliases ))))))))
  82.  
  83. (defun my-expand-mailalias ()
  84.   "Expands any mail alias appearing in the header lines.
  85.    They may be folded back using undo"
  86.   (interactive)
  87.   (switch-to-buffer "*mail*")
  88.   (save-excursion 
  89.     (goto-char (point-min))
  90.     (expand-mail-aliases (point) 
  91.       (progn (search-forward "--text") (point)))))
  92.  
  93. --
  94.                            David Carlisle
  95.                                     JANET: carlisle@uk.ac.man.cs
  96.  
  97.                                     Computer Science Department
  98.                                     Manchester University
  99.                                     Oxford Road
  100.                                     Manchester
  101.                                     England
  102.                                     M13 9PL
  103.