From 7cd6e1a6fbd7f2307050fc93858acbedbf68c7f4 Mon Sep 17 00:00:00 2001 From: Martin Rudalics Date: Fri, 19 Nov 2010 17:16:41 +0100 Subject: [PATCH] Revive display-buffer-function, add a few more buffer display functions and adjust callers. * window.el (display-buffer-same-frame-specifiers) (display-buffer-other-window-same-frame-specifiers): New constants. (display-buffer): Call display-buffer-function if it's non-nil. (display-buffer-same-window, display-buffer-other-window) (pop-to-buffer-other-window, switch-to-buffer-other-window): Adjust doc-strings. (display-buffer-same-frame) (display-buffer-other-window-same-frame) (pop-to-buffer-same-frame) (pop-to-buffer-other-window-same-frame) (switch-to-buffer-same-frame) (switch-to-buffer-other-window-same-frame): New functions. (display-buffer-function): Un-obsolete. * bookmark.el (bookmark-bmenu-2-window): Use pop-to-buffer-other-window. (bookmark-bmenu-switch-other-window): Use display-buffer-other-window. * progmodes/etags.el (find-tag-other-window): New argument other-frame. Call either pop-to-buffer-other-window or pop-to-buffer-other-frame. (find-tag-other-frame): Call find-tag-other-window with other-frame argument t. * speedbar.el (speedbar-find-file-in-frame) (speedbar-buffer-click): Use pop-to-buffer-other-frame. * term/ns-win.el (ns-find-file): Use pop-to-buffer-other-frame. * erc-speedbar.el (erc-speedbar-goto-buffer): Use pop-to-buffer-other-frame. * windows.texi (Displaying Buffers): Document display-buffer-function revival and the -same-frame, -other-window-same-frame postfixed functions. --- doc/lispref/ChangeLog | 6 + doc/lispref/windows.texi | 118 ++++++++----- lisp/ChangeLog | 33 ++++ lisp/bookmark.el | 12 +- lisp/erc/ChangeLog | 5 + lisp/erc/erc-speedbar.el | 5 +- lisp/progmodes/etags.el | 11 +- lisp/speedbar.el | 4 +- lisp/term/ns-win.el | 2 +- lisp/window.el | 350 +++++++++++++++++++++++++++------------ 10 files changed, 385 insertions(+), 161 deletions(-) diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index a98f73df852..6edf8543d05 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,9 @@ +2010-11-19 Martin Rudalics + + * windows.texi (Displaying Buffers): Document + display-buffer-function revival and the -same-frame, + -other-window-same-frame postfixed functions. + 2010-11-16 Martin Rudalics * windows.texi (Displaying Buffers): Mention that if a window is diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 0f1cb085cda..f5063069d9b 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -1766,7 +1766,7 @@ The optional third argument @var{ignore} is ignored. @end deffn Precisely how @code{display-buffer} finds or creates a window depends on -the @var{specifiers} argument and the two variables described next. +the @var{specifiers} argument and the three variables described next. @defopt display-buffer-names The value of this option is a list associating buffer names with buffer @@ -1804,6 +1804,11 @@ function should set up the @code{quit-restore} window parameter which is required for proper functioning of the command @code{quit-restore-window}, see below. + It's in general a bad idea to call @code{display-buffer} within the +body of this function since this might lead to infinite recursion. If +you do need to call @code{display-buffer} from it, consider setting the +option @code{display-buffer-function} described below. + The remaining buffer display specifiers are cons cells or lists whose @sc{car} is one of the symbols listed next. @@ -2057,12 +2062,35 @@ up a new frame (@code{make-frame}) is given three parameters: A height of 24 lines, a width of 80 columns, and a non-@code{nil} unsplittable property. On text-only displays, @code{display-buffer} will not try to show the buffer on another frame. +@end defopt + +@defopt display-buffer-function +This variable is the most flexible way to customize the behavior of +@code{display-buffer}. If it is non-@code{nil}, it should be a function +that @code{display-buffer} calls to do the work. The function must +accept two arguments, the buffer to display and a list of buffer display +specifiers. + + It should choose or create a window, display the specified buffer in +it, and then return the window. It is also responsible for giving the +variable @code{display-buffer-window} a meaningful value, see below for +an explanation. Moreover, the function should set up the +@code{quit-restore} window parameter which is required for proper +functioning of the command @code{quit-restore-window}, see below. + + The function specified here is free to ignore any specifiers passed to +it as second argument. If you intend to call @code{display-buffer} +within the body of that function, it's a good idea to bind +@code{display-buffer-function} to @code{nil} around each such call to +avoid running into an infinite recursion. @end defopt In order to understand how @code{display-buffer} combines the values of @code{display-buffer-names} and @code{display-buffer-regexps} with -the @var{specifiers} argument consider the following settings. Suppose -the value of @code{display-buffer-names} has been specified as +the @var{specifiers} argument consider the following settings (in our +examples we generally assume that @code{display-buffer-function} +is @code{nil}). Suppose the value of @code{display-buffer-names} has +been specified as @example ((("*text*") @@ -2209,8 +2237,7 @@ the desired minimum sizes of the new window. @code{even-window-sizes} specifier to a non-@code{nil} value. @end itemize -The following two functions are simple variations of -@code{display-buffer}. +The following functions are simple variations of @code{display-buffer}. @defun display-buffer-same-window &optional buffer-or-name This function is like @code{display-buffer} but preferably displays the @@ -2219,10 +2246,19 @@ Another window will be used only if the buffer can't be shown in the selected window, usually because it is dedicated to some other buffer. @end defun +@defun display-buffer-same-frame &optional buffer-or-name +This function is like @code{display-buffer} but tries to avoid using +another frame. +@end defun + @defun display-buffer-other-window &optional buffer-or-name This function is like @code{display-buffer} but tries to avoid using the -selected window. The selected window will be used if and only if there -is no other choice. +selected window. +@end defun + +@defun display-buffer-other-window-same-frame &optional buffer-or-name +This function is like @code{display-buffer-other-window} but tries to +avoid using another frame. @end defun The following variable conveys some information about the last @@ -2345,12 +2381,12 @@ recently selected one. @kbd{C-x b}. It returns the buffer that it switched to. @end deffn -The next two functions are similar to @code{switch-to-buffer}, except -for the described features. +The next functions are similar to @code{switch-to-buffer}, except for +the described features. @deffn Command switch-to-buffer-other-window buffer-or-name &optional norecord This command makes the buffer specified by @var{buffer-or-name} current -and displays it in a window not currently selected, by using the +and tries to display it in a window not currently selected, by using the function @code{pop-to-buffer} (see below). It returns the buffer switched to. @@ -2363,12 +2399,20 @@ The arguments @var{buffer-or-name} and @var{norecord} have the same meaning as for @code{switch-to-buffer}. @end deffn -@deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord -This command switches to buffer @var{buffer-or-name} in another frame. -It returns the buffer switched to. +@deffn Command switch-to-buffer-same-frame buffer-or-name &optional norecord +This command is like @code{switch-to-buffer-other-window} but does not +necessarily avoid the selected window. It does, however, try to use or +make a window on the selected frame. +@end deffn -The arguments @var{buffer-or-name} and @var{norecord} have the same -meaning as for @code{switch-to-buffer}. +@deffn Command switch-to-buffer-other-window-same-frame buffer-or-name &optional norecord +This command is like @code{switch-to-buffer-other-window} but tries to +use or make a window on the selected frame. +@end deffn + +@deffn Command switch-to-buffer-other-frame buffer-or-name &optional norecord +This command is like @code{switch-to-buffer-other-window} but tries to +display the buffer on another frame. @end deffn @deffn Command pop-to-buffer buffer-or-name &optional specifiers norecord @@ -2398,39 +2442,35 @@ specifiers are used. @code{switch-to-buffer}. @end deffn -The following three commands are similar to @code{pop-to-buffer} but -for the mentioned differences. +The following commands are similar to @code{pop-to-buffer} but for the +mentioned differences. @deffn Command pop-to-buffer-same-window &optional buffer-or-name norecord -This command tries to display the buffer specified by -@var{buffer-or-name} in the selected window. Another window will be -used only if the buffer can't be shown in the selected window, usually -because it is dedicated to another buffer. +This command is like @code{pop-to-buffer} but tries to display the +buffer in the selected window. Another window will be used only if the +buffer can't be shown in the selected window, usually because the window +is dedicated to another buffer. +@end deffn - The optional arguments @var{buffer-or-name} and @var{norecord} are as -for @code{pop-to-buffer}. +@deffn Command pop-to-buffer-same-frame &optional buffer-or-name norecord +This command is like @code{pop-to-buffer} but tries to make or use a +window on the selected frame. @end deffn @deffn Command pop-to-buffer-other-window &optional buffer-or-name norecord -This command displays the buffer specified by @var{buffer-or-name} in -any but the selected window and selects that window. The selected -window will be used if and only if there is no other choice. Windows on -the selected frame are preferred to windows on other frames. It returns -the buffer specified by @var{buffer-or-name} or @code{nil} if displaying -the buffer failed. - - The optional arguments @var{buffer-or-name} and @var{norecord} are as -for @code{pop-to-buffer}. +This command is like @code{pop-to-buffer} but tries to avoid the +selected window. Windows on the selected frame are preferred to windows +on other frames. @end deffn -@deffn Command pop-to-buffer-other-frame &optional buffer-or-name norecord -This command displays the buffer specified by @var{buffer-or-name} -preferably on another frame. It selects the window used for displaying -the buffer and returns the buffer specified by @var{buffer-or-name} or -@code{nil} if displaying the buffer failed. +@deffn Command pop-to-buffer-other-window-same-frame &optional buffer-or-name norecord +This command is like @code{pop-to-buffer-other-window} but tries to make +or use a window on the selected frame. +@end deffn - The optional arguments @var{buffer-or-name} and @var{norecord} are as -for @code{pop-to-buffer}. +@deffn Command pop-to-buffer-other-frame &optional buffer-or-name norecord +This command is like @code{pop-to-buffer} but preferably displays the +buffer on another frame. @end deffn @node Dedicated Windows diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3c50fa82ac4..29951081852 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,36 @@ +2010-11-19 Martin Rudalics + + * window.el (display-buffer-same-frame-specifiers) + (display-buffer-other-window-same-frame-specifiers): New + constants. + (display-buffer): Call display-buffer-function if it's non-nil. + (display-buffer-same-window, display-buffer-other-window) + (pop-to-buffer-other-window, switch-to-buffer-other-window): + Adjust doc-strings. + (display-buffer-same-frame) + (display-buffer-other-window-same-frame) + (pop-to-buffer-same-frame) + (pop-to-buffer-other-window-same-frame) + (switch-to-buffer-same-frame) + (switch-to-buffer-other-window-same-frame): New functions. + (display-buffer-function): Un-obsolete. + + * bookmark.el (bookmark-bmenu-2-window): Use + pop-to-buffer-other-window. + (bookmark-bmenu-switch-other-window): Use + display-buffer-other-window. + + * progmodes/etags.el (find-tag-other-window): New argument + other-frame. Call either pop-to-buffer-other-window or + pop-to-buffer-other-frame. + (find-tag-other-frame): Call find-tag-other-window with + other-frame argument t. + + * speedbar.el (speedbar-find-file-in-frame) + (speedbar-buffer-click): Use pop-to-buffer-other-frame. + + * term/ns-win.el (ns-find-file): Use pop-to-buffer-other-frame. + 2010-11-17 Martin Rudalics * window.el (display-buffer-split-window-1): Fix sizing for diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 11883febb07..ce719c6a3be 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -1874,11 +1874,10 @@ With a prefix arg, prompts for a file to save them in." "Select this line's bookmark, with previous buffer in second window." (interactive) (let ((bmrk (bookmark-bmenu-bookmark)) - (menu (current-buffer)) - (pop-up-windows t)) + (menu (current-buffer))) (delete-other-windows) (switch-to-buffer (other-buffer)) - (bookmark--jump-via bmrk 'pop-to-buffer) + (bookmark--jump-via bmrk 'pop-to-buffer-other-window) (bury-buffer menu))) @@ -1899,11 +1898,8 @@ With a prefix arg, prompts for a file to save them in." "Make the other window select this line's bookmark. The current window remains selected." (interactive) - (let ((bookmark (bookmark-bmenu-bookmark)) - (pop-up-windows t) - same-window-buffer-names - same-window-regexps) - (bookmark--jump-via bookmark 'display-buffer))) + (let ((bookmark (bookmark-bmenu-bookmark))) + (bookmark--jump-via bookmark 'display-buffer-other-window))) (defun bookmark-bmenu-other-window-with-mouse (event) "Select bookmark at the mouse pointer in other window, leaving bookmark menu visible." diff --git a/lisp/erc/ChangeLog b/lisp/erc/ChangeLog index 210f6985dc9..34f7bd58ce7 100644 --- a/lisp/erc/ChangeLog +++ b/lisp/erc/ChangeLog @@ -1,3 +1,8 @@ +2010-11-19 Martin Rudalics + + * erc-speedbar.el (erc-speedbar-goto-buffer): Use + pop-to-buffer-other-frame. + 2010-11-11 Glenn Morris * erc-lang.el (erc-cmd-LANG): Fix what may have been a typo. diff --git a/lisp/erc/erc-speedbar.el b/lisp/erc/erc-speedbar.el index bf45061d70c..63b61131406 100644 --- a/lisp/erc/erc-speedbar.el +++ b/lisp/erc/erc-speedbar.el @@ -327,8 +327,7 @@ The INDENT level is ignored." (select-window bwin) (raise-frame (window-frame bwin))) (if dframe-power-click - (let ((pop-up-frames t)) - (select-window (display-buffer buffer))) + (pop-to-buffer-other-frame buffer) (dframe-select-attached-frame speedbar-frame) (switch-to-buffer buffer))))) (let ((bwin (get-buffer-window buffer 0))) @@ -337,7 +336,7 @@ The INDENT level is ignored." (select-window bwin) (raise-frame (window-frame bwin))) (if speedbar-power-click - (let ((pop-up-frames t)) (select-window (display-buffer buffer))) + (pop-to-buffer-other-frame buffer) (dframe-select-attached-frame speedbar-frame) (switch-to-buffer buffer)))))) diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el index 0d11fd6423d..3cc76a94b22 100644 --- a/lisp/progmodes/etags.el +++ b/lisp/progmodes/etags.el @@ -956,7 +956,7 @@ See documentation of variable `tags-file-name'." ;;;###autoload (define-key esc-map "." 'find-tag) ;;;###autoload -(defun find-tag-other-window (tagname &optional next-p regexp-p) +(defun find-tag-other-window (tagname &optional next-p regexp-p other-frame) "Find tag (in current tags table) whose name contains TAGNAME. Select the buffer containing the tag's definition in another window, and move point there. The default for TAGNAME is the expression in the buffer @@ -970,6 +970,8 @@ just \\[negative-argument]), pop back to the previous tag gone to. If third arg REGEXP-P is non-nil, treat TAGNAME as a regexp. +Third arg OTHER-FRAME non-nil find tag on another frame. + A marker representing the point when this command is invoked is pushed onto a ring and may be popped back to with \\[pop-tag-mark]. Contrast this with the ring of marks gone to by the command. @@ -986,7 +988,9 @@ See documentation of variable `tags-file-name'." (tagpoint (progn (set-buffer tagbuf) (point)))) (set-window-point (prog1 (selected-window) - (switch-to-buffer-other-window tagbuf) + (if other-frame + (pop-to-buffer-other-frame tagbuf) + (pop-to-buffer-other-window tagbuf)) ;; We have to set this new window's point; it ;; might already have been displaying a ;; different portion of tagbuf, in which case @@ -1017,8 +1021,7 @@ Contrast this with the ring of marks gone to by the command. See documentation of variable `tags-file-name'." (interactive (find-tag-interactive "Find tag other frame: ")) - (let ((pop-up-frames t)) - (find-tag-other-window tagname next-p))) + (find-tag-other-window tagname next-p t)) ;;;###autoload (define-key ctl-x-5-map "." 'find-tag-other-frame) ;;;###autoload diff --git a/lisp/speedbar.el b/lisp/speedbar.el index f3b7531ba24..451e4ad93fd 100644 --- a/lisp/speedbar.el +++ b/lisp/speedbar.el @@ -3500,7 +3500,7 @@ frame instead." (select-window bwin) (raise-frame (window-frame bwin))) (if dframe-power-click - (let ((pop-up-frames t)) (select-window (display-buffer buff))) + (pop-to-buffer-other-frame (display-buffer buff)) (if (numberp speedbar-select-frame-method) (other-frame speedbar-select-frame-method) (dframe-select-attached-frame speedbar-frame)) @@ -3943,7 +3943,7 @@ Optional argument DEPTH specifies the current depth of the back search." "When the users clicks on a buffer-button in speedbar. TEXT is the buffer's name, TOKEN and INDENT are unused." (if dframe-power-click - (let ((pop-up-frames t)) (select-window (display-buffer text))) + (pop-to-buffer-other-frame text) (dframe-select-attached-frame speedbar-frame) (switch-to-buffer text) (if token (speedbar-change-initial-expansion-list diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el index 24f70f9dee0..46cd76332ca 100644 --- a/lisp/term/ns-win.el +++ b/lisp/term/ns-win.el @@ -501,7 +501,7 @@ unless the current buffer is a scratch buffer." (find-file f)) (ns-pop-up-frames (ns-hide-emacs 'activate) - (let ((pop-up-frames t)) (pop-to-buffer file nil))) + (pop-to-buffer-other-frame file nil)) (t (ns-hide-emacs 'activate) (find-file f))))) diff --git a/lisp/window.el b/lisp/window.el index 684f375179e..c8136b50d43 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4458,6 +4458,14 @@ buffer display specifiers.") These are the specifiers applied when `display-buffer' is called with the second argument equal t.") +(defconst display-buffer-same-frame-specifiers + '(same-frame (reuse-buffer-window . nil)) + "Specifiers for displaying a buffer in a window on the selected frame.") + +(defconst display-buffer-other-window-same-frame-specifiers + '(same-frame (reuse-buffer-window . nil) (not-this-window . t)) + "Specifiers for displaying a buffer in another window on the selected frame.") + (defconst display-buffer-other-frame-specifiers '(other-frame (reuse-buffer-window . visible) (not-this-window . t) (not-this-frame . t)) @@ -5020,8 +5028,8 @@ frame for displaying the buffer. The optional third argument IGNORE is ignored. -The method to display a buffer is derived by combining the values -of `display-buffer-names', `display-buffer-regexps', and +The method to display the buffer is derived by combining the +values of `display-buffer-names', `display-buffer-regexps', and SPECIFIERS. Highest priority is given to overriding elements of `display-buffer-names' followed by overriding elements of `display-buffer-regexps'. Next come the elements specified by @@ -5029,15 +5037,17 @@ SPECIFIERS, followed by the non-overriding elements of `display-buffer-names' and the non-overriding elements of `display-buffer-regexps'. -The result must be a list of valid buffer display specifiers. -`display-buffer' scans this list from front to back until it -finds a location specifier and attempts to use that specifier in -order to produce a suitable window. For this purpose, all -non-symbolic specifiers following the location specifier in the -list are considered additional specifiers. If an attempt fails -to produce a window, `display-buffer' continues with the next -location specifier on the list. Additional specifiers preceding -the currently chosen location specifier in the list are ignored." +The result must be a list of valid buffer display specifiers. If +`display-buffer-function' is non-nil, call it with the buffer and +this list as arguments. Otherwise, `display-buffer' scans this +list from front to back until it finds a location specifier and +attempts to use that specifier in order to produce a suitable +window. For this purpose, all non-symbolic specifiers following +the location specifier in the list are considered additional +specifiers. If an attempt fails to produce a window, +`display-buffer' continues with the next location specifier on +the list. Additional specifiers preceding the currently chosen +location specifier in the list are ignored." (interactive "BDisplay buffer:\nP") (let* ((buffer (normalize-buffer-to-display buffer-or-name)) (buffer-name (buffer-name buffer)) @@ -5051,87 +5061,92 @@ the currently chosen location specifier in the list are ignored." reuse-buffer-window reuse-other-window) ;; Reset this. (setq display-buffer-window nil) - ;; Retrieve the next location specifier while there a specifiers left - ;; and we don't have a valid window. - (while (and specifiers (or (not window) (not (window-live-p window)))) - (setq location (car specifiers)) - (setq specifiers (cdr specifiers)) - (when (symbolp location) - (setq window - (or (and (eq location 'same-window) - (or (not (window-dedicated-p)) - (eq (window-buffer) buffer)) - (let ((selected-window - ;; If the selected window is a minibuffer - ;; window, use the selected window of the - ;; last nonminibuffer frame instead. - (if (window-minibuffer-p) - (frame-selected-window - (last-nonminibuffer-frame)) - (selected-window)))) - (display-buffer-in-window - buffer selected-window specifiers))) - (and (memq location '(same-frame other-frame)) - (not (eq (setq reuse-buffer-window - (cdr (assq - 'reuse-buffer-window specifiers))) - 'never)) - ;; Try to reuse a window showing BUFFER. If - ;; reuse-buffer-window was set, it will specify - ;; the frames to consider, otherwise look at the - ;; selected frame's windows only. - (display-buffer-in-lru-buffer-window - buffer reuse-buffer-window specifiers)) - (and (eq location 'same-frame) - (not (frame-parameter frame 'unsplittable)) - (cdr (assq 'new-window specifiers)) - ;; Try making a new window. - (display-buffer-in-new-window buffer specifiers)) - (and (eq location 'other-frame) - ;; Try making a new frame. - (display-buffer-in-new-frame buffer specifiers)) - (and (eq location 'same-frame) - (not (eq (setq reuse-other-window - (cdr (assq 'reuse-other-window specifiers))) - 'never)) - ;; Try to reuse a window not showing BUFFER. If - ;; reuse-buffer-window was set, it will specify - ;; the frames to consider, otherwise look at the - ;; selected frame's windows only. - (display-buffer-in-lru-window - buffer reuse-other-window specifiers)) - (and (not (memq location display-buffer-locations)) - (functionp location) - ;; Separate function. - (funcall location buffer specifiers)))))) - - ;; If we don't have a window yet, try a fallback method. Note: All - ;; specifiers have been used up by now. - (or (and (window-live-p window) window) - ;; Try reusing any window showing BUFFER on a visible or - ;; iconfied frame. - (display-buffer-in-lru-buffer-window buffer 0) - ;; Try reusing a window on the selected frame. - (display-buffer-in-lru-window buffer nil) - ;; Try reusing a window on a visible frame. - (display-buffer-in-lru-window buffer 'visible) - ;; Try reusing a window on a visible or iconified frame. - (display-buffer-in-lru-window buffer 0) - ;; Try reusing any window showing BUFFER on any frame. - (display-buffer-in-lru-buffer-window buffer t) - ;; Try reusing a window on any frame. - (display-buffer-in-lru-window buffer t) - ;; Try making a new window. - (display-buffer-in-new-window buffer nil) - ;; Try making a new frame - (display-buffer-in-new-frame buffer nil) - ;; Use the selected window and let errors show trough. - (display-buffer-in-window buffer (selected-window) nil)))) + (if display-buffer-function + ;; Let `display-buffer-function' do the job handing it the list + ;; of our specifiers. + (funcall display-buffer-function buffer specifiers) + ;; Retrieve the next location specifier while there a specifiers + ;; left and we don't have a valid window. + (while (and specifiers (or (not window) (not (window-live-p window)))) + (setq location (car specifiers)) + (setq specifiers (cdr specifiers)) + (when (symbolp location) + (setq window + (or (and (eq location 'same-window) + (or (not (window-dedicated-p)) + (eq (window-buffer) buffer)) + (let ((selected-window + ;; If the selected window is a minibuffer + ;; window, use the selected window of the + ;; last nonminibuffer frame instead. + (if (window-minibuffer-p) + (frame-selected-window + (last-nonminibuffer-frame)) + (selected-window)))) + (display-buffer-in-window + buffer selected-window specifiers))) + (and (memq location '(same-frame other-frame)) + (not (eq (setq reuse-buffer-window + (cdr + (assq 'reuse-buffer-window specifiers))) + 'never)) + ;; Try to reuse a window showing BUFFER. If + ;; reuse-buffer-window was set, it will specify + ;; the frames to consider, otherwise look at the + ;; selected frame's windows only. + (display-buffer-in-lru-buffer-window + buffer reuse-buffer-window specifiers)) + (and (eq location 'same-frame) + (not (frame-parameter frame 'unsplittable)) + (cdr (assq 'new-window specifiers)) + ;; Try making a new window. + (display-buffer-in-new-window buffer specifiers)) + (and (eq location 'other-frame) + ;; Try making a new frame. + (display-buffer-in-new-frame buffer specifiers)) + (and (eq location 'same-frame) + (not (eq (setq reuse-other-window + (cdr + (assq 'reuse-other-window specifiers))) + 'never)) + ;; Try to reuse a window not showing BUFFER. If + ;; reuse-buffer-window was set, it will specify + ;; the frames to consider, otherwise look at the + ;; selected frame's windows only. + (display-buffer-in-lru-window + buffer reuse-other-window specifiers)) + (and (not (memq location display-buffer-locations)) + (functionp location) + ;; Separate function. + (funcall location buffer specifiers)))))) + + ;; If we don't have a window yet, try a fallback method. Note: All + ;; specifiers have been used up by now. + (or (and (window-live-p window) window) + ;; Try reusing any window showing BUFFER on a visible or + ;; iconfied frame. + (display-buffer-in-lru-buffer-window buffer 0) + ;; Try reusing a window on the selected frame. + (display-buffer-in-lru-window buffer nil) + ;; Try reusing a window on a visible frame. + (display-buffer-in-lru-window buffer 'visible) + ;; Try reusing a window on a visible or iconified frame. + (display-buffer-in-lru-window buffer 0) + ;; Try reusing any window showing BUFFER on any frame. + (display-buffer-in-lru-buffer-window buffer t) + ;; Try reusing a window on any frame. + (display-buffer-in-lru-window buffer t) + ;; Try making a new window. + (display-buffer-in-new-window buffer nil) + ;; Try making a new frame + (display-buffer-in-new-frame buffer nil) + ;; Use the selected window and let errors show trough. + (display-buffer-in-window buffer (selected-window) nil))))) (defun display-buffer-same-window (&optional buffer-or-name) "Display buffer specified by BUFFER-OR-NAME in the selected window. Another window will be used only if the buffer can't be shown in -the selected window, usualy because it is dedicated to another +the selected window, usually because it is dedicated to another buffer. Optional argument BUFFER-OR-NAME may be a buffer, a string \(a @@ -5144,9 +5159,24 @@ nil if no such window is found. Do not change the selected window unless a new frame is created." (display-buffer buffer-or-name 'same-window)) +(defun display-buffer-same-frame (&optional buffer-or-name) + "Display buffer specified by BUFFER-OR-NAME in a window on the same frame. +Another frame will be used only if there is no other choice. + +Optional argument BUFFER-OR-NAME may be a buffer, a string \(a +buffer name), or nil. If BUFFER-OR-NAME is a string not naming +an existent buffer, create a buffer with that name. If +BUFFER-OR-NAME is nil or omitted, display the current buffer. + +Return the window chosen to display BUFFER-OR-NAME or +nil if no such window is found. Do not change the selected +window unless a new frame is created." + (display-buffer + buffer-or-name display-buffer-same-frame-specifiers)) + (defun display-buffer-other-window (&optional buffer-or-name) "Display buffer specified by BUFFER-OR-NAME in another window. -The selected window will be used if and only if there is no other +The selected window will be used only if there is no other choice. Windows on the selected frame are preferred to windows on other frames. @@ -5161,6 +5191,22 @@ window unless a new frame is created." (display-buffer buffer-or-name display-buffer-other-window-specifiers)) +(defun display-buffer-other-window-same-frame (&optional buffer-or-name) + "Display buffer specified by BUFFER-OR-NAME in another window on the same frame. +The selected window or another frame will be used only if there +is no other choice. + +Optional argument BUFFER-OR-NAME may be a buffer, a string \(a +buffer name), or nil. If BUFFER-OR-NAME is a string not naming +an existent buffer, create a buffer with that name. If +BUFFER-OR-NAME is nil or omitted, display the current buffer. + +Return the window chosen to display BUFFER-OR-NAME or +nil if no such window is found. Do not change the selected +window unless a new frame is created." + (display-buffer + buffer-or-name display-buffer-other-window-same-frame-specifiers)) + (defun pop-to-buffer (&optional buffer-or-name specifiers norecord) "Display buffer specified by BUFFER-OR-NAME and select the window used. Optional argument BUFFER-OR-NAME may be a buffer, a string \(a @@ -5207,9 +5253,22 @@ Optional arguments BUFFER-OR-NAME and NORECORD are as for (interactive "BPop to buffer in selected window:\nP") (pop-to-buffer buffer-or-name 'same-window norecord)) +(defun pop-to-buffer-same-frame (&optional buffer-or-name norecord) + "Pop to buffer specified by BUFFER-OR-NAME in a window on the selected frame. +Another frame will be used only if there is no other choice. +Select the window used for displaying the buffer and return the +buffer specified by BUFFER-OR-NAME or nil if displaying the +buffer failed. + +Optional arguments BUFFER-OR-NAME and NORECORD are as for +`pop-to-buffer'." + (interactive "BPop to buffer in another window:\nP") + (pop-to-buffer + buffer-or-name display-buffer-same-frame-specifiers norecord)) + (defun pop-to-buffer-other-window (&optional buffer-or-name norecord) "Pop to buffer specified by BUFFER-OR-NAME in another window. -The selected window will be used if and only if there is no other +The selected window will be used only if there is no other choice. Windows on the selected frame are preferred to windows on other frames. Select the window used for displaying the buffer and return the buffer specified by BUFFER-OR-NAME or nil @@ -5221,6 +5280,19 @@ Optional arguments BUFFER-OR-NAME and NORECORD are as for (pop-to-buffer buffer-or-name display-buffer-other-window-specifiers norecord)) +(defun pop-to-buffer-other-window-same-frame (&optional buffer-or-name norecord) + "Pop to buffer specified by BUFFER-OR-NAME in another window on the selected frame. +The selected window or another frame will be used only if there +is no other choice. Select the window used for displaying the +buffer and return the buffer specified by BUFFER-OR-NAME or nil +if displaying the buffer failed. + +Optional arguments BUFFER-OR-NAME and NORECORD are as for +`pop-to-buffer'." + (interactive "BPop to buffer in another window:\nP") + (pop-to-buffer + buffer-or-name display-buffer-other-window-same-frame-specifiers norecord)) + (defun pop-to-buffer-other-frame (&optional buffer-or-name norecord) "Pop to buffer specified by BUFFER-OR-NAME on another frame. The selected frame will be used only if there's no other choice. @@ -5308,9 +5380,41 @@ should call `pop-to-buffer-same-window' instead." (select-window (selected-window))) (set-buffer buffer)))) +(defun switch-to-buffer-same-frame (buffer-or-name &optional norecord) + "Switch to buffer BUFFER-OR-NAME in a window on the selected frame. +Another frame will be used only if there is no other choice. + +If called interactively, prompt for the buffer name using the +minibuffer. The variable `confirm-nonexistent-file-or-buffer' +determines whether to request confirmation before creating a new +buffer. + +When called from Lisp, BUFFER-OR-NAME may be a buffer, a string +\(a buffer name), or nil. If BUFFER-OR-NAME is a string that +does not identify an existing buffer, create a buffer with that +name. If BUFFER-OR-NAME is nil, switch to the buffer returned by +`other-buffer'. + +Optional argument NORECORD non-nil means do not put the buffer +specified by BUFFER-OR-NAME at the front of the buffer list and +do not make the window displaying it the most recently selected +one. Return the buffer switched to. + +This uses the function `display-buffer' as a subroutine; see the +documentations of `display-buffer', `display-buffer-names' and +`display-buffer-regexps' for additional information. + +This function is intended for interactive use. Lisp functions +should call `pop-to-buffer-other-window' instead." + (interactive + (list (read-buffer-to-switch "Switch to buffer in other window: "))) + (let ((buffer (normalize-buffer-to-switch-to buffer-or-name))) + (pop-to-buffer + buffer display-buffer-same-frame-specifiers norecord))) + (defun switch-to-buffer-other-window (buffer-or-name &optional norecord) "Switch to buffer BUFFER-OR-NAME in another window. -The selected window will be used if and only if there is no other +The selected window will be used only if there is no other choice. Windows on the selected frame are preferred to windows on other frames. @@ -5342,6 +5446,39 @@ should call `pop-to-buffer-other-window' instead." (pop-to-buffer buffer display-buffer-other-window-specifiers norecord))) +(defun switch-to-buffer-other-window-same-frame (buffer-or-name &optional norecord) + "Switch to buffer BUFFER-OR-NAME in another window on the selected frame. +The selected window or another frame will be used only if there +is no other choice. + +If called interactively, prompt for the buffer name using the +minibuffer. The variable `confirm-nonexistent-file-or-buffer' +determines whether to request confirmation before creating a new +buffer. + +When called from Lisp, BUFFER-OR-NAME may be a buffer, a string +\(a buffer name), or nil. If BUFFER-OR-NAME is a string that +does not identify an existing buffer, create a buffer with that +name. If BUFFER-OR-NAME is nil, switch to the buffer returned by +`other-buffer'. + +Optional argument NORECORD non-nil means do not put the buffer +specified by BUFFER-OR-NAME at the front of the buffer list and +do not make the window displaying it the most recently selected +one. Return the buffer switched to. + +This uses the function `display-buffer' as a subroutine; see the +documentations of `display-buffer', `display-buffer-names' and +`display-buffer-regexps' for additional information. + +This function is intended for interactive use. Lisp functions +should call `pop-to-buffer-other-window' instead." + (interactive + (list (read-buffer-to-switch "Switch to buffer in other window: "))) + (let ((buffer (normalize-buffer-to-switch-to buffer-or-name))) + (pop-to-buffer + buffer display-buffer-other-window-same-frame-specifiers norecord))) + (defun switch-to-buffer-other-frame (buffer-or-name &optional norecord) "Switch to buffer BUFFER-OR-NAME on another frame. If called interactively, prompt for the buffer name using the @@ -5371,26 +5508,31 @@ should call `pop-to-buffer-other-frame' instead." (let ((buffer (normalize-buffer-to-switch-to buffer-or-name))) (pop-to-buffer buffer display-buffer-other-frame-specifiers norecord))) -;;; Obsolete definitions of `display-buffer' below. (defcustom display-buffer-function nil "If non-nil, function to call to display a buffer. `display-buffer' calls this function with two arguments, the -buffer to display and a flag which if non-nil means that the -selected window is not acceptable for displaying the buffer. It -should choose or create a window, display the specified buffer in -it, and return the window. - -Commands such as `switch-to-buffer-other-window' and -`find-file-other-window' work using this function." +buffer to display and a list of buffer display specifiers, see +`display-buffer-names'. + +The function is supposed to choose or create a window, display +the specified buffer in it, and return the window. It is also +responsible for giving the variable `display-buffer-window' and +the `quit-restore' parameter of the window used a meaningful +value. + +The function specified here overrides all specifiers of the +variables `display-buffer-names' and `display-buffer-regexps' and +any specifiers passed to `display-buffer'. + +If you call `display-buffer' within the body of the function, +bind the value of `display-buffer-function' to nil around that +call to avoid that the function recursively calls itself." :type '(choice (const nil) - (function :tag "function")) + (function :tag "Function")) :group 'display-buffer) -(make-obsolete-variable - 'display-buffer-function - "use `display-buffer-names' or `display-buffer-regexps' instead." - "24.1") +;;; Obsolete definitions of `display-buffer' below. (defcustom special-display-buffer-names nil "List of names of buffers that should be displayed specially. Displaying a buffer with `display-buffer' or `pop-to-buffer', if -- 2.39.5