Function: mh-alias-add-alias-to-file
mh-alias-add-alias-to-file is a byte-compiled function defined in
mh-alias.el.gz.
Signature
(mh-alias-add-alias-to-file ALIAS ADDRESS &optional FILE)
Documentation
Add ALIAS for ADDRESS in alias FILE without alias check or prompts.
Prompt for alias file if not provided and there is more than one candidate.
If the alias exists already, you will have the choice of inserting the new alias before or after the old alias. In the former case, this alias will be used when sending mail to this alias. In the latter case, the alias serves as an additional folder name hint when filing messages.
Source Code
;; Defined in /usr/src/emacs/lisp/mh-e/mh-alias.el.gz
(defun mh-alias-add-alias-to-file (alias address &optional file)
"Add ALIAS for ADDRESS in alias FILE without alias check or prompts.
Prompt for alias file if not provided and there is more than one
candidate.
If the alias exists already, you will have the choice of
inserting the new alias before or after the old alias. In the
former case, this alias will be used when sending mail to this
alias. In the latter case, the alias serves as an additional
folder name hint when filing messages."
(if (not file)
(setq file (mh-alias-insert-file alias)))
(with-current-buffer (find-file-noselect file)
(goto-char (point-min))
(let ((alias-search (concat alias ":"))
(letter)
(case-fold-search t))
(cond
;; Search for exact match (if we had the same alias before)
((re-search-forward
(concat "^" (regexp-quote alias-search) " *\\(.*\\)") nil t)
(let ((answer (read-string
(format (concat "Alias %s exists; insert new address "
"[b]efore or [a]fter: ")
(match-string 1))))
(case-fold-search t))
(cond ((string-match "^b" answer))
((string-match "^a" answer)
(forward-line 1))
(t
(error "Unrecognized response")))))
;; No, so sort-in at the right place
;; search for "^alias", then "^alia", etc.
((eq mh-alias-insertion-location 'sorted)
(setq letter (substring alias-search -1)
alias-search (substring alias-search 0 -1))
(while (and (not (equal alias-search ""))
(not (re-search-forward
(concat "^" (regexp-quote alias-search)) nil t)))
(setq letter (substring alias-search -1)
alias-search (substring alias-search 0 -1)))
;; Next, move forward to sort alphabetically for following letters
(beginning-of-line)
(while (re-search-forward
(concat "^" (regexp-quote alias-search) "[a-" letter "]")
nil t)
(forward-line 1)))
((eq mh-alias-insertion-location 'bottom)
(goto-char (point-max)))
((eq mh-alias-insertion-location 'top)
(goto-char (point-min)))))
(beginning-of-line)
(insert (format "%s: %s\n" alias address))
(save-buffer)))