Use with-current-buffer instead of save-excursion set-buffer where possible

Patch by Stefan Monnier
This commit is contained in:
Carsten Dominik 2009-11-05 22:51:50 +01:00
parent eff6680d11
commit 7c0a16e256
10 changed files with 22 additions and 33 deletions

View File

@ -188,7 +188,8 @@
(let ((b (current-buffer)) (p (point))) (let ((b (current-buffer)) (p (point)))
;; Restore the window configuration because we just use the web link ;; Restore the window configuration because we just use the web link
(set-window-configuration org-window-config-before-follow-link) (set-window-configuration org-window-config-before-follow-link)
(save-excursion (set-buffer b) (goto-char p) (with-current-buffer b
(goto-char p)
(bibtex-url))) (bibtex-url)))
(recenter 0)) ; Move entry start to beginning of window (recenter 0)) ; Move entry start to beginning of window
;; return t to indicate that the search is done. ;; return t to indicate that the search is done.

View File

@ -1103,8 +1103,7 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
(if (not (marker-buffer org-clock-marker)) (if (not (marker-buffer org-clock-marker))
(if fail-quietly (throw 'exit t) (error "No active clock"))) (if fail-quietly (throw 'exit t) (error "No active clock")))
(let (ts te s h m remove) (let (ts te s h m remove)
(save-excursion (with-current-buffer (marker-buffer org-clock-marker)
(set-buffer (marker-buffer org-clock-marker))
(save-restriction (save-restriction
(widen) (widen)
(goto-char org-clock-marker) (goto-char org-clock-marker)
@ -1169,8 +1168,7 @@ If there is no running clock, throw an error, unless FAIL-QUIETLY is set."
(interactive) (interactive)
(if (not (marker-buffer org-clock-marker)) (if (not (marker-buffer org-clock-marker))
(error "No active clock")) (error "No active clock"))
(save-excursion (with-current-buffer (marker-buffer org-clock-marker)
(set-buffer (marker-buffer org-clock-marker))
(goto-char org-clock-marker) (goto-char org-clock-marker)
(delete-region (1- (point-at-bol)) (point-at-eol)) (delete-region (1- (point-at-bol)) (point-at-eol))
;; Just in case, remove any empty LOGBOOK left over ;; Just in case, remove any empty LOGBOOK left over

View File

@ -285,8 +285,7 @@ then use this command to convert it."
beg end t 'string)) beg end t 'string))
(setq reg (buffer-substring beg end) (setq reg (buffer-substring beg end)
buf (get-buffer-create "*Org tmp*")) buf (get-buffer-create "*Org tmp*"))
(save-excursion (with-current-buffer buf
(set-buffer buf)
(erase-buffer) (erase-buffer)
(insert reg) (insert reg)
(org-mode) (org-mode)

View File

@ -457,8 +457,7 @@ then use this command to convert it."
beg end t 'string)) beg end t 'string))
(setq reg (buffer-substring beg end) (setq reg (buffer-substring beg end)
buf (get-buffer-create "*Org tmp*")) buf (get-buffer-create "*Org tmp*"))
(save-excursion (with-current-buffer buf
(set-buffer buf)
(erase-buffer) (erase-buffer)
(insert reg) (insert reg)
(org-mode) (org-mode)

View File

@ -193,8 +193,7 @@ If heading exists, delete all message:// links within heading's first
level. If heading doesn't exist, create it at point-max. Insert level. If heading doesn't exist, create it at point-max. Insert
list of message:// links to flagged mail after heading." list of message:// links to flagged mail after heading."
(interactive "bBuffer in which to insert links: \nsHeading after which to insert links: ") (interactive "bBuffer in which to insert links: \nsHeading after which to insert links: ")
(save-excursion (with-current-buffer org-buffer
(set-buffer org-buffer)
(goto-char (point-min)) (goto-char (point-min))
(let ((isearch-forward t) (let ((isearch-forward t)
(message-re "\\[\\[\\(message:\\)\\([^]]+\\)\\]\\(\\[\\([^]]+\\)\\]\\)?\\]")) (message-re "\\[\\[\\(message:\\)\\([^]]+\\)\\]\\(\\[\\([^]]+\\)\\]\\)?\\]"))

View File

@ -551,8 +551,7 @@ If nothing new has beed added, return nil."
org-mobile-directory))) org-mobile-directory)))
(insertion-point (make-marker)) (insertion-point (make-marker))
not-empty content) not-empty content)
(save-excursion (with-current-buffer capture-buffer
(set-buffer capture-buffer)
(setq content (buffer-string)) (setq content (buffer-string))
(setq not-empty (string-match "\\S-" content)) (setq not-empty (string-match "\\S-" content))
(when not-empty (when not-empty

View File

@ -1042,11 +1042,10 @@ SCHEDULED: or DEADLINE: or ANYTHINGLIKETHIS:"
(org-mouse-direct nil) (org-mouse-direct nil)
(org-mouse-main-buffer (current-buffer))) (org-mouse-main-buffer (current-buffer)))
(when (eq (with-current-buffer buffer major-mode) 'org-mode) (when (eq (with-current-buffer buffer major-mode) 'org-mode)
(let ((endmarker (save-excursion (let ((endmarker (with-current-buffer buffer
(set-buffer buffer) (outline-end-of-subtree)
(outline-end-of-subtree) (forward-char 1)
(forward-char 1) (copy-marker (point)))))
(copy-marker (point)))))
(org-with-remote-undo buffer (org-with-remote-undo buffer
(with-current-buffer buffer (with-current-buffer buffer
(widen) (widen)

View File

@ -279,8 +279,8 @@ line directly before or after the table."
(save-window-excursion (save-window-excursion
(delete-other-windows) (delete-other-windows)
(when (get-buffer "*gnuplot*") ;; reset *gnuplot* if it already running (when (get-buffer "*gnuplot*") ;; reset *gnuplot* if it already running
(save-excursion (with-current-buffer "*gnuplot*"
(set-buffer "*gnuplot*") (goto-char (point-max)) (goto-char (point-max))
(gnuplot-delchar-or-maybe-eof nil))) (gnuplot-delchar-or-maybe-eof nil)))
(org-plot/goto-nearest-table) (org-plot/goto-nearest-table)
;; set default options ;; set default options

View File

@ -607,8 +607,7 @@ Default for INDEX-FILENAME is 'sitemap.org'."
(let* ((visiting (find-buffer-visiting file)) (let* ((visiting (find-buffer-visiting file))
(buffer (or visiting (find-file-noselect file))) (buffer (or visiting (find-file-noselect file)))
title) title)
(save-excursion (with-current-buffer buffer
(set-buffer buffer)
(let* ((opt-plist (org-combine-plists (org-default-export-plist) (let* ((opt-plist (org-combine-plists (org-default-export-plist)
(org-infile-export-plist)))) (org-infile-export-plist))))
(setq title (setq title

View File

@ -110,8 +110,7 @@ With prefix arg HERE, insert it at point."
(let ((pwd (substring (pwd) 10))) (let ((pwd (substring (pwd) 10)))
(cd dir) (cd dir)
(if (eql 0 (shell-command "git describe --abbrev=4 HEAD")) (if (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
(save-excursion (with-current-buffer "*Shell Command Output*"
(set-buffer "*Shell Command Output*")
(goto-char (point-min)) (goto-char (point-min))
(re-search-forward "[^\n]+") (re-search-forward "[^\n]+")
(setq git-version (match-string 0)) (setq git-version (match-string 0))
@ -8836,8 +8835,8 @@ on the system \"/user@host:\"."
"\\}[ \t]"))) "\\}[ \t]")))
(t (error "Bad refiling target description %s" desc))) (t (error "Bad refiling target description %s" desc)))
(while (setq f (pop files)) (while (setq f (pop files))
(save-excursion (with-current-buffer
(set-buffer (if (bufferp f) f (org-get-agenda-file-buffer f))) (if (bufferp f) f (org-get-agenda-file-buffer f))
(if (bufferp f) (setq f (buffer-file-name (buffer-base-buffer f)))) (if (bufferp f) (setq f (buffer-file-name (buffer-base-buffer f))))
(setq f (expand-file-name f)) (setq f (expand-file-name f))
(if (eq org-refile-use-outline-path 'file) (if (eq org-refile-use-outline-path 'file)
@ -8996,9 +8995,8 @@ See also `org-refile-use-outline-path' and `org-completion-use-ido'"
(org-kill-new (buffer-substring region-start region-end)) (org-kill-new (buffer-substring region-start region-end))
(org-save-markers-in-region region-start region-end)) (org-save-markers-in-region region-start region-end))
(org-copy-subtree 1 nil t)) (org-copy-subtree 1 nil t))
(save-excursion (with-current-buffer (setq nbuf (or (find-buffer-visiting file)
(set-buffer (setq nbuf (or (find-buffer-visiting file) (find-file-noselect file)))
(find-file-noselect file))))
(setq reversed (org-notes-order-reversed-p)) (setq reversed (org-notes-order-reversed-p))
(save-excursion (save-excursion
(save-restriction (save-restriction
@ -10610,8 +10608,7 @@ EXTRA is additional text that will be inserted into the notes buffer."
org-log-note-marker)) org-log-note-marker))
(setq lines nil)) (setq lines nil))
(when lines (when lines
(save-excursion (with-current-buffer (marker-buffer org-log-note-marker)
(set-buffer (marker-buffer org-log-note-marker))
(save-excursion (save-excursion
(goto-char org-log-note-marker) (goto-char org-log-note-marker)
(move-marker org-log-note-marker nil) (move-marker org-log-note-marker nil)
@ -13497,8 +13494,7 @@ This uses the icalendar.el library."
(tmpfile (make-temp-name (tmpfile (make-temp-name
(expand-file-name "orgics" tmpdir))) (expand-file-name "orgics" tmpdir)))
buf rtn b e) buf rtn b e)
(save-excursion (with-current-buffer frombuf
(set-buffer frombuf)
(icalendar-export-region (point-min) (point-max) tmpfile) (icalendar-export-region (point-min) (point-max) tmpfile)
(setq buf (find-buffer-visiting tmpfile)) (setq buf (find-buffer-visiting tmpfile))
(set-buffer buf) (set-buffer buf)