Commit 90749b53 authored by Chong Yidong's avatar Chong Yidong
Browse files

Add inhibit-switch-frame parameter for display-buffer, and use it in occur-edit.

* replace.el (occur-after-change-function): Avoid losing focus by
using the inhibit-switch-frame display action option.

* window.el (window--maybe-raise-frame): New function.
(window--display-buffer): Split off from here.
(display-buffer-reuse-window, display-buffer-pop-up-frame)
(display-buffer-pop-up-window, display-buffer-use-some-window):
Obey an inhibit-switch-frame action alist entry.
(display-buffer): Update doc.

Fixes: debbugs:12139
parent edd74c35
...@@ -565,9 +565,14 @@ The interpretation of the DECLS is determined by `defun-declarations-alist'. ...@@ -565,9 +565,14 @@ The interpretation of the DECLS is determined by `defun-declarations-alist'.
** New error type and new function `user-error'. Doesn't trigger the debugger. ** New error type and new function `user-error'. Doesn't trigger the debugger.
** The functions get-lru-window, get-mru-window and get-largest-window ** Window changes
*** The functions get-lru-window, get-mru-window and get-largest-window
now accept a third argument to avoid choosing the selected window. now accept a third argument to avoid choosing the selected window.
*** New display action alist `inhibit-switch-frame', if non-nil, tells
display action functions to avoid changing which frame is selected.
** Completion ** Completion
*** New function `completion-table-with-quoting' to handle completion *** New function `completion-table-with-quoting' to handle completion
......
2012-08-06 Chong Yidong <cyd@gnu.org>
* window.el (window--maybe-raise-frame): New function.
(window--display-buffer): Split off from here.
(display-buffer-reuse-window, display-buffer-pop-up-frame)
(display-buffer-pop-up-window, display-buffer-use-some-window):
Obey an inhibit-switch-frame action alist entry.
(display-buffer): Update doc.
* replace.el (occur-after-change-function): Avoid losing focus by
using the inhibit-switch-frame display parameter (Bug#12139).
2012-08-06 Fabián Ezequiel Gallina <fgallina@cuca> 2012-08-06 Fabián Ezequiel Gallina <fgallina@cuca>
   
Make internal shell process buffer names start with space. Make internal shell process buffer names start with space.
......
...@@ -912,7 +912,9 @@ To return to ordinary Occur mode, use \\[occur-cease-edit]." ...@@ -912,7 +912,9 @@ To return to ordinary Occur mode, use \\[occur-cease-edit]."
(line-number-at-pos (window-start)))) (line-number-at-pos (window-start))))
(readonly (with-current-buffer buf buffer-read-only)) (readonly (with-current-buffer buf buffer-read-only))
(win (or (get-buffer-window buf) (win (or (get-buffer-window buf)
(display-buffer buf t))) (display-buffer buf
'(nil (inhibit-same-window . t)
(inhibit-switch-frame . t)))))
(line-end (line-end-position)) (line-end (line-end-position))
(text (save-excursion (text (save-excursion
(goto-char (next-single-property-change (goto-char (next-single-property-change
......
...@@ -4602,27 +4602,26 @@ is passed unaltered to `display-buffer-record-window'. Set ...@@ -4602,27 +4602,26 @@ is passed unaltered to `display-buffer-record-window'. Set
`window-dedicated-p' to DEDICATED if non-nil. Return WINDOW if `window-dedicated-p' to DEDICATED if non-nil. Return WINDOW if
BUFFER and WINDOW are live." BUFFER and WINDOW are live."
(when (and (buffer-live-p buffer) (window-live-p window)) (when (and (buffer-live-p buffer) (window-live-p window))
(let* ((frame (window-frame window)) (unless (eq buffer (window-buffer window))
(visible (frame-visible-p frame))) (set-window-dedicated-p window nil)
(unless (eq buffer (window-buffer window)) (display-buffer-record-window type window buffer)
(set-window-dedicated-p window nil) (set-window-buffer window buffer)
(display-buffer-record-window type window buffer) (when dedicated
(set-window-buffer window buffer) (set-window-dedicated-p window dedicated))
(when dedicated (when (memq type '(window frame))
(set-window-dedicated-p window dedicated)) (set-window-prev-buffers window nil)))
(when (memq type '(window frame)) window))
(set-window-prev-buffers window nil)))
(defun window--maybe-raise-frame (frame)
(unless (or (not visible) (let ((visible (frame-visible-p frame)))
;; Assume the selected frame is already visible enough. (unless (or (not visible)
(eq frame (selected-frame)) ;; Assume the selected frame is already visible enough.
;; Assume the frame from which we invoked the minibuffer (eq frame (selected-frame))
;; is visible. ;; Assume the frame from which we invoked the
(and (minibuffer-window-active-p (selected-window)) ;; minibuffer is visible.
(eq frame (window-frame (minibuffer-selected-window))))) (and (minibuffer-window-active-p (selected-window))
(raise-frame frame)) (eq frame (window-frame (minibuffer-selected-window)))))
(raise-frame frame))))
window)))
;; FIXME: Not implemented. ;; FIXME: Not implemented.
;; FIXME: By the way, there could be more levels of dedication: ;; FIXME: By the way, there could be more levels of dedication:
...@@ -4771,6 +4770,10 @@ Recognized alist entries include: ...@@ -4771,6 +4770,10 @@ Recognized alist entries include:
`inhibit-same-window' -- A non-nil value prevents the same `inhibit-same-window' -- A non-nil value prevents the same
window from being used for display. window from being used for display.
`inhibit-switch-frame' -- A non-nil value prevents any other
frame from being raised or selected,
even if the window is displayed there.
`reusable-frames' -- Value specifies frame(s) to search for a `reusable-frames' -- Value specifies frame(s) to search for a
window that already displays the buffer. window that already displays the buffer.
See `display-buffer-reuse-window'. See `display-buffer-reuse-window'.
...@@ -4872,7 +4875,11 @@ which frames to search for a reusable window: ...@@ -4872,7 +4875,11 @@ which frames to search for a reusable window:
If ALIST contains no `reusable-frames' entry, search just the If ALIST contains no `reusable-frames' entry, search just the
selected frame if `display-buffer-reuse-frames' and selected frame if `display-buffer-reuse-frames' and
`pop-up-frames' are both nil; search all frames on the current `pop-up-frames' are both nil; search all frames on the current
terminal if either of those variables is non-nil." terminal if either of those variables is non-nil.
If ALIST has a non-nil `inhibit-switch-frame' entry, then in the
event that a window on another frame is chosen, avoid raising
that frame."
(let* ((alist-entry (assq 'reusable-frames alist)) (let* ((alist-entry (assq 'reusable-frames alist))
(frames (cond (alist-entry (cdr alist-entry)) (frames (cond (alist-entry (cdr alist-entry))
((if (eq pop-up-frames 'graphic-only) ((if (eq pop-up-frames 'graphic-only)
...@@ -4887,8 +4894,10 @@ terminal if either of those variables is non-nil." ...@@ -4887,8 +4894,10 @@ terminal if either of those variables is non-nil."
(car (delq (selected-window) (car (delq (selected-window)
(get-buffer-window-list buffer 'nomini (get-buffer-window-list buffer 'nomini
frames)))))) frames))))))
(when window (when (window-live-p window)
(window--display-buffer buffer window 'reuse)))) (prog1 (window--display-buffer buffer window 'reuse)
(unless (cdr (assq 'inhibit-switch-frame alist))
(window--maybe-raise-frame (window-frame window)))))))
(defun display-buffer--special-action (buffer) (defun display-buffer--special-action (buffer)
"Return special display action for BUFFER, if any. "Return special display action for BUFFER, if any.
...@@ -4905,23 +4914,32 @@ See `display-buffer' for the format of display actions." ...@@ -4905,23 +4914,32 @@ See `display-buffer' for the format of display actions."
(funcall special-display-function (funcall special-display-function
buffer ',(if (listp pars) pars))))))))) buffer ',(if (listp pars) pars)))))))))
(defun display-buffer-pop-up-frame (buffer _alist) (defun display-buffer-pop-up-frame (buffer alist)
"Display BUFFER in a new frame. "Display BUFFER in a new frame.
This works by calling `pop-up-frame-function'. If successful, This works by calling `pop-up-frame-function'. If successful,
return the window used; otherwise return nil." return the window used; otherwise return nil.
If ALIST has a non-nil `inhibit-switch-frame' entry, avoid
raising the new frame."
(let ((fun pop-up-frame-function) (let ((fun pop-up-frame-function)
frame window) frame window)
(when (and fun (when (and fun
(setq frame (funcall fun)) (setq frame (funcall fun))
(setq window (frame-selected-window frame))) (setq window (frame-selected-window frame)))
(window--display-buffer (prog1 (window--display-buffer buffer window
buffer window 'frame display-buffer-mark-dedicated)))) 'frame display-buffer-mark-dedicated)
(unless (cdr (assq 'inhibit-switch-frame alist))
(window--maybe-raise-frame frame))))))
(defun display-buffer-pop-up-window (buffer _alist) (defun display-buffer-pop-up-window (buffer alist)
"Display BUFFER by popping up a new window. "Display BUFFER by popping up a new window.
The new window is created on the selected frame, or in The new window is created on the selected frame, or in
`last-nonminibuffer-frame' if no windows can be created there. `last-nonminibuffer-frame' if no windows can be created there.
If successful, return the new window; otherwise return nil." If successful, return the new window; otherwise return nil.
If ALIST has a non-nil `inhibit-switch-frame' entry, then in the
event that the new window is created on another frame, avoid
raising the frame."
(let ((frame (or (window--frame-usable-p (selected-frame)) (let ((frame (or (window--frame-usable-p (selected-frame))
(window--frame-usable-p (last-nonminibuffer-frame)))) (window--frame-usable-p (last-nonminibuffer-frame))))
window) window)
...@@ -4937,8 +4955,10 @@ If successful, return the new window; otherwise return nil." ...@@ -4937,8 +4955,10 @@ If successful, return the new window; otherwise return nil."
(get-largest-window frame t)) (get-largest-window frame t))
(window--try-to-split-window (window--try-to-split-window
(get-lru-window frame t))))) (get-lru-window frame t)))))
(window--display-buffer (prog1 (window--display-buffer buffer window
buffer window 'window display-buffer-mark-dedicated)))) 'window display-buffer-mark-dedicated)
(unless (cdr (assq 'inhibit-switch-frame alist))
(window--maybe-raise-frame (window-frame window)))))))
(defun display-buffer--maybe-pop-up-frame-or-window (buffer alist) (defun display-buffer--maybe-pop-up-frame-or-window (buffer alist)
"Try displaying BUFFER based on `pop-up-frames' or `pop-up-windows'. "Try displaying BUFFER based on `pop-up-frames' or `pop-up-windows'.
...@@ -4958,7 +4978,11 @@ again with `display-buffer-pop-up-window'." ...@@ -4958,7 +4978,11 @@ again with `display-buffer-pop-up-window'."
(defun display-buffer-use-some-window (buffer alist) (defun display-buffer-use-some-window (buffer alist)
"Display BUFFER in an existing window. "Display BUFFER in an existing window.
Search for a usable window, set that window to the buffer, and Search for a usable window, set that window to the buffer, and
return the window. If no suitable window is found, return nil." return the window. If no suitable window is found, return nil.
If ALIST has a non-nil `inhibit-switch-frame' entry, then in the
event that a window in another frame is chosen, avoid raising
that frame."
(let* ((not-this-window (cdr (assq 'inhibit-same-window alist))) (let* ((not-this-window (cdr (assq 'inhibit-same-window alist)))
(frame (or (window--frame-usable-p (selected-frame)) (frame (or (window--frame-usable-p (selected-frame))
(window--frame-usable-p (last-nonminibuffer-frame)))) (window--frame-usable-p (last-nonminibuffer-frame))))
...@@ -4975,9 +4999,11 @@ return the window. If no suitable window is found, return nil." ...@@ -4975,9 +4999,11 @@ return the window. If no suitable window is found, return nil."
(eq window (selected-window))) (eq window (selected-window)))
window)) window))
(get-largest-window 0 not-this-window)))) (get-largest-window 0 not-this-window))))
(when window (when (window-live-p window)
(window--even-window-heights window) (window--even-window-heights window)
(window--display-buffer buffer window 'reuse)))) (prog1 (window--display-buffer buffer window 'reuse)
(unless (cdr (assq 'inhibit-switch-frame alist))
(window--maybe-raise-frame (window-frame window)))))))
;;; Display + selection commands: ;;; Display + selection commands:
(defun pop-to-buffer (buffer &optional action norecord) (defun pop-to-buffer (buffer &optional action norecord)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment