unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#20861: 24.4/5; [PATCH] Consistency of switch-to-visible-buffer
@ 2015-06-20 20:34 Jürgen Hartmann
  2015-06-22  8:49 ` martin rudalics
  0 siblings, 1 reply; 4+ messages in thread
From: Jürgen Hartmann @ 2015-06-20 20:34 UTC (permalink / raw)
  To: 20861

This patch is based on an idea of Martin Rudalics who also suggested to send
it as a bug report:

   http://lists.gnu.org/archive/html/help-gnu-emacs/2015-05/msg00228.html
   http://lists.gnu.org/archive/html/help-gnu-emacs/2015-05/msg00291.html

The problem was discussed on help-gnu-emacs--

   http://lists.gnu.org/archive/html/help-gnu-emacs/2015-05/msg00135.html

--and can be summarized like this:

In accordance to the documentation of the variable switch-to-visible-buffer,
the commands switch-to-prev-buffer and switch-to-next-buffer switch to an
already visible buffer only if switch-to-visible-buffer is non-nil _and_ if
that buffer was already shown before in the respective window. The latter
condition is an obstacle if one wants to use these commands to quickly cycle
a window through all existing buffers.

To illustrate that in great detail:

   * Open an Emacs session via

        emacs -Q

   * Split window by means of C-x 2.

   * Use C-x b to generate a new buffer and name it A.

   * Select the other window via C-x o.

   * Use C-x b to generate a new buffer and name it B.

   * Repetitively switch buffers using C-x <left> which is bound to
     previous-buffer, noticing that this never switches to buffer A.

NB: switch-to-visible-buffer is bound to t.

The patch below alters this behavior, such that the repetitive switching of
buffers in the example will include buffer A in spite the fact that it was
never shown before in the current window. So it will be easier for example to
get buffer A shown in both windows or to swap the buffers A and B between the
windows.

Only the file

   lisp/window.el

is affected by the patch and therein only the definitions of

   switch-to-visible-buffer
   switch-to-prev-buffer
   switch-to-next-buffer

Since there were only minor changes in window.el between Emacs 24.4 and 24.5
the patch should perfectly apply to both of these versions of Emacs. However
it was build and tested on Emacs 24.4 only.

Proposal for a change log entry:

   * lisp/window.el (switch-to-visible-buffer): Doc adjustment.
     (switch-to-prev-buffer, switch-to-next-buffer): Respect
     switch-to-visible-buffer independent of the windows history.

Patch:

diff -rcN emacs-24.4_original/lisp/window.el emacs-24.4_changed/lisp/window.el
*** emacs-24.4_original/lisp/window.el    2014-09-30 17:27:41.000000000 +0200
--- emacs-24.4_changed/lisp/window.el    2015-06-20 18:52:24.815266436 +0200
***************
*** 3648,3659 ****
  (defcustom switch-to-visible-buffer t
    "If non-nil, allow switching to an already visible buffer.
  If this variable is non-nil, `switch-to-prev-buffer' and
! `switch-to-next-buffer' may switch to an already visible buffer
! provided the buffer was shown before in the window specified as
! argument to those functions.  If this variable is nil,
! `switch-to-prev-buffer' and `switch-to-next-buffer' always try to
! avoid switching to a buffer that is already visible in another
! window on the same frame."
    :type 'boolean
    :version "24.1"
    :group 'windows)
--- 3648,3657 ----
  (defcustom switch-to-visible-buffer t
    "If non-nil, allow switching to an already visible buffer.
  If this variable is non-nil, `switch-to-prev-buffer' and
! `switch-to-next-buffer' may switch to an already visible buffer.
! If this variable is nil, `switch-to-prev-buffer' and
! `switch-to-next-buffer' always try to avoid switching to a buffer
! that is already visible in another window on the same frame."
    :type 'boolean
    :version "24.1"
    :group 'windows)
***************
*** 3724,3730 ****
                     (or (null pred) (funcall pred buffer))
             (not (eq (aref (buffer-name buffer) 0) ?\s))
             (or bury-or-kill (not (memq buffer next-buffers))))
!       (if (get-buffer-window buffer frame)
            ;; Try to avoid showing a buffer visible in some other window.
            (unless visible
          (setq visible buffer))
--- 3722,3729 ----
                     (or (null pred) (funcall pred buffer))
             (not (eq (aref (buffer-name buffer) 0) ?\s))
             (or bury-or-kill (not (memq buffer next-buffers))))
!       (if (and (not switch-to-visible-buffer)
!            (get-buffer-window buffer frame))
            ;; Try to avoid showing a buffer visible in some other window.
            (unless visible
          (setq visible buffer))
***************
*** 3826,3832 ****
                     (or (null pred) (funcall pred buffer))
             (not (eq (aref (buffer-name buffer) 0) ?\s))
             (not (assq buffer (window-prev-buffers window))))
!       (if (get-buffer-window buffer frame)
            ;; Try to avoid showing a buffer visible in some other window.
            (setq visible buffer)
          (setq new-buffer buffer)
--- 3825,3832 ----
                     (or (null pred) (funcall pred buffer))
             (not (eq (aref (buffer-name buffer) 0) ?\s))
             (not (assq buffer (window-prev-buffers window))))
