Hi,
Stephan Helma sent me the following patch to merge mutt-alias.el into
post.el and provide menus for expaing aliases inside emacs. I prefer to expand
aliases inside mutt instead of my editor, so I have not folded it into post, or
tested it myself. Is editor alias expansion a must have for a lot of you out
there? Please email me off the list if you have an opinion.
Speaking of more appropriate places to discuss post.el, I suppose I
could set up a post mailing list, but I haven't. I have saved correspondance
from everybody who emailed me about it in an mbox file, which probably isn't
everyone who uses post. Can anybody think of a quick way off the top of their
head for extracting all the From addresses in that file and then mailing them
or putting them into an alias? Whoever comes up with the best solution wins a
free copy of post ;-)
----- Forwarded message from Stephan Helma <[EMAIL PROTECTED]> -----
*** post.el.orig Thu Dec 2 10:05:22 1999
***************
*** 367,372 ****
comment-region"
:group 'post)
+ ;; START mutt-alias
+ (defgroup mutt-alias nil
+ "Lookup mutt mail aliases."
+ :group 'post
+ :prefix "mutt-alias-")
+
+ (defcustom mutt-alias-file-list '("~/.mutt_mail_aliases")
+ "*List of files that contain your mutt aliases."
+ :type '(repeat (file :must-exist t))
+ :group 'mutt-alias)
+
+ (defcustom mutt-alias-cache t
+ "*Should we cache the aliases?"
+ :type '(choice (const :tag "Always cache the alias list" t)
+ (const :tag "Always re-load the alias list" nil))
+ :group 'mutt-alias)
+ ;; END mutt-alias
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Customizable Faces
***************
*** 471,476 ****
(defvar post-has-attachment nil
"Whether the message has an attachment.")
+ ;; START mutt-alias
+ (defvar mutt-alias-aliases nil
+ "\"Cache\" of aliases.")
+ ;; END mutt-alias
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Interactive Commands
***************
*** 791,796 ****
(description (string-read "Description: ")))
(header-attach-file file description))))
+ ;; START mutt-alias
+ (defun mutt-alias-load-aliases ()
+ "Load aliases from files defined in `mutt-alias-file-list'.
+
+ The resulting list is an assoc list where the car is a string representation
+ of the alias and the cdr is the expansion of the alias. Note that no attempt
+ is made to handle aliases-in-expansions or continued lines."
+ (unless (and mutt-alias-aliases mutt-alias-cache)
+ (with-temp-buffer
+ (loop for file in mutt-alias-file-list do (insert-file-contents file))
+ (setf (point) (point-min))
+ (setq mutt-alias-aliases
+ (loop while (search-forward-regexp "^[ \t]*alias +" nil t)
+ collect (mutt-alias-grab-alias)))))
+ mutt-alias-aliases)
+
+ (defun mutt-alias-grab-alias ()
+ "Convert an alias line into a cons where the car is the alias and the cdr
+ is the expansion. Note that no attempt is made to handle continued lines."
+ (let ((old-point (point))
+ (end-point)
+ (alias)
+ (expansion))
+ (end-of-line)
+ (setq end-point (point))
+ (setf (point) old-point)
+ (search-forward-regexp "[ \t]" nil t)
+ (setq alias (buffer-substring-no-properties old-point (1- (point))))
+ (search-forward-regexp "[^ \t]" nil t)
+ (setq expansion (buffer-substring-no-properties (1- (point)) end-point))
+ (setf (point) old-point)
+ (cons alias expansion)))
+
+ (defun mutt-alias-expand (alias)
+ "Attempt to expand an alias."
+ (let ((expansion (assoc alias (mutt-alias-load-aliases))))
+ (when expansion
+ (cdr expansion))))
+
+ (put 'mutt-alias-interactive 'lisp-indent-function 3)
+
+ (defmacro mutt-alias-interactive (name alias expansion doc &rest body)
+ "Generate a function that asks for an alias (placed into variable named by
+ ALIAS) and gets the expansion (placed into variable named by EXPANSION). If
+ there is an expansion BODY will be evaluated otherwise an error is
+ reported. The function will be given a doc string of DOC."
+ `(defun ,name (,alias) ,doc
+ (interactive (list (completing-read "Alias: " (mutt-alias-load-aliases))))
+ (let ((,expansion (mutt-alias-expand ,alias)))
+ (if ,expansion
+ (progn
+ ,@body)
+ (error "Unknown alias \"%s\"" ,alias)))))
+
+ (mutt-alias-interactive mutt-alias-insert alias expansion
+ "Insert the expansion for ALIAS into the current buffer."
+ (insert expansion))
+
+ (mutt-alias-interactive mutt-alias-lookup alias expansion
+ "Lookup and display the expansion for ALIAS."
+ (message "%s: %s" alias expansion))
+ ;; STOP mutt-alias
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Post Header Mode
***************
*** 1018,1023 ****
"----"
["Quote region" post-quote-region t]
["Unquote region" post-unquote-region t]
+ "----"
+ ["Expand alias" mutt-alias-insert t]
+ ["Lookup alias" mutt-alias-lookup t]
"----"
["Save message and return from Post" post-save-current-buffer-and-exit t]))
----- End forwarded message -----
--
Friendship, n. A ship big enough to carry two in fair weather, but only one in
foul. - Ambrose Bierce, The Devil's Dictionary
Robert I. Reid <[EMAIL PROTECTED]> http://astro.utoronto.ca/~reid/
PGP Key: http://astro.utoronto.ca/~reid/pgp.html
PGP signature