all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Lars Magne Ingebrigtsen <larsi@gnus.org>,
	Steve Yegge <stevey@google.com>,
	4041@debbugs.gnu.org
Subject: bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local
Date: Wed, 12 Oct 2011 11:48:07 +0200	[thread overview]
Message-ID: <4E956257.6020501@gmx.at> (raw)
In-Reply-To: <jwvvcrvf1qa.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 260 bytes --]

 > 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

[-- Attachment #2: stbpwp.diff --]
[-- Type: text/plain, Size: 2151 bytes --]

=== 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)))



  parent reply	other threads:[~2011-10-12  9:48 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-05  0:17 bug#4041: 23.0.92; Emacs 23: buffer point is no longer frame-local Steve Yegge
2009-08-06  9:33 ` martin rudalics
2011-09-17  7:04 ` Lars Magne Ingebrigtsen
2011-09-17  8:43   ` martin rudalics
2011-09-18  8:03     ` Lars Magne Ingebrigtsen
2011-10-06 22:14     ` Lars Magne Ingebrigtsen
2011-10-07  7:07       ` martin rudalics
2011-10-07 10:46         ` Lars Magne Ingebrigtsen
2011-10-07 17:00           ` martin rudalics
2011-10-07 21:09             ` Steve Yegge
2011-10-08  6:23               ` Eli Zaretskii
2011-10-08  6:32                 ` Drew Adams
2011-10-08  6:23               ` Leo
2011-10-08 13:23               ` martin rudalics
2011-10-08 14:12                 ` Eli Zaretskii
2011-10-08 15:00                   ` martin rudalics
2011-10-08 15:34                     ` Eli Zaretskii
2011-10-08 15:55                       ` martin rudalics
2011-10-08 17:07                         ` Eli Zaretskii
2011-10-08 17:53                           ` martin rudalics
2011-10-08 20:35                             ` Eli Zaretskii
2011-10-09  8:33                               ` martin rudalics
2011-10-09 17:45                                 ` Eli Zaretskii
2011-10-10 12:57                                   ` martin rudalics
2011-10-11 12:45               ` Stefan Monnier
2011-10-12  0:35                 ` Steve Yegge
2011-10-12  1:19                   ` Stefan Monnier
2011-10-12  3:52                     ` Steve Yegge
2011-10-12  9:48                     ` martin rudalics [this message]
2011-10-12 13:11                       ` Stefan Monnier
2011-10-12 13:39                         ` Stefan Monnier
2011-10-12 14:25                           ` martin rudalics
2012-10-05 10:08                         ` martin rudalics
2012-10-10 10:22                           ` martin rudalics
2011-10-12  6:52                   ` martin rudalics

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E956257.6020501@gmx.at \
    --to=rudalics@gmx.at \
    --cc=4041@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=stevey@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.