aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics2012-03-27 11:22:01 +0200
committerMartin Rudalics2012-03-27 11:22:01 +0200
commitdcb6e7b38ab0a732c18bf80deacc803a03aeb85c (patch)
tree019b49dc83df3700c25fb1cf0697b5f89829664a
parent4fb9a543142d6cdd7760e7bfcad186017fa57ead (diff)
downloademacs-dcb6e7b38ab0a732c18bf80deacc803a03aeb85c.tar.gz
emacs-dcb6e7b38ab0a732c18bf80deacc803a03aeb85c.zip
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.
-rw-r--r--doc/lispref/ChangeLog5
-rw-r--r--doc/lispref/windows.texi16
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/window.el49
4 files changed, 61 insertions, 16 deletions
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 @@
12012-03-27 Martin Rudalics <rudalics@gmx.at>
2
3 * windows.texi (Window History): Describe new option
4 switch-to-visible-buffer.
5
12012-03-27 Glenn Morris <rgm@gnu.org> 62012-03-27 Glenn Morris <rgm@gnu.org>
2 7
3 * searching.texi (String Search): Add xref to Emacs manual. 8 * 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
2073If repeated invocations of this command have already shown all buffers 2073If repeated invocations of this command have already shown all buffers
2074previously shown in @var{window}, further invocations will show buffers 2074previously shown in @var{window}, further invocations will show buffers
2075from the buffer list of the frame @var{window} appears on (@pxref{The 2075from the buffer list of the frame @var{window} appears on (@pxref{The
2076Buffer List}). 2076Buffer List}) trying to skip buffers that are already shown in another
2077window on that frame.
2077@end deffn 2078@end deffn
2078 2079
2079@deffn Command switch-to-next-buffer &optional window 2080@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
2087of the frame @var{window} appears on (@pxref{The Buffer List}). 2088of the frame @var{window} appears on (@pxref{The Buffer List}).
2088@end deffn 2089@end deffn
2089 2090
2091By default @code{switch-to-prev-buffer} and @code{switch-to-next-buffer}
2092can switch to a buffer that is already shown in another window on the
2093same frame. The following option can be used to override that behavior.
2094
2095@defopt switch-to-visible-buffer
2096If this variable is non-@code{nil}, @code{switch-to-prev-buffer} and
2097@code{switch-to-next-buffer} may switch to a buffer that is already
2098visible on the same frame, provided the buffer was shown in the argument
2099window before. If it's @code{nil}, @code{switch-to-prev-buffer} and
2100@code{switch-to-next-buffer} always try to avoid switching to a buffer
2101that is already visible in another window on the same frame.
2102@end defopt
2103
2090 2104
2091@node Dedicated Windows 2105@node Dedicated Windows
2092@section Dedicated Windows 2106@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 @@
12012-03-27 Martin Rudalics <rudalics@gmx.at>
2
3 * window.el (switch-to-visible-buffer): New option.
4 (switch-to-prev-buffer, switch-to-next-buffer): Observe
5 switch-to-visible-buffer. Make sure that checking for a window
6 showing a buffer already is done on the same frame.
7
12012-03-27 Glenn Morris <rgm@gnu.org> 82012-03-27 Glenn Morris <rgm@gnu.org>
2 9
3 * startup.el (mail-host-address): Doc fix. 10 * 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."
2575 (when point 2575 (when point
2576 (set-window-point-1 window point)))) 2576 (set-window-point-1 window point))))
2577 2577
2578(defcustom switch-to-visible-buffer t
2579 "If non-nil, allow switching to an already visible buffer.
2580If this variable is non-nil, `switch-to-prev-buffer' and
2581`switch-to-next-buffer' may switch to an already visible buffer
2582provided the buffer was shown in the argument window before. If
2583this variable is nil, `switch-to-prev-buffer' and
2584`switch-to-next-buffer' always try to avoid switching to a buffer
2585that is already visible in another window on the same frame."
2586 :type 'boolean
2587 :version "24.1"
2588 :group 'windows)
2589
2578(defun switch-to-prev-buffer (&optional window bury-or-kill) 2590(defun switch-to-prev-buffer (&optional window bury-or-kill)
2579 "In WINDOW switch to previous buffer. 2591 "In WINDOW switch to previous buffer.
2580WINDOW must be a live window and defaults to the selected one. 2592WINDOW 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
2584shall not be switched to in future invocations of this command." 2596shall not be switched to in future invocations of this command."
2585 (interactive) 2597 (interactive)
2586 (let* ((window (window-normalize-window window t)) 2598 (let* ((window (window-normalize-window window t))
2599 (frame (window-frame window))
2587 (old-buffer (window-buffer window)) 2600 (old-buffer (window-buffer window))
2588 ;; Save this since it's destroyed by `set-window-buffer'. 2601 ;; Save this since it's destroyed by `set-window-buffer'.
2589 (next-buffers (window-next-buffers window)) 2602 (next-buffers (window-next-buffers window))
@@ -2602,14 +2615,13 @@ shall not be switched to in future invocations of this command."
2602 (not (eq new-buffer old-buffer)) 2615 (not (eq new-buffer old-buffer))
2603 (or bury-or-kill 2616 (or bury-or-kill
2604 (not (memq new-buffer next-buffers)))) 2617 (not (memq new-buffer next-buffers))))
2605 ;; _DO_ show visible buffers as advertized in Elisp manual 28.14 2618 (if (and (not switch-to-visible-buffer)
2606 ;; on `switch-to-prev-buffer' & `switch-to-next-buffer' 2619 (get-buffer-window new-buffer frame))
2607 ;;(if (get-buffer-window new-buffer) 2620 ;; Try to avoid showing a buffer visible in some other window.
2608 ;; ;; Try to avoid showing a buffer visible in some other window. 2621 (setq visible new-buffer)
2609 ;; (setq visible new-buffer)
2610 (set-window-buffer-start-and-point 2622 (set-window-buffer-start-and-point
2611 window new-buffer (nth 1 entry) (nth 2 entry)) 2623 window new-buffer (nth 1 entry) (nth 2 entry))
2612 (throw 'found t))) 2624 (throw 'found t))))
2613 ;; Scan reverted buffer list of WINDOW's frame next, skipping 2625 ;; Scan reverted buffer list of WINDOW's frame next, skipping
2614 ;; entries of next buffers. Note that when we bury or kill a 2626 ;; entries of next buffers. Note that when we bury or kill a
2615 ;; buffer we don't reverse the global buffer list to avoid showing 2627 ;; 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."
2617 ;; buffer list in order to make sure that switching to the 2629 ;; buffer list in order to make sure that switching to the
2618 ;; previous/next buffer traverse it in opposite directions. 2630 ;; previous/next buffer traverse it in opposite directions.
2619 (dolist (buffer (if bury-or-kill 2631 (dolist (buffer (if bury-or-kill
2620 (buffer-list (window-frame window)) 2632 (buffer-list frame)
2621 (nreverse (buffer-list (window-frame window))))) 2633 (nreverse (buffer-list frame))))
2622 (when (and (buffer-live-p buffer) 2634 (when (and (buffer-live-p buffer)
2623 (not (eq buffer old-buffer)) 2635 (not (eq buffer old-buffer))
2624 (not (eq (aref (buffer-name buffer) 0) ?\s)) 2636 (not (eq (aref (buffer-name buffer) 0) ?\s))
2625 (or bury-or-kill (not (memq buffer next-buffers)))) 2637 (or bury-or-kill (not (memq buffer next-buffers))))
2626 (if (get-buffer-window buffer) 2638 (if (get-buffer-window buffer frame)
2627 ;; Try to avoid showing a buffer visible in some other window. 2639 ;; Try to avoid showing a buffer visible in some other window.
2628 (setq visible buffer) 2640 (unless visible
2641 (setq visible buffer))
2629 (setq new-buffer buffer) 2642 (setq new-buffer buffer)
2630 (set-window-buffer-start-and-point window new-buffer) 2643 (set-window-buffer-start-and-point window new-buffer)
2631 (throw 'found t)))) 2644 (throw 'found t))))
@@ -2678,6 +2691,7 @@ shall not be switched to in future invocations of this command."
2678WINDOW must be a live window and defaults to the selected one." 2691WINDOW must be a live window and defaults to the selected one."
2679 (interactive) 2692 (interactive)
2680 (let* ((window (window-normalize-window window t)) 2693 (let* ((window (window-normalize-window window t))
2694 (frame (window-frame window))
2681 (old-buffer (window-buffer window)) 2695 (old-buffer (window-buffer window))
2682 (next-buffers (window-next-buffers window)) 2696 (next-buffers (window-next-buffers window))
2683 new-buffer entry killed-buffers visible) 2697 new-buffer entry killed-buffers visible)
@@ -2698,11 +2712,11 @@ WINDOW must be a live window and defaults to the selected one."
2698 (throw 'found t))) 2712 (throw 'found t)))
2699 ;; Scan the buffer list of WINDOW's frame next, skipping previous 2713 ;; Scan the buffer list of WINDOW's frame next, skipping previous
2700 ;; buffers entries. 2714 ;; buffers entries.
2701 (dolist (buffer (buffer-list (window-frame window))) 2715 (dolist (buffer (buffer-list frame))
2702 (when (and (buffer-live-p buffer) (not (eq buffer old-buffer)) 2716 (when (and (buffer-live-p buffer) (not (eq buffer old-buffer))
2703 (not (eq (aref (buffer-name buffer) 0) ?\s)) 2717 (not (eq (aref (buffer-name buffer) 0) ?\s))
2704 (not (assq buffer (window-prev-buffers window)))) 2718 (not (assq buffer (window-prev-buffers window))))
2705 (if (get-buffer-window buffer) 2719 (if (get-buffer-window buffer frame)
2706 ;; Try to avoid showing a buffer visible in some other window. 2720 ;; Try to avoid showing a buffer visible in some other window.
2707 (setq visible buffer) 2721 (setq visible buffer)
2708 (setq new-buffer buffer) 2722 (setq new-buffer buffer)
@@ -2716,9 +2730,14 @@ WINDOW must be a live window and defaults to the selected one."
2716 (not (setq killed-buffers 2730 (not (setq killed-buffers
2717 (cons new-buffer killed-buffers)))) 2731 (cons new-buffer killed-buffers))))
2718 (not (eq new-buffer old-buffer))) 2732 (not (eq new-buffer old-buffer)))
2719 (set-window-buffer-start-and-point 2733 (if (and (not switch-to-visible-buffer)
2720 window new-buffer (nth 1 entry) (nth 2 entry)) 2734 (get-buffer-window new-buffer frame))
2721 (throw 'found t))) 2735 ;; Try to avoid showing a buffer visible in some other window.
2736 (unless visible
2737 (setq visible new-buffer))
2738 (set-window-buffer-start-and-point
2739 window new-buffer (nth 1 entry) (nth 2 entry))
2740 (throw 'found t))))
2722 2741
2723 ;; Show a buffer visible in another window. 2742 ;; Show a buffer visible in another window.
2724 (when visible 2743 (when visible