diff options
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/window.el | 38 |
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 @@ | |||
| 1 | 2012-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 | |||
| 1 | 2012-10-09 Stefan Monnier <monnier@iro.umontreal.ca> | 7 | 2012-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'. | ||
| 5823 | If this is nil, `switch-to-buffer' displays the buffer at that | ||
| 5824 | buffer's `point'. If this is `already-displayed', it tries to | ||
| 5825 | display the buffer at its pevious position in the selected | ||
| 5826 | window, provided the buffer is currently displayed in some other | ||
| 5827 | window on any visible or iconified frame. If this is t, it | ||
| 5828 | unconditionally tries to display the buffer at its previous | ||
| 5829 | position in the selected window. | ||
| 5830 | |||
| 5831 | This variable is ignored if the the buffer is already displayed | ||
| 5832 | in 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. |
| 5823 | If the selected window cannot display the specified | 5843 | If the selected window cannot display the specified |
| @@ -5843,6 +5863,10 @@ If optional argument FORCE-SAME-WINDOW is non-nil, the buffer | |||
| 5843 | must be displayed in the selected window; if that is impossible, | 5863 | must be displayed in the selected window; if that is impossible, |
| 5844 | signal an error rather than calling `pop-to-buffer'. | 5864 | signal an error rather than calling `pop-to-buffer'. |
| 5845 | 5865 | ||
| 5866 | The option `switch-to-buffer-preserve-window-point' can be used | ||
| 5867 | to make the buffer appear at its last position in the selected | ||
| 5868 | window. | ||
| 5869 | |||
| 5846 | Return the buffer switched to." | 5870 | Return 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))) |