Skip to content

Commit 7826a2d

Browse files
committed
cider-popup-buffer-display: Do nothing if the intended buffer is visible in another frame and select is nil
This seems the right thing to do.
1 parent c4fa1a8 commit 7826a2d

File tree

1 file changed

+43
-38
lines changed

1 file changed

+43
-38
lines changed

cider-popup.el

+43-38
Original file line numberDiff line numberDiff line change
@@ -55,44 +55,49 @@ If SELECT is non-nil, select the buffer.
5555
5656
You can customize how the window will be chosen/created
5757
by adding BUFFER-NAME to the `special-display-buffer-names' list."
58-
(let ((buffer-name (if (bufferp buffer-name) ;; ensure buffer-name is a string
59-
(buffer-name buffer-name)
60-
buffer-name)))
61-
;; if `buffer-name' belongs to `special-display-buffer-names',
62-
;; delegate to that mechanism the displaying of the buffer,
63-
;; otherwise the displaying would happen twice (ance through `special-display-buffer-names',
64-
;; another time through `cider-popup-buffer-display'):
65-
(if (and (boundp 'special-display-buffer-names)
66-
(seq-find (lambda (entry)
67-
(equal (car entry) buffer-name))
68-
special-display-buffer-names))
69-
(progn
70-
(display-buffer buffer-name)
71-
(when select
72-
(when-let ((window (get-buffer-window buffer-name)))
73-
(select-window window))))
74-
(let ((window (get-buffer-window buffer-name 'visible)))
75-
(when window
76-
(with-current-buffer buffer-name
77-
(set-window-point window (point))))
78-
;; If the buffer we are popping up is already displayed in the selected
79-
;; window, the below `inhibit-same-window' logic will cause it to be
80-
;; displayed twice - so we early out in this case. Note that we must check
81-
;; `selected-window', as async request handlers are executed in the context
82-
;; of the current connection buffer (i.e. `current-buffer' is dynamically
83-
;; bound to that).
84-
(unless (eq window (selected-window))
85-
;; Non nil `inhibit-same-window' ensures that current window is not covered
86-
;; Non nil `inhibit-switch-frame' ensures that the other frame is not selected
87-
;; if that's where the buffer is being shown.
88-
(funcall (if select #'pop-to-buffer #'display-buffer)
89-
buffer-name `(nil . ((inhibit-same-window .
90-
;; A non-nil value prevents the same window from being used for display:
91-
,pop-up-windows)
92-
(reusable-frames .
93-
;; choose any visible frame
94-
visible)))))))
95-
(get-buffer buffer-name)))
58+
(if (and (not select)
59+
(get-buffer-window buffer-name t))
60+
;; if the buffer is visible on some frame and the user didn't intend `select', we're done.
61+
;; This supports e.g. rendering contents to frames that the user might want to remain in the background (e.g. cider-log, cider-auto-inspect-after-eval)
62+
nil
63+
(let ((buffer-name (if (bufferp buffer-name) ;; ensure buffer-name is a string
64+
(buffer-name buffer-name)
65+
buffer-name)))
66+
;; if `buffer-name' belongs to `special-display-buffer-names',
67+
;; delegate to that mechanism the displaying of the buffer,
68+
;; otherwise the displaying would happen twice (ance through `special-display-buffer-names',
69+
;; another time through `cider-popup-buffer-display'):
70+
(if (and (boundp 'special-display-buffer-names)
71+
(seq-find (lambda (entry)
72+
(equal (car entry) buffer-name))
73+
special-display-buffer-names))
74+
(progn
75+
(display-buffer buffer-name)
76+
(when select
77+
(when-let ((window (get-buffer-window buffer-name)))
78+
(select-window window))))
79+
(let ((window (get-buffer-window buffer-name 'visible)))
80+
(when window
81+
(with-current-buffer buffer-name
82+
(set-window-point window (point))))
83+
;; If the buffer we are popping up is already displayed in the selected
84+
;; window, the below `inhibit-same-window' logic will cause it to be
85+
;; displayed twice - so we early out in this case. Note that we must check
86+
;; `selected-window', as async request handlers are executed in the context
87+
;; of the current connection buffer (i.e. `current-buffer' is dynamically
88+
;; bound to that).
89+
(unless (eq window (selected-window))
90+
;; Non nil `inhibit-same-window' ensures that current window is not covered
91+
;; Non nil `inhibit-switch-frame' ensures that the other frame is not selected
92+
;; if that's where the buffer is being shown.
93+
(funcall (if select #'pop-to-buffer #'display-buffer)
94+
buffer-name `(nil . ((inhibit-same-window .
95+
;; A non-nil value prevents the same window from being used for display:
96+
,pop-up-windows)
97+
(reusable-frames .
98+
;; choose any visible frame
99+
visible)))))))
100+
(get-buffer buffer-name))))
96101

97102
(defun cider-popup-buffer-quit (&optional kill)
98103
"Quit the current (temp) window.

0 commit comments

Comments
 (0)