feat(popup): +popup/raise: use visible popup if none selected

This command would formerly raise the focused window into a regular
window, erroring out if that window isn't a popup. Now, if the focused
window isn't a popup, any (single) visible popup in the current frame
will be targeted, and if multiple popups are visible, you'll be prompted
to select one.
This commit is contained in:
Henrik Lissner
2025-03-31 17:25:44 -04:00
parent 8b37baada7
commit 5b11ac7267

View File

@ -428,15 +428,34 @@ If no popups are available, display the *Messages* buffer in a popup window."
;;;###autoload
(defun +popup/raise (window &optional arg)
"Raise the current popup window into a regular window and
return it. If prefix ARG, raise the current popup into a new
window and return that window."
"Raise a popup WINDOW into a regular window, then select it.
When called interactively, the selected popup window will be raised. If the
selected window isn't a popup, any sole, visible popup window in the active
frame will be raised. If there are multiple visible popups, then the user will
be prompted to select one.
If prefix ARG, the popup is raised into `other-window' instead."
(interactive
(list (selected-window) current-prefix-arg))
(list
(let ((win (selected-window)))
(if (+popup-window-p win)
win
(if-let* ((popups
(cl-loop for w in (+popup-windows)
collect (cons (buffer-name (window-buffer w)) w))))
(if (cdr popups)
(or (cdr (assoc (completing-read
"Select window: " (mapcar #'car popups))
popups))
(user-error "Aborted"))
(cdar popups))
(user-error "No popup windows to raise"))))
current-prefix-arg))
(cl-check-type window window)
(unless (+popup-window-p window)
(user-error "Cannot raise a non-popup window"))
(let ((buffer (current-buffer))
(let ((buffer (window-buffer window))
(+popup--inhibit-transient t)
+popup--remember-last)
(+popup/close window 'force)