From: Martin Rudalics Date: Tue, 27 Mar 2012 09:22:01 +0000 (+0200) Subject: Optionally avoid that switching to previous or next buffer shows that buffer twice. X-Git-Tag: emacs-pretest-24.0.05~44 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=dcb6e7b38ab0a732c18bf80deacc803a03aeb85c;p=emacs.git Optionally avoid that switching to previous or next buffer shows that buffer twice. * window.el (switch-to-visible-buffer): New option. (switch-to-prev-buffer, switch-to-next-buffer): Observe switch-to-visible-buffer. Make sure that checking for a window showing a buffer already is done on the same frame. * windows.texi (Window History): Describe new option switch-to-visible-buffer. --- diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index a326117cdce..494e3416d80 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,8 @@ +2012-03-27 Martin Rudalics + + * windows.texi (Window History): Describe new option + switch-to-visible-buffer. + 2012-03-27 Glenn Morris * searching.texi (String Search): Add xref to Emacs manual. diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index b541b2419c8..8df32785036 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -2073,7 +2073,8 @@ or killed or has been already shown by a recent invocation of If repeated invocations of this command have already shown all buffers previously shown in @var{window}, further invocations will show buffers from the buffer list of the frame @var{window} appears on (@pxref{The -Buffer List}). +Buffer List}) trying to skip buffers that are already shown in another +window on that frame. @end deffn @deffn Command switch-to-next-buffer &optional window @@ -2087,6 +2088,19 @@ can be undone, this function tries to show a buffer from the buffer list of the frame @var{window} appears on (@pxref{The Buffer List}). @end deffn +By default @code{switch-to-prev-buffer} and @code{switch-to-next-buffer} +can switch to a buffer that is already shown in another window on the +same frame. The following option can be used to override that behavior. + +@defopt switch-to-visible-buffer +If this variable is non-@code{nil}, @code{switch-to-prev-buffer} and +@code{switch-to-next-buffer} may switch to a buffer that is already +visible on the same frame, provided the buffer was shown in the argument +window before. If it's @code{nil}, @code{switch-to-prev-buffer} and +@code{switch-to-next-buffer} always try to avoid switching to a buffer +that is already visible in another window on the same frame. +@end defopt + @node Dedicated Windows @section Dedicated Windows diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ca07cc36062..7d81bbb46b5 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2012-03-27 Martin Rudalics + + * window.el (switch-to-visible-buffer): New option. + (switch-to-prev-buffer, switch-to-next-buffer): Observe + switch-to-visible-buffer. Make sure that checking for a window + showing a buffer already is done on the same frame. + 2012-03-27 Glenn Morris * startup.el (mail-host-address): Doc fix. diff --git a/lisp/window.el b/lisp/window.el index cb7368fc7ff..42bc57272bb 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -2575,6 +2575,18 @@ before was current this also makes BUFFER the current buffer." (when point (set-window-point-1 window point)))) +(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 in the argument window before. 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) + (defun switch-to-prev-buffer (&optional window bury-or-kill) "In WINDOW switch to previous buffer. WINDOW must be a live window and defaults to the selected one. @@ -2584,6 +2596,7 @@ shown in WINDOW is about to be buried or killed and consequently shall not be switched to in future invocations of this command." (interactive) (let* ((window (window-normalize-window window t)) + (frame (window-frame window)) (old-buffer (window-buffer window)) ;; Save this since it's destroyed by `set-window-buffer'. (next-buffers (window-next-buffers window)) @@ -2602,14 +2615,13 @@ shall not be switched to in future invocations of this command." (not (eq new-buffer old-buffer)) (or bury-or-kill (not (memq new-buffer next-buffers)))) - ;; _DO_ show visible buffers as advertized in Elisp manual 28.14 - ;; on `switch-to-prev-buffer' & `switch-to-next-buffer' - ;;(if (get-buffer-window new-buffer) - ;; ;; Try to avoid showing a buffer visible in some other window. - ;; (setq visible new-buffer) + (if (and (not switch-to-visible-buffer) + (get-buffer-window new-buffer frame)) + ;; Try to avoid showing a buffer visible in some other window. + (setq visible new-buffer) (set-window-buffer-start-and-point window new-buffer (nth 1 entry) (nth 2 entry)) - (throw 'found t))) + (throw 'found t)))) ;; Scan reverted buffer list of WINDOW's frame next, skipping ;; entries of next buffers. Note that when we bury or kill a ;; buffer we don't reverse the global buffer list to avoid showing @@ -2617,15 +2629,16 @@ shall not be switched to in future invocations of this command." ;; buffer list in order to make sure that switching to the ;; previous/next buffer traverse it in opposite directions. (dolist (buffer (if bury-or-kill - (buffer-list (window-frame window)) - (nreverse (buffer-list (window-frame window))))) + (buffer-list frame) + (nreverse (buffer-list frame)))) (when (and (buffer-live-p buffer) (not (eq buffer old-buffer)) (not (eq (aref (buffer-name buffer) 0) ?\s)) (or bury-or-kill (not (memq buffer next-buffers)))) - (if (get-buffer-window buffer) + (if (get-buffer-window buffer frame) ;; Try to avoid showing a buffer visible in some other window. - (setq visible buffer) + (unless visible + (setq visible buffer)) (setq new-buffer buffer) (set-window-buffer-start-and-point window new-buffer) (throw 'found t)))) @@ -2678,6 +2691,7 @@ shall not be switched to in future invocations of this command." WINDOW must be a live window and defaults to the selected one." (interactive) (let* ((window (window-normalize-window window t)) + (frame (window-frame window)) (old-buffer (window-buffer window)) (next-buffers (window-next-buffers window)) new-buffer entry killed-buffers visible) @@ -2698,11 +2712,11 @@ WINDOW must be a live window and defaults to the selected one." (throw 'found t))) ;; Scan the buffer list of WINDOW's frame next, skipping previous ;; buffers entries. - (dolist (buffer (buffer-list (window-frame window))) + (dolist (buffer (buffer-list frame)) (when (and (buffer-live-p buffer) (not (eq buffer old-buffer)) (not (eq (aref (buffer-name buffer) 0) ?\s)) (not (assq buffer (window-prev-buffers window)))) - (if (get-buffer-window buffer) + (if (get-buffer-window buffer frame) ;; Try to avoid showing a buffer visible in some other window. (setq visible buffer) (setq new-buffer buffer) @@ -2716,9 +2730,14 @@ WINDOW must be a live window and defaults to the selected one." (not (setq killed-buffers (cons new-buffer killed-buffers)))) (not (eq new-buffer old-buffer))) - (set-window-buffer-start-and-point - window new-buffer (nth 1 entry) (nth 2 entry)) - (throw 'found t))) + (if (and (not switch-to-visible-buffer) + (get-buffer-window new-buffer frame)) + ;; Try to avoid showing a buffer visible in some other window. + (unless visible + (setq visible new-buffer)) + (set-window-buffer-start-and-point + window new-buffer (nth 1 entry) (nth 2 entry)) + (throw 'found t)))) ;; Show a buffer visible in another window. (when visible