[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r110495: In switch-to-buffer optional
From: |
martin rudalics |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r110495: In switch-to-buffer optionally restore window point (Bug#4041). |
Date: |
Wed, 10 Oct 2012 11:36:45 +0200 |
User-agent: |
Bazaar (2.5.0) |
------------------------------------------------------------
revno: 110495
committer: martin rudalics <address@hidden>
branch nick: trunk
timestamp: Wed 2012-10-10 11:36:45 +0200
message:
In switch-to-buffer optionally restore window point (Bug#4041).
* window.el (switch-to-buffer-preserve-window-point): New option.
(switch-to-buffer): Obey
`switch-to-buffer-preserve-window-point' (Bug#4041).
modified:
lisp/ChangeLog
lisp/window.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2012-10-09 16:37:51 +0000
+++ b/lisp/ChangeLog 2012-10-10 09:36:45 +0000
@@ -1,3 +1,9 @@
+2012-10-10 Martin Rudalics <address@hidden>
+
+ * window.el (switch-to-buffer-preserve-window-point): New option.
+ (switch-to-buffer): Obey
+ `switch-to-buffer-preserve-window-point' (Bug#4041).
+
2012-10-09 Stefan Monnier <address@hidden>
* newcomment.el (comment-start-skip, comment-end-skip, comment-end):
=== modified file 'lisp/window.el'
--- a/lisp/window.el 2012-10-07 15:54:30 +0000
+++ b/lisp/window.el 2012-10-10 09:36:45 +0000
@@ -5818,6 +5818,26 @@
buffer))
(other-buffer)))
+(defcustom switch-to-buffer-preserve-window-point nil
+ "If non-nil, `switch-to-buffer' tries to preserve `window-point'.
+If this is nil, `switch-to-buffer' displays the buffer at that
+buffer's `point'. If this is `already-displayed', it tries to
+display the buffer at its pevious position in the selected
+window, provided the buffer is currently displayed in some other
+window on any visible or iconified frame. If this is t, it
+unconditionally tries to display the buffer at its previous
+position in the selected window.
+
+This variable is ignored if the the buffer is already displayed
+in the selected window or never appeared in it before, or if
+`switch-to-buffer' calls `pop-to-buffer' to display the buffer."
+ :type '(choice
+ (const :tag "Never" nil)
+ (const :tag "If already displayed elsewhere" already-displayed)
+ (const :tag "Always" t))
+ :group 'windows
+ :version "24.3")
+
(defun switch-to-buffer (buffer-or-name &optional norecord force-same-window)
"Switch to buffer BUFFER-OR-NAME in the selected window.
If the selected window cannot display the specified
@@ -5843,6 +5863,10 @@
must be displayed in the selected window; if that is impossible,
signal an error rather than calling `pop-to-buffer'.
+The option `switch-to-buffer-preserve-window-point' can be used
+to make the buffer appear at its last position in the selected
+window.
+
Return the buffer switched to."
(interactive
(list (read-buffer-to-switch "Switch to buffer: ") nil 'force-same-window))
@@ -5859,7 +5883,19 @@
(if force-same-window
(user-error "Cannot switch buffers in a dedicated window")
(pop-to-buffer buffer norecord)))
- (t (set-window-buffer nil buffer)))
+ (t
+ (let* ((entry (assq buffer (window-prev-buffers)))
+ (displayed (and (eq switch-to-buffer-preserve-window-point
+ 'already-displayed)
+ (get-buffer-window buffer 0))))
+ (set-window-buffer nil buffer)
+ (when (and entry
+ (or (eq switch-to-buffer-preserve-window-point t)
+ displayed))
+ ;; Try to restore start and point of buffer in the selected
+ ;; window (Bug#4041).
+ (set-window-start (selected-window) (nth 1 entry) t)
+ (set-window-point nil (nth 2 entry))))))
(unless norecord
(select-window (selected-window)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r110495: In switch-to-buffer optionally restore window point (Bug#4041).,
martin rudalics <=