bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#20861: 24.4/5; [PATCH] Consistency of switch-to-visible-buffer


From: Jürgen Hartmann
Subject: bug#20861: 24.4/5; [PATCH] Consistency of switch-to-visible-buffer
Date: Sat, 20 Jun 2015 22:34:26 +0200

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

                                          




reply via email to

[Prev in Thread] Current Thread [Next in Thread]