Mercurial > emacs
changeset 104648:a9e9aa0de2e5
(build-mail-aliases): Use with-temp-buffer,
expand-file-name and with-current-buffer.
(mail-get-names, mail-directory): Use with-current-buffer.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 27 Aug 2009 18:32:37 +0000 |
parents | ef4820f099a1 |
children | bfbe36e44416 |
files | lisp/ChangeLog lisp/mail/mailalias.el |
diffstat | 2 files changed, 55 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/ChangeLog Thu Aug 27 16:53:04 2009 +0000 +++ b/lisp/ChangeLog Thu Aug 27 18:32:37 2009 +0000 @@ -1,5 +1,9 @@ 2009-08-27 Stefan Monnier <monnier@iro.umontreal.ca> + * mail/mailalias.el (build-mail-aliases): Use with-temp-buffer, + expand-file-name and with-current-buffer. + (mail-get-names, mail-directory): Use with-current-buffer. + * vc.el (vc-read-revision): New function. (vc-version-diff, vc-merge): Use it.
--- a/lisp/mail/mailalias.el Thu Aug 27 16:53:04 2009 +0000 +++ b/lisp/mail/mailalias.el Thu Aug 27 18:32:37 2009 +0000 @@ -244,61 +244,53 @@ ;; In case mail-aliases is t, make sure define-mail-alias ;; does not recursively call build-mail-aliases. (setq mail-aliases nil) - (let ((buffer nil) - (obuf (current-buffer))) - (unwind-protect - (progn - (setq buffer (generate-new-buffer " mailrc")) - (set-buffer buffer) - (while file - (cond ((get-file-buffer file) - (insert (save-excursion - (set-buffer (get-file-buffer file)) - (buffer-substring-no-properties - (point-min) (point-max))))) - ((file-exists-p file) (insert-file-contents file)) - ((file-exists-p (setq file (concat "~/" file))) - (insert-file-contents file)) - (t (setq file nil))) - (goto-char (point-min)) - ;; Delete comments from the contents. - (while (search-forward "# " nil t) - (let ((p (- (point) 2))) - (end-of-line) - (delete-region p (point)))) - ;; Don't lose if no final newline. - (goto-char (point-max)) - (or (eq (preceding-char) ?\n) (newline)) - (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)) - ;; handle `source' directives -- Eddy/1994/May/25 - (cond ((re-search-forward "^source[ \t]+" nil t) - (re-search-forward "\\S-+") - (setq file (buffer-substring-no-properties - (match-beginning 0) (match-end 0))) - (beginning-of-line) - (insert "# ") ; to ensure we don't re-process this file - (beginning-of-line)) - (t (setq file nil)))) - (goto-char (point-min)) - (while (re-search-forward - "^\\(a\\|alias\\|g\\|group\\)[ \t]+\\([^ \t\n]+\\)" nil t) - (let* ((name (match-string 2)) - (start (progn (skip-chars-forward " \t") (point))) - value) - (end-of-line) - (setq value (buffer-substring-no-properties start (point))) - (unless (equal value "") - (define-mail-alias name value t)))) - mail-aliases) - (if buffer (kill-buffer buffer)) - (set-buffer obuf)))) + (with-temp-buffer + (while file + (cond ((get-file-buffer file) + (insert (with-current-buffer (get-file-buffer file) + (buffer-substring-no-properties + (point-min) (point-max))))) + ((file-exists-p file) (insert-file-contents file)) + ((file-exists-p (setq file (expand-file-name file "~/"))) + (insert-file-contents file)) + (t (setq file nil))) + (goto-char (point-min)) + ;; Delete comments from the contents. + (while (search-forward "# " nil t) + (let ((p (- (point) 2))) + (end-of-line) + (delete-region p (point)))) + ;; Don't lose if no final newline. + (goto-char (point-max)) + (or (eq (preceding-char) ?\n) (newline)) + (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)) + ;; handle `source' directives -- Eddy/1994/May/25 + (cond ((re-search-forward "^source[ \t]+" nil t) + (re-search-forward "\\S-+") + (setq file (buffer-substring-no-properties + (match-beginning 0) (match-end 0))) + (beginning-of-line) + (insert "# ") ; to ensure we don't re-process this file + (beginning-of-line)) + (t (setq file nil)))) + (goto-char (point-min)) + (while (re-search-forward + "^\\(a\\|alias\\|g\\|group\\)[ \t]+\\([^ \t\n]+\\)" nil t) + (let* ((name (match-string 2)) + (start (progn (skip-chars-forward " \t") (point))) + value) + (end-of-line) + (setq value (buffer-substring-no-properties start (point))) + (unless (equal value "") + (define-mail-alias name value t)))) + mail-aliases)) ;; Always autoloadable in case the user wants to define aliases ;; interactively or in .emacs. @@ -452,8 +444,7 @@ `mail-directory-function'. PATTERN is the string we want to complete." (if (eq mail-local-names t) - (save-excursion - (set-buffer (generate-new-buffer " passwd")) + (with-current-buffer (generate-new-buffer " passwd") (let ((files mail-passwd-files)) (while files (insert-file-contents (car files) nil nil nil t) @@ -511,11 +502,10 @@ If PATTERN is nil, get all the defined user names. This function calls `mail-directory-function' to query the directory, then uses `mail-directory-parser' to parse the output it returns." - (save-excursion - (message "Querying directory...") - (set-buffer (generate-new-buffer " *mail-directory*")) + (message "Querying directory...") + (with-current-buffer (generate-new-buffer " *mail-directory*") (funcall mail-directory-function pattern) - (goto-char 1) + (goto-char (point-min)) (let (directory) (if (stringp mail-directory-parser) (while (re-search-forward mail-directory-parser nil t)