Function: build-mail-abbrevs

build-mail-abbrevs is an autoloaded and byte-compiled function defined in mailabbrev.el.gz.

Signature

(build-mail-abbrevs &optional FILE RECURSIVEP)

Documentation

Read mail aliases from personal mail alias file and set mail-abbrevs.

By default this is the file specified by mail-personal-alias-file.

Source Code

;; Defined in /usr/src/emacs/lisp/mail/mailabbrev.el.gz
;;;###autoload
(defun build-mail-abbrevs (&optional file recursivep)
  "Read mail aliases from personal mail alias file and set `mail-abbrevs'.
By default this is the file specified by `mail-personal-alias-file'."
  (setq file (expand-file-name (or file mail-personal-alias-file)))
  (if (obarrayp mail-abbrevs)
      nil
    (setq mail-abbrevs nil)
    (define-abbrev-table 'mail-abbrevs '()))
  (message "Parsing %s..." file)
  (with-temp-buffer
    (buffer-disable-undo)
    (cond ((get-file-buffer file)
           (insert (with-current-buffer (get-file-buffer file)
                     (buffer-substring (point-min) (point-max)))))
          ((not (file-exists-p file)))
          (t (insert-file-contents file)))
    ;; Don't lose if no final newline.
    (goto-char (point-max))
    (or (eq (preceding-char) ?\n) (newline))
    (goto-char (point-min))
    ;; Delete comments from the file
    (while (search-forward "# " nil t)
      (let ((p (- (point) 2)))
        (end-of-line)
        (delete-region p (point))))
    (goto-char (point-min))
    ;; handle "\\\n" continuation lines
    (while (not (eobp))
      (end-of-line)
      (if (= (preceding-char) ?\\)
          (progn (delete-char -1) (delete-char 1) (insert ?\ ))
        (forward-char 1)))
    (goto-char (point-min))
    (while (re-search-forward
            "^\\(a\\(lias\\)?\\|g\\(roup\\)?\\|source\\)[ \t]+" nil t)
      (beginning-of-line)
      (if (looking-at "source[ \t]+\\([^ \t\n]+\\)")
          (progn
            (end-of-line)
            (build-mail-abbrevs
             (substitute-in-file-name
              (buffer-substring (match-beginning 1) (match-end 1)))
             t))
        (re-search-forward "[ \t]+\\([^ \t\n]+\\)")
        (let* ((name (buffer-substring
                      (match-beginning 1) (match-end 1)))
               (start (progn (skip-chars-forward " \t") (point))))
          (end-of-line)
          ;; (message "** %s \"%s\"" name (buffer-substring start (point)))(sit-for 1)
          (define-mail-abbrev
            name
            (buffer-substring start (point))
            t))))
    ;; Resolve forward references in .mailrc file.
    ;; This would happen automatically before the first abbrev was
    ;; expanded, but why not do it now.
    (or recursivep (mail-resolve-all-aliases))
    mail-abbrevs)
  (message "Parsing %s... done" file))