From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: splitting windows and switching buffers Date: Sat, 24 Mar 2012 12:16:16 +0100 Message-ID: <4F6DAD00.6000103@gmx.at> References: <4F6AD765.3050404@gmx.at> <87lims5x1q.fsf@gnu.org> <4F6B7937.2070202@gmx.at> <87d3845pk9.fsf@gnu.org> <4F6C51C1.7080903@gmx.at> <87limr4b2r.fsf_-_@gnu.org> <4F6CCF90.20302@gmx.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010206070000020904020703" X-Trace: dough.gmane.org 1332587781 8573 80.91.229.3 (24 Mar 2012 11:16:21 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 24 Mar 2012 11:16:21 +0000 (UTC) Cc: emacs-devel@gnu.org To: sds@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 24 12:16:20 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SBOxG-0000bS-Px for ged-emacs-devel@m.gmane.org; Sat, 24 Mar 2012 12:16:19 +0100 Original-Received: from localhost ([::1]:54609 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBOxG-0006OO-3y for ged-emacs-devel@m.gmane.org; Sat, 24 Mar 2012 07:16:18 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:54865) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SBOxC-0006Nf-4e for emacs-devel@gnu.org; Sat, 24 Mar 2012 07:16:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SBOx9-0003Py-24 for emacs-devel@gnu.org; Sat, 24 Mar 2012 07:16:13 -0400 Original-Received: from mailout-de.gmx.net ([213.165.64.22]:45458) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1SBOx8-0003P8-PZ for emacs-devel@gnu.org; Sat, 24 Mar 2012 07:16:11 -0400 Original-Received: (qmail invoked by alias); 24 Mar 2012 11:16:07 -0000 Original-Received: from 62-47-43-39.adsl.highway.telekom.at (EHLO [62.47.43.39]) [62.47.43.39] by mail.gmx.net (mp032) with SMTP; 24 Mar 2012 12:16:07 +0100 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX18vywAngtYvT+GEeaYGMN+kJDCFFU9bhjYuNbRopQ lU/MhhqVB7teGj In-Reply-To: <4F6CCF90.20302@gmx.at> X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 213.165.64.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:149204 Archived-At: This is a multi-part message in MIME format. --------------010206070000020904020703 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit A patch for this and some other minor issues is attached. martin --------------010206070000020904020703 Content-Type: text/plain; name="switch-to-visible-buffer.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="switch-to-visible-buffer.diff" === modified file 'doc/lispref/windows.texi' --- doc/lispref/windows.texi 2012-03-11 16:10:07 +0000 +++ doc/lispref/windows.texi 2012-03-24 10:56:10 +0000 @@ -2073,7 +2073,8 @@ 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 @@ 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 === modified file 'lisp/window.el' --- lisp/window.el 2012-03-22 20:49:04 +0000 +++ lisp/window.el 2012-03-24 11:00:06 +0000 @@ -2575,6 +2575,18 @@ (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 @@ 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 @@ (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 @@ ;; 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 @@ 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 @@ (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 @@ (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 --------------010206070000020904020703--