!       (if (and (not switch-to-visible-buffer)
!            (get-buffer-window buffer frame))
            ;; Try to avoid showing a buffer visible in some other window.
            (setq visible buffer)
          (setq new-buffer buffer)

Juergen

 		 	   		  




^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#20861: 24.4/5; [PATCH] Consistency of switch-to-visible-buffer
  2015-06-20 20:34 bug#20861: 24.4/5; [PATCH] Consistency of switch-to-visible-buffer Jürgen Hartmann
@ 2015-06-22  8:49 ` martin rudalics
  2015-06-22 10:01   ` Jürgen Hartmann
  0 siblings, 1 reply; 4+ messages in thread
From: martin rudalics @ 2015-06-22  8:49 UTC (permalink / raw)
  To: Jürgen Hartmann, 20861

 > Since there were only minor changes in window.el between Emacs 24.4 and 24.5
 > the patch should perfectly apply to both of these versions of Emacs. However
 > it was build and tested on Emacs 24.4 only.

Thanks Jürgen

Unfortunately your patch does not apply to current master/trunk here
(even with a large fuzz factor).  Can you try to make a patch against
the current version of window.el?  You should be able to retrieve it
from

http://git.savannah.gnu.org/cgit/emacs.git/plain/lisp/window.el

You don't have to compile it, I'll check that here.  Also please post
the patch as attachment and in unified format.

Thanks in advance, martin






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#20861: 24.4/5; [PATCH] Consistency of switch-to-visible-buffer
  2015-06-22  8:49 ` martin rudalics
@ 2015-06-22 10:01   ` Jürgen Hartmann
  2015-06-23 15:59     ` martin rudalics
  0 siblings, 1 reply; 4+ messages in thread
From: Jürgen Hartmann @ 2015-06-22 10:01 UTC (permalink / raw)
  To: martin rudalics, 20861@debbugs.gnu.org

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

Martin Rudalics wrote:

> Thanks Jürgen
>
> Unfortunately your patch does not apply to current master/trunk here
> (even with a large fuzz factor).  Can you try to make a patch against
> the current version of window.el?  You should be able to retrieve it
> from
>
> http://git.savannah.gnu.org/cgit/emacs.git/plain/lisp/window.el
>
> You don't have to compile it, I'll check that here.  Also please post
> the patch as attachment and in unified format.
>
> Thanks in advance, martin

Been there, done that.

Thank you Martin Rudalics.

Jürgen

 		 	   		  

[-- Attachment #2: buffer-cycling.patch --]
[-- Type: application/octet-stream, Size: 1880 bytes --]

diff -ruN original/window.el changed/window.el
--- original/window.el	2015-06-22 11:12:17.385663505 +0200
+++ changed/window.el	2015-06-22 11:35:00.646695905 +0200
@@ -3874,12 +3874,10 @@
 (defcustom switch-to-visible-buffer t
   "If non-nil, allow switching to an already visible buffer.
 If this variable is non-nil, `switch-to-prev-buffer' and
-`switch-to-next-buffer' may switch to an already visible buffer
-provided the buffer was shown before in the window specified as
-argument to those functions.  If this variable is nil,
-`switch-to-prev-buffer' and `switch-to-next-buffer' always try to
-avoid switching to a buffer that is already visible in another
-window on the same frame."
+`switch-to-next-buffer' may switch to an already visible buffer.
+If this variable is nil, `switch-to-prev-buffer' and
+`switch-to-next-buffer' always try to avoid switching to a buffer
+that is already visible in another window on the same frame."
   :type 'boolean
   :version "24.1"
   :group 'windows)
@@ -3950,7 +3948,8 @@
                    (or (null pred) (funcall pred buffer))
 		   (not (eq (aref (buffer-name buffer) 0) ?\s))
 		   (or bury-or-kill (not (memq buffer next-buffers))))
-	  (if (get-buffer-window buffer frame)
+	  (if (and (not switch-to-visible-buffer)
+		   (get-buffer-window buffer frame))
 	      ;; Try to avoid showing a buffer visible in some other window.
 	      (unless visible
 		(setq visible buffer))
@@ -4052,7 +4051,8 @@
                    (or (null pred) (funcall pred buffer))
 		   (not (eq (aref (buffer-name buffer) 0) ?\s))
 		   (not (assq buffer (window-prev-buffers window))))
-	  (if (get-buffer-window buffer frame)
+	  (if (and (not switch-to-visible-buffer)
+		   (get-buffer-window buffer frame))
 	      ;; Try to avoid showing a buffer visible in some other window.
 	      (setq visible buffer)
 	    (setq new-buffer buffer)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#20861: 24.4/5; [PATCH] Consistency of switch-to-visible-buffer
  2015-06-22 10:01   ` Jürgen Hartmann
@ 2015-06-23 15:59     ` martin rudalics
  0 siblings, 0 replies; 4+ messages in thread
From: martin rudalics @ 2015-06-23 15:59 UTC (permalink / raw)
  To: Jürgen Hartmann, 20861@debbugs.gnu.org

 > Been there, done that.

Thank you.  Committed as

    931f006..abe07ef  master -> master

martin





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-23 15:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-20 20:34 bug#20861: 24.4/5; [PATCH] Consistency of switch-to-visible-buffer Jürgen Hartmann
2015-06-22  8:49 ` martin rudalics
2015-06-22 10:01   ` Jürgen Hartmann
2015-06-23 15:59     ` martin rudalics

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