aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/window.el38
2 files changed, 43 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 69371cec518..59eba7a7d27 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12012-10-10 Martin Rudalics <rudalics@gmx.at>
2
3 * window.el (switch-to-buffer-preserve-window-point): New option.
4 (switch-to-buffer): Obey
5 `switch-to-buffer-preserve-window-point' (Bug#4041).
6
12012-10-09 Stefan Monnier <monnier@iro.umontreal.ca> 72012-10-09 Stefan Monnier <monnier@iro.umontreal.ca>
2 8
3 * newcomment.el (comment-start-skip, comment-end-skip, comment-end): 9 * newcomment.el (comment-start-skip, comment-end-skip, comment-end):
diff --git a/lisp/window.el b/lisp/window.el
index f9761366b62..b033f9c26e3 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5818,6 +5818,26 @@ buffer with the name BUFFER-OR-NAME and return that buffer."
5818 buffer)) 5818 buffer))
5819 (other-buffer))) 5819 (other-buffer)))
5820 5820
5821(defcustom switch-to-buffer-preserve-window-point nil
5822 "If non-nil, `switch-to-buffer' tries to preserve `window-point'.
5823If this is nil, `switch-to-buffer' displays the buffer at that
5824buffer's `point'. If this is `already-displayed', it tries to
5825display the buffer at its pevious position in the selected
5826window, provided the buffer is currently displayed in some other
5827window on any visible or iconified frame. If this is t, it
5828unconditionally tries to display the buffer at its previous
5829position in the selected window.
5830
5831This variable is ignored if the the buffer is already displayed
5832in the selected window or never appeared in it before, or if
5833`switch-to-buffer' calls `pop-to-buffer' to display the buffer."
5834 :type '(choice
5835 (const :tag "Never" nil)
5836 (const :tag "If already displayed elsewhere" already-displayed)
5837 (const :tag "Always" t))
5838 :group 'windows
5839 :version "24.3")
5840
5821(defun switch-to-buffer (buffer-or-name &optional norecord force-same-window) 5841(defun switch-to-buffer (buffer-or-name &optional norecord force-same-window)
5822 "Switch to buffer BUFFER-OR-NAME in the selected window. 5842 "Switch to buffer BUFFER-OR-NAME in the selected window.
5823If the selected window cannot display the specified 5843If the selected window cannot display the specified
@@ -5843,6 +5863,10 @@ If optional argument FORCE-SAME-WINDOW is non-nil, the buffer
5843must be displayed in the selected window; if that is impossible, 5863must be displayed in the selected window; if that is impossible,
5844signal an error rather than calling `pop-to-buffer'. 5864signal an error rather than calling `pop-to-buffer'.
5845 5865
5866The option `switch-to-buffer-preserve-window-point' can be used
5867to make the buffer appear at its last position in the selected
5868window.
5869
5846Return the buffer switched to." 5870Return the buffer switched to."
5847 (interactive 5871 (interactive
5848 (list (read-buffer-to-switch "Switch to buffer: ") nil 'force-same-window)) 5872 (list (read-buffer-to-switch "Switch to buffer: ") nil 'force-same-window))
@@ -5859,7 +5883,19 @@ Return the buffer switched to."
5859 (if force-same-window 5883 (if force-same-window
5860 (user-error "Cannot switch buffers in a dedicated window") 5884 (user-error "Cannot switch buffers in a dedicated window")
5861 (pop-to-buffer buffer norecord))) 5885 (pop-to-buffer buffer norecord)))
5862 (t (set-window-buffer nil buffer))) 5886 (t
5887 (let* ((entry (assq buffer (window-prev-buffers)))
5888 (displayed (and (eq switch-to-buffer-preserve-window-point
5889 'already-displayed)
5890 (get-buffer-window buffer 0))))
5891 (set-window-buffer nil buffer)
5892 (when (and entry
5893 (or (eq switch-to-buffer-preserve-window-point t)
5894 displayed))
5895 ;; Try to restore start and point of buffer in the selected
5896 ;; window (Bug#4041).
5897 (set-window-start (selected-window) (nth 1 entry) t)
5898 (set-window-point nil (nth 2 entry))))))
5863 5899
5864 (unless norecord 5900 (unless norecord
5865 (select-window (selected-window))) 5901 (select-window (selected-window)))