Replace save-excursion, set-buffer with with-current-buffer

When byte-compiling magit.el, Emacs throws several warnings saying
`save-excursion' defeated by `set-buffer'. Eliminate these warnings by
replacing calls to save-excursion followed by set-buffer with
with-current-buffer.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
This commit is contained in:
Ramkumar Ramachandra 2010-05-28 17:29:51 +02:00 committed by Phil Jackson
parent c33f87fe71
commit 9813ac8859

View file

@ -1257,8 +1257,7 @@ FUNC should leave point at the end of the modified region"
(magit-set-mode-line-process
(magit-process-indicator-from-command cmd-and-args))
(setq magit-process-client-buffer (current-buffer))
(save-excursion
(set-buffer buf)
(with-current-buffer buf
(view-mode 1)
(set (make-local-variable 'view-no-disable-on-exit) t)
(setq view-exit-action
@ -1719,8 +1718,7 @@ Please see the manual for a complete description of Magit.
(defun magit-find-buffer (submode &optional dir)
(let ((topdir (magit-get-top-dir (or dir default-directory))))
(dolist (buf (buffer-list))
(if (save-excursion
(set-buffer buf)
(if (with-current-buffer buf
(and default-directory
(equal (expand-file-name default-directory) topdir)
(eq major-mode 'magit-mode)
@ -1732,8 +1730,7 @@ Please see the manual for a complete description of Magit.
(defun magit-for-all-buffers (func &optional dir)
(dolist (buf (buffer-list))
(save-excursion
(set-buffer buf)
(with-current-buffer buf
(if (and (eq major-mode 'magit-mode)
(or (null dir)
(equal default-directory dir)))
@ -3027,8 +3024,7 @@ Prefix arg means justify as well."
(replace-match "\n" nil nil))))
(defun magit-log-edit-append (str)
(save-excursion
(set-buffer (get-buffer-create magit-log-edit-buffer-name))
(with-current-buffer (get-buffer-create magit-log-edit-buffer-name)
(goto-char (point-max))
(insert str "\n")))
@ -3038,8 +3034,7 @@ Prefix arg means justify as well."
(let ((buf (get-buffer magit-log-edit-buffer-name))
(result nil))
(if buf
(save-excursion
(set-buffer buf)
(with-current-buffer buf
(goto-char (point-min))
(while (looking-at "^\\([A-Za-z0-9-_]+\\): *\\(.*\\)$")
(setq result (acons (intern (downcase (match-string 1)))
@ -3052,8 +3047,7 @@ Prefix arg means justify as well."
(defun magit-log-edit-set-fields (fields)
(let ((buf (get-buffer-create magit-log-edit-buffer-name)))
(save-excursion
(set-buffer buf)
(with-current-buffer buf
(goto-char (point-min))
(if (search-forward-regexp (format "^\\([A-Za-z0-9-_]+:.*\n\\)+%s"
(regexp-quote magit-log-header-end))
@ -3637,8 +3631,7 @@ With a non numeric prefix ARG, show all entries"
(args (magit-rev-range-to-git range))
(buf (get-buffer-create "*magit-diff*")))
(display-buffer buf)
(save-excursion
(set-buffer buf)
(with-current-buffer buf
(magit-mode-init dir 'diff #'magit-refresh-diff-buffer range args)
(magit-diff-mode t)))))
@ -4120,8 +4113,7 @@ With prefix force the removal even it it hasn't been merged."
(defun magit-list-buffers ()
"Returns a list of magit buffers."
(delq nil (mapcar (lambda (b)
(save-excursion
(set-buffer b)
(with-current-buffer b
(when (eq major-mode 'magit-mode)
b)))
(buffer-list))))
@ -4140,8 +4132,7 @@ With prefix force the removal even it it hasn't been merged."
(remove-dupes
(sort
(mapcar (lambda (b)
(save-excursion
(set-buffer b)
(with-current-buffer b
(directory-file-name default-directory)))
(magit-list-buffers))
'string=)))