New macro: save-popups!

This commit is contained in:
Henrik Lissner 2017-09-25 02:58:59 +02:00
parent 5aeb5232ed
commit 6de185409f
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 19 additions and 12 deletions

View file

@ -196,6 +196,24 @@ window parameter."
,@body ,@body
(setq shackle-rules old-shackle-rules))) (setq shackle-rules old-shackle-rules)))
;;;###autoload
(defmacro save-popups! (&rest body)
"Sets aside all popups before executing the original function, usually to
prevent the popup(s) from messing up the UI (or vice versa)."
`(let ((in-popup-p (doom-popup-p))
(popups (doom-popup-windows))
(doom-popup-remember-history t)
(doom-popup-inhibit-autokill t))
(when popups
(mapc #'doom/popup-close popups))
(unwind-protect
(progn ,@body)
(when popups
(let ((origin (selected-window)))
(doom/popup-restore)
(unless in-popup-p
(select-window origin)))))))
;;;###autoload ;;;###autoload
(defun doom/other-popup (count) (defun doom/other-popup (count)
"Cycle through popup windows. Like `other-window', but for popups." "Cycle through popup windows. Like `other-window', but for popups."

View file

@ -237,18 +237,7 @@ and setting `doom-popup-rules' within it. Returns the window."
(defun doom*popups-save (orig-fn &rest args) (defun doom*popups-save (orig-fn &rest args)
"Sets aside all popups before executing the original function, usually to "Sets aside all popups before executing the original function, usually to
prevent the popup(s) from messing up the UI (or vice versa)." prevent the popup(s) from messing up the UI (or vice versa)."
(let ((in-popup-p (doom-popup-p)) (save-popups! (apply orig-fn args)))
(popups (doom-popup-windows))
(doom-popup-remember-history t)
(doom-popup-inhibit-autokill t))
(when popups
(mapc #'doom/popup-close popups))
(unwind-protect (apply orig-fn args)
(when popups
(let ((origin (selected-window)))
(doom/popup-restore)
(unless in-popup-p
(select-window origin)))))))
(defun doom*delete-popup-window (&optional window) (defun doom*delete-popup-window (&optional window)
"Ensure that popups are deleted properly, and killed if they have :autokill "Ensure that popups are deleted properly, and killed if they have :autokill