diff options
| author | Martin Rudalics | 2016-08-30 12:30:29 +0200 |
|---|---|---|
| committer | Martin Rudalics | 2016-08-30 12:30:29 +0200 |
| commit | 4961cc3f368d9114c305efe6243987bcfa3fd29b (patch) | |
| tree | 8aa4e8baf1f2efeca29a4e40adae8d720da9d587 | |
| parent | bcd2d911f35fd28f0a0051f237dc76f15cea4b4a (diff) | |
| download | emacs-4961cc3f368d9114c305efe6243987bcfa3fd29b.tar.gz emacs-4961cc3f368d9114c305efe6243987bcfa3fd29b.zip | |
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 36bccdd30a1..3c9df0b306d 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 | |||
| 2233 | displays it in some window, preferably not the window currently | 2233 | displays it in some window, preferably not the window currently |
| 2234 | selected. It then selects the displaying window. If that window is | 2234 | selected. It then selects the displaying window. If that window is |
| 2235 | on a different graphical frame, that frame is given input focus if | 2235 | on a different graphical frame, that frame is given input focus if |
| 2236 | possible (@pxref{Input Focus}). The return value is the buffer that | 2236 | possible (@pxref{Input Focus}). |
| 2237 | was switched to. | ||
| 2238 | 2237 | ||
| 2239 | If @var{buffer-or-name} is @code{nil}, it defaults to the buffer | 2238 | If @var{buffer-or-name} is @code{nil}, it defaults to the buffer |
| 2240 | returned by @code{other-buffer} (@pxref{Buffer List}). If | 2239 | returned by @code{other-buffer} (@pxref{Buffer List}). If |
| 2241 | @var{buffer-or-name} is a string that is not the name of any existing | 2240 | @var{buffer-or-name} is a string that is not the name of any existing |
| 2242 | buffer, this function creates a new buffer with that name; the new | 2241 | buffer, this function creates a new buffer with that name; the new |
| 2243 | buffer's major mode is determined by the variable @code{major-mode} | 2242 | buffer's major mode is determined by the variable @code{major-mode} |
| 2244 | (@pxref{Major Modes}). | 2243 | (@pxref{Major Modes}). In any case, that buffer is made current and |
| 2244 | returned, even when no suitable window was found to display it. | ||
| 2245 | 2245 | ||
| 2246 | If @var{action} is non-@code{nil}, it should be a display action to | 2246 | If @var{action} is non-@code{nil}, it should be a display action to |
| 2247 | pass to @code{display-buffer} (@pxref{Choosing Window}). | 2247 | pass to @code{display-buffer} (@pxref{Choosing Window}). |
diff --git a/lisp/window.el b/lisp/window.el index cfa10ea1b0f..6728ea34a83 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -6692,8 +6692,7 @@ that allows the selected frame)." | |||
| 6692 | (window--display-buffer | 6692 | (window--display-buffer |
| 6693 | buffer window 'frame alist display-buffer-mark-dedicated) | 6693 | buffer window 'frame alist display-buffer-mark-dedicated) |
| 6694 | (unless (cdr (assq 'inhibit-switch-frame alist)) | 6694 | (unless (cdr (assq 'inhibit-switch-frame alist)) |
| 6695 | (window--maybe-raise-frame frame)))) | 6695 | (window--maybe-raise-frame frame)))))) |
| 6696 | )) | ||
| 6697 | 6696 | ||
| 6698 | (defun display-buffer-same-window (buffer alist) | 6697 | (defun display-buffer-same-window (buffer alist) |
| 6699 | "Display BUFFER in the selected window. | 6698 | "Display BUFFER in the selected window. |
| @@ -7074,12 +7073,12 @@ returned from `display-buffer' in this case." | |||
| 7074 | 'fail)) | 7073 | 'fail)) |
| 7075 | 7074 | ||
| 7076 | ;;; Display + selection commands: | 7075 | ;;; Display + selection commands: |
| 7077 | (defun pop-to-buffer (buffer &optional action norecord) | 7076 | (defun pop-to-buffer (buffer-or-name &optional action norecord) |
| 7078 | "Select buffer BUFFER in some window, preferably a different one. | 7077 | "Display buffer specified by BUFFER-OR-NAME and select its window. |
| 7079 | BUFFER may be a buffer, a string (a buffer name), or nil. If it | 7078 | BUFFER-OR-NAME may be a buffer, a string (a buffer name), or nil. |
| 7080 | is a string not naming an existent buffer, create a buffer with | 7079 | If it is a string not naming an existent buffer, create a buffer |
| 7081 | that name. If BUFFER is nil, choose some other buffer. Return | 7080 | with that name. If BUFFER-OR-NAME is nil, choose some other |
| 7082 | the buffer. | 7081 | buffer. In either case, make that buffer current and return it. |
| 7083 | 7082 | ||
| 7084 | This uses `display-buffer' as a subroutine. The optional ACTION | 7083 | This uses `display-buffer' as a subroutine. The optional ACTION |
| 7085 | argument is passed to `display-buffer' as its ACTION argument. | 7084 | 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 | |||
| 7088 | window other than the selected one even if the buffer is already | 7087 | window other than the selected one even if the buffer is already |
| 7089 | displayed in the selected window. | 7088 | displayed in the selected window. |
| 7090 | 7089 | ||
| 7091 | If the window to show BUFFER is not on the selected | 7090 | If a suitable window is found, select that window. If it is not |
| 7092 | frame, raise that window's frame and give it input focus. | 7091 | on the selected frame, raise that window's frame and give it |
| 7092 | input focus. | ||
| 7093 | 7093 | ||
| 7094 | Optional third arg NORECORD non-nil means do not put this buffer | 7094 | Optional third arg NORECORD non-nil means do not put this buffer |
| 7095 | at the front of the list of recently selected ones." | 7095 | at the front of the list of recently selected ones." |
| 7096 | (interactive (list (read-buffer "Pop to buffer: " (other-buffer)) | 7096 | (interactive (list (read-buffer "Pop to buffer: " (other-buffer)) |
| 7097 | (if current-prefix-arg t))) | 7097 | (if current-prefix-arg t))) |
| 7098 | (setq buffer (window-normalize-buffer-to-switch-to buffer)) | 7098 | (let* ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)) |
| 7099 | ;; This should be done by `select-window' below. | 7099 | (old-frame (selected-frame)) |
| 7100 | ;; (set-buffer buffer) | 7100 | (window (display-buffer buffer action))) |
| 7101 | (let* ((old-frame (selected-frame)) | 7101 | ;; Don't assume that `display-buffer' has supplied us with a window |
| 7102 | (window (display-buffer buffer action)) | 7102 | ;; (Bug#24332). |
| 7103 | (frame (window-frame window))) | 7103 | (if window |
| 7104 | ;; If we chose another frame, make sure it gets input focus. | 7104 | (let ((frame (window-frame window))) |
| 7105 | (unless (eq frame old-frame) | 7105 | ;; If we chose another frame, make sure it gets input focus. |
| 7106 | (select-frame-set-input-focus frame norecord)) | 7106 | (unless (eq frame old-frame) |
| 7107 | ;; Make sure new window is selected (Bug#8615), (Bug#6954). | 7107 | (select-frame-set-input-focus frame norecord)) |
| 7108 | (select-window window norecord) | 7108 | ;; Make sure the window is selected (Bug#8615), (Bug#6954) |
| 7109 | (select-window window norecord)) | ||
| 7110 | ;; If `display-buffer' failed to supply a window, just make the | ||
| 7111 | ;; buffer current. | ||
| 7112 | (set-buffer buffer)) | ||
| 7113 | ;; Return BUFFER even when we got no window. | ||
| 7109 | buffer)) | 7114 | buffer)) |
| 7110 | 7115 | ||
| 7111 | (defun pop-to-buffer-same-window (buffer &optional norecord) | 7116 | (defun pop-to-buffer-same-window (buffer &optional norecord) |