feature/popup: split +popup-p into two functions

Better to be explicit about what we want, especially when using one or
the other with no arguments.
This commit is contained in:
Henrik Lissner 2018-01-07 21:52:54 -05:00
parent f9ab0cf767
commit 7ca2e1593e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 29 additions and 22 deletions

View file

@ -39,7 +39,7 @@
;; a term buffer to run it in, but where it spawns it is the problem... ;; a term buffer to run it in, but where it spawns it is the problem...
(defun +popup*eshell-undedicate-popup (orig-fn &rest args) (defun +popup*eshell-undedicate-popup (orig-fn &rest args)
"Force spawned term buffer to share with the eshell popup (if necessary)." "Force spawned term buffer to share with the eshell popup (if necessary)."
(when (+popup-p) (when (+popup-window-p)
(set-window-dedicated-p nil nil) (set-window-dedicated-p nil nil)
(add-transient-hook! #'eshell-query-kill-processes :after (add-transient-hook! #'eshell-query-kill-processes :after
(set-window-dedicated-p nil t))) (set-window-dedicated-p nil t)))

View file

@ -102,7 +102,8 @@ This will ensure all popups have a modeline /by default/, but allows you to over
+ ~+popup/raise~ + ~+popup/raise~
** Library ** Library
+ Functions + Functions
+ ~+popup-p WINDOW~ + ~+popup-window-p WINDOW~
+ ~+popup-buffer-p BUFFER~
+ ~+popup-buffer BUFFER &optional ALIST~ + ~+popup-buffer BUFFER &optional ALIST~
+ ~+popup-parameter PARAMETER &optional WINDOW~ + ~+popup-parameter PARAMETER &optional WINDOW~
+ ~+popup-parameter-fn PARAMETER &optional WINDOW~ + ~+popup-parameter-fn PARAMETER &optional WINDOW~

View file

@ -97,18 +97,24 @@ and enables `+popup-buffer-mode'."
;; ;;
;;;###autoload ;;;###autoload
(defun +popup-p (&optional target) (defun +popup-buffer-p (&optional buffer)
"Return t if TARGET is a popup window or buffer. If TARGET is nil, use the "Return t if BUFFER is a popup buffer. Defaults to the current buffer."
current buffer." (unless buffer
(unless target (setq buffer (current-buffer)))
(setq target (current-buffer))) (cl-assert (bufferp buffer) t)
(cond ((windowp target) (and (buffer-live-p buffer)
(+popup-p (window-buffer target))) (buffer-local-value '+popup-buffer-mode buffer)
((bufferp target) buffer))
(buffer-local-value '+popup-buffer-mode target))
(t ;;;###autoload
(error "Expected a window/buffer, got %s (%s)" (defun +popup-window-p (&optional window)
(type-of target) target)))) "Return t if WINDOW is a popup window. Defaults to the current window."
(unless window
(setq window (selected-window)))
(cl-assert (windowp window) t)
(and (window-live-p window)
(window-parameter window 'popup)
window))
;;;###autoload ;;;###autoload
(defun +popup-buffer (buffer &optional alist) (defun +popup-buffer (buffer &optional alist)
@ -142,7 +148,7 @@ with ARGS to get its return value."
;;;###autoload ;;;###autoload
(defun +popup-windows () (defun +popup-windows ()
"Returns a list of all popup windows." "Returns a list of all popup windows."
(cl-remove-if-not #'+popup-p (window-list))) (cl-remove-if-not #'+popup-window-p (window-list)))
;;;###autoload ;;;###autoload
(defun +popup-shrink-to-fit (&optional window) (defun +popup-shrink-to-fit (&optional window)
@ -166,7 +172,7 @@ Uses `shrink-window-if-larger-than-buffer'."
:global t :global t
:keymap +popup-mode-map :keymap +popup-mode-map
(cond (+popup-mode (cond (+popup-mode
(add-hook 'doom-unreal-buffer-functions #'+popup-p) (add-hook 'doom-unreal-buffer-functions #'+popup-buffer-p)
(add-hook 'doom-escape-hook #'+popup|close-on-escape t) (add-hook 'doom-escape-hook #'+popup|close-on-escape t)
(add-hook 'doom-cleanup-hook #'+popup|cleanup-rules) (add-hook 'doom-cleanup-hook #'+popup|cleanup-rules)
(setq +popup--old-display-buffer-alist display-buffer-alist (setq +popup--old-display-buffer-alist display-buffer-alist
@ -174,7 +180,7 @@ Uses `shrink-window-if-larger-than-buffer'."
(dolist (prop +popup-window-parameters) (dolist (prop +popup-window-parameters)
(push (cons prop 'writable) window-persistent-parameters))) (push (cons prop 'writable) window-persistent-parameters)))
(t (t
(remove-hook 'doom-unreal-buffer-functions #'+popup-p) (remove-hook 'doom-unreal-buffer-functions #'+popup-buffer-p)
(remove-hook 'doom-escape-hook #'+popup|close-on-escape) (remove-hook 'doom-escape-hook #'+popup|close-on-escape)
(remove-hook 'doom-cleanup-hook #'+popup|cleanup-rules) (remove-hook 'doom-cleanup-hook #'+popup|cleanup-rules)
(setq display-buffer-alist +popup--old-display-buffer-alist) (setq display-buffer-alist +popup--old-display-buffer-alist)
@ -234,7 +240,7 @@ disabled."
"If called inside a popup, try to close that popup window (see "If called inside a popup, try to close that popup window (see
`+popup/close'). If called outside, try to close all popup windows (see `+popup/close'). If called outside, try to close all popup windows (see
`+popup/close-all')." `+popup/close-all')."
(if (+popup-p) (if (+popup-window-p)
(+popup/close) (+popup/close)
(+popup/close-all))) (+popup/close-all)))
@ -264,7 +270,7 @@ disabled."
(window (selected-window))) (window (selected-window)))
(unless popups (unless popups
(user-error "No popups are open")) (user-error "No popups are open"))
(select-window (if (+popup-p) (select-window (if (+popup-window-p)
(or (car-safe (cdr (memq window popups))) (or (car-safe (cdr (memq window popups)))
(car (delq window popups)) (car (delq window popups))
(car popups)) (car popups))
@ -281,7 +287,7 @@ This will do nothing if the popup's `quit' window parameter is either nil or
current-prefix-arg)) current-prefix-arg))
(unless window (unless window
(setq window (selected-window))) (setq window (selected-window)))
(when (and (+popup-p window) (when (and (+popup-window-p window)
(or force-p (or force-p
(memq (+popup-parameter-fn 'quit window window) (memq (+popup-parameter-fn 'quit window window)
'(t current)))) '(t current))))
@ -335,7 +341,7 @@ the message buffer in a popup window."
(defun +popup/raise () (defun +popup/raise ()
"Raise the current popup window into a regular window." "Raise the current popup window into a regular window."
(interactive) (interactive)
(unless (+popup-p) (unless (+popup-window-p)
(user-error "Cannot raise a non-popup window")) (user-error "Cannot raise a non-popup window"))
(let ((window (selected-window)) (let ((window (selected-window))
(buffer (current-buffer)) (buffer (current-buffer))
@ -360,7 +366,7 @@ with the :popup setting."
(defmacro save-popups! (&rest body) (defmacro save-popups! (&rest body)
"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 (+popup-p)) `(let* ((in-popup-p (+popup-buffer-p))
(popups (+popup-windows)) (popups (+popup-windows))
(+popup--inhibit-transient t) (+popup--inhibit-transient t)
+popup--last) +popup--last)