[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local
From: |
martin rudalics |
Subject: |
bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local |
Date: |
Wed, 12 Oct 2011 11:48:07 +0200 |
User-agent: |
Thunderbird 2.0.0.21 (Windows/20090302) |
> I think I generally agree it would be a good change. But without an
> actual patch, it's difficult to assess how reliable and backward
> compatible we can make it.
Attached find a diff with a new option
`switch-to-buffer-preserve-window-point'.
martin
=== modified file 'lisp/window.el'
--- lisp/window.el 2011-10-10 17:52:03 +0000
+++ lisp/window.el 2011-10-12 09:23:47 +0000
@@ -4976,6 +4976,19 @@
buffer))
(other-buffer)))
+(defcustom switch-to-buffer-preserve-window-point nil
+ "If non-nil, `switch-to-buffer' tries to preserve `window-point'.
+If nil, `switch-to-buffer' displays the buffer at that buffer's
+`point'. If non-nil, it tries to display the buffer at the last
+position of `window-point' in the window used for display.
+
+If the window used for display is either new, or the buffer
+already appears in it, or the buffer never appeared in that
+window, this variable has no impact."
+ :type 'boolean
+ :group 'windows
+ :version "24.1")
+
(defun switch-to-buffer (buffer-or-name &optional norecord force-same-window)
"Switch to buffer BUFFER-OR-NAME in the selected window.
If called interactively, prompt for the buffer name using the
@@ -5001,7 +5014,7 @@
Return the buffer switched to."
(interactive
- (list (read-buffer-to-switch "Switch to buffer: ") nil nil))
+ (list (read-buffer-to-switch "Switch to buffer: ") nil t))
(let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)))
(if (null force-same-window)
(pop-to-buffer buffer display-buffer--same-window-action norecord)
@@ -5013,7 +5026,19 @@
(error "Cannot switch buffers in minibuffer window"))
((eq (window-dedicated-p) t)
(error "Cannot switch buffers in a dedicated window"))
- (t (set-window-buffer nil buffer)))
+ (t
+ (let* ((entry (and switch-to-buffer-preserve-window-point
+ (assq buffer (window-prev-buffers))))
+ (start (and entry (nth 1 entry)))
+ (pos (and entry (nth 2 entry))))
+ (set-window-buffer nil buffer)
+ (when entry
+ ;; If BUFFER-OR-NAME (1) was shown in the selected window
+ ;; before and (2) is currently displayed in some other
+ ;; visible window, try to restore start and point of buffer
+ ;; in the selected window.
+ (set-window-start (selected-window) start t)
+ (set-window-point-1 nil pos)))))
(unless norecord
(select-window (selected-window)))
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, (continued)
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, Eli Zaretskii, 2011/10/08
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, martin rudalics, 2011/10/08
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, Eli Zaretskii, 2011/10/08
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, martin rudalics, 2011/10/09
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, Eli Zaretskii, 2011/10/09
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, martin rudalics, 2011/10/10
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, Stefan Monnier, 2011/10/11
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, Steve Yegge, 2011/10/11
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, Stefan Monnier, 2011/10/11
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, Steve Yegge, 2011/10/11
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local,
martin rudalics <=
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, Stefan Monnier, 2011/10/12
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, Stefan Monnier, 2011/10/12
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, martin rudalics, 2011/10/12
- bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local, martin rudalics, 2011/10/12