diff options
author | Martin Rudalics <rudalics@gmx.at> | 2016-08-30 12:30:29 +0200 |
---|---|---|
committer | Martin Rudalics <rudalics@gmx.at> | 2016-08-30 12:30:29 +0200 |
commit | 4961cc3f368d9114c305efe6243987bcfa3fd29b (patch) | |
tree | 8aa4e8baf1f2efeca29a4e40adae8d720da9d587 | |
parent | bcd2d911f35fd28f0a0051f237dc76f15cea4b4a (diff) |
In `pop-to-buffer' handle case where `display-buffer' fails (Bug#24332)
* lisp/window.el (pop-to-buffer): Don't assume that
`display-buffer' has supplied a window (Bug#24332).
Rename BUFFER argument to BUFFER-OR-NAME.
* doc/lispref/windows.texi (Switching Buffers): Fix
`pop-to-buffer' documentation.
-rw-r--r-- | doc/lispref/windows.texi | 6 | ||||
-rw-r--r-- | lisp/window.el | 47 |
2 files changed, 29 insertions, 24 deletions
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 36bccdd30a..3c9df0b306 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -2233,15 +2233,15 @@ This function makes @var{buffer-or-name} the current buffer and displays it in some window, preferably not the window currently selected. It then selects the displaying window. If that window is on a different graphical frame, that frame is given input focus if -possible (@pxref{Input Focus}). The return value is the buffer that -was switched to. +possible (@pxref{Input Focus}). If @var{buffer-or-name} is @code{nil}, it defaults to the buffer returned by @code{other-buffer} (@pxref{Buffer List}). If @var{buffer-or-name} is a string that is not the name of any existing buffer, this function creates a new buffer with that name; the new buffer's major mode is determined by the variable @code{major-mode} -(@pxref{Major Modes}). +(@pxref{Major Modes}). In any case, that buffer is made current and +returned, even when no suitable window was found to display it. If @var{action} is non-@code{nil}, it should be a display action to pass to @code{display-buffer} (@pxref{Choosing Window}). diff --git a/lisp/window.el b/lisp/window.el index cfa10ea1b0..6728ea34a8 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -6692,8 +6692,7 @@ that allows the selected frame)." (window--display-buffer buffer window 'frame alist display-buffer-mark-dedicated) (unless (cdr (assq 'inhibit-switch-frame alist)) - (window--maybe-raise-frame frame)))) - )) + (window--maybe-raise-frame frame)))))) (defun display-buffer-same-window (buffer alist) "Display BUFFER in the selected window. @@ -7074,12 +7073,12 @@ returned from `display-buffer' in this case." 'fail)) ;;; Display + selection commands: -(defun pop-to-buffer (buffer &optional action norecord) - "Select buffer BUFFER in some window, preferably a different one. -BUFFER may be a buffer, a string (a buffer name), or nil. If it -is a string not naming an existent buffer, create a buffer with -that name. If BUFFER is nil, choose some other buffer. Return -the buffer. +(defun pop-to-buffer (buffer-or-name &optional action norecord) + "Display buffer specified by BUFFER-OR-NAME and select its window. +BUFFER-OR-NAME may be a buffer, a string (a buffer name), or nil. +If it is a string not naming an existent buffer, create a buffer +with that name. If BUFFER-OR-NAME is nil, choose some other +buffer. In either case, make that buffer current and return it. This uses `display-buffer' as a subroutine. The optional ACTION argument is passed to `display-buffer' as its ACTION argument. @@ -7088,24 +7087,30 @@ interactively with a prefix argument, which means to pop to a window other than the selected one even if the buffer is already displayed in the selected window. -If the window to show BUFFER is not on the selected -frame, raise that window's frame and give it input focus. +If a suitable window is found, select that window. If it is not +on the selected frame, raise that window's frame and give it +input focus. Optional third arg NORECORD non-nil means do not put this buffer at the front of the list of recently selected ones." (interactive (list (read-buffer "Pop to buffer: " (other-buffer)) (if current-prefix-arg t))) - (setq buffer (window-normalize-buffer-to-switch-to buffer)) - ;; This should be done by `select-window' below. - ;; (set-buffer buffer) - (let* ((old-frame (selected-frame)) - (window (display-buffer buffer action)) - (frame (window-frame window))) - ;; If we chose another frame, make sure it gets input focus. - (unless (eq frame old-frame) - (select-frame-set-input-focus frame norecord)) - ;; Make sure new window is selected (Bug#8615), (Bug#6954). - (select-window window norecord) + (let* ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)) + (old-frame (selected-frame)) + (window (display-buffer buffer action))) + ;; Don't assume that `display-buffer' has supplied us with a window + ;; (Bug#24332). + (if window + (let ((frame (window-frame window))) + ;; If we chose another frame, make sure it gets input focus. + (unless (eq frame old-frame) + (select-frame-set-input-focus frame norecord)) + ;; Make sure the window is selected (Bug#8615), (Bug#6954) + (select-window window norecord)) + ;; If `display-buffer' failed to supply a window, just make the + ;; buffer current. + (set-buffer buffer)) + ;; Return BUFFER even when we got no window. buffer)) (defun pop-to-buffer-same-window (buffer &optional norecord) |