unofficial mirror of bug-gnu-emacs@gnu.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: Fri, 05 Oct 2012 12:08:24 +0200	[thread overview]
Message-ID: <506EB198.5080008@gmx.at> (raw)
In-Reply-To: <jwvy5wqcq4z.fsf-monnier+emacs@gnu.org>

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

 > That looks pretty good.  I'd be willing to try and turn it on by default
 > in something like Emacs-25 or maybe even 24.2.

I completely forgot about this.  Any objections to install the attached
version for 24.3?

 > One thing bothers me, tho: why not do it in set-window-buffer?

I'm still not sure whether this would be safe in all cases.  I wouldn't
even do that for plain `display-buffer'.  The current patch addresses
all requests raised in the current thread.  If there's real need to
provide this option for other functions as well, we can still do that.

martin

[-- Attachment #2: switch-to-buffer-preserve-window-point.diff --]
[-- Type: text/plain, Size: 3025 bytes --]

=== modified file 'lisp/ChangeLog'
--- lisp/ChangeLog	2012-10-04 12:56:14 +0000
+++ lisp/ChangeLog	2012-10-05 09:40:16 +0000
@@ -1,3 +1,10 @@
+2012-10-05  Martin Rudalics  <rudalics@gmx.at>
+
+	* window.el (switch-to-buffer-preserve-window-point): New
+	option.
+	(switch-to-buffer): Optionally preserve window point if buffer
+	appeared earlier in the selected window (Bug#4041).
+
 2012-10-04  Martin Rudalics  <rudalics@gmx.at>
 
 	* emacs-lisp/edebug.el (edebug-pop-to-buffer): Select window

=== modified file 'lisp/window.el'
--- lisp/window.el	2012-09-30 10:44:43 +0000
+++ lisp/window.el	2012-10-05 09:47:10 +0000
@@ -5812,6 +5812,25 @@
 	    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 last position in the selected window
+provided the buffer is curently displayed in some other window on
+a visible or iconified frame.  If this is t, it always tries to
+display the buffer at its last position in the selected window.
+
+If the window used for display is either new, or the buffer
+already appears in it, or the buffer never appeared in that
+window, the setting of this variable has no impact."
+  :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
@@ -5837,6 +5856,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))
@@ -5853,7 +5876,21 @@
       (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)))
+	     (start (and entry (nth 1 entry)))
+	     (pos (and entry (nth 2 entry))))
+	(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) start t)
+	  (set-window-point nil pos)))))
 
     (unless norecord
       (select-window (selected-window)))



  parent reply	other threads:[~2012-10-05 10:08 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
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 [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=506EB198.5080008@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).