From 9be87b323515f9c3c92344601a4abc2703ee311a Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Wed, 1 Mar 2017 21:38:26 -0500 Subject: [PATCH] core-popups: add :autoclose property + apply to message & help buffers --- core/autoload/popups.el | 15 ++++++++++++--- core/core-popups.el | 36 ++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/core/autoload/popups.el b/core/autoload/popups.el index b1c55738c..37d160867 100644 --- a/core/autoload/popups.el +++ b/core/autoload/popups.el @@ -75,14 +75,23 @@ real files, they will be restored. Special buffers or buffers with non-nil (delete-window window)))) ;;;###autoload -(defun doom/popup-close-all () - "Closes all open popups." +(defun doom/popup-close-all (&optional force-p) + "Closes all open popups. If FORCE-P is non-nil, or this function is called +interactively, it will close all popups without question. Otherwise, it will +only close popups that have an :autoclose property in their rule (see +`shackle-rules')." (interactive) (let ((orig-win (selected-window))) (when-let (popups (doom-popup-windows)) (setq doom-popup-history (mapcar 'doom--popup-data popups)) (let (doom-popup-remember-history) - (mapc 'delete-window popups))))) + (dolist (window popups) + (let ((rules (window-parameter window 'popup))) + (when (or force-p + (called-interactively-p 'interactive) + (and (plist-member rules :autoclose) + (plist-get rules :autoclose))) + (delete-window window)))))))) ;;;###autoload (defun doom/popup-close-maybe () diff --git a/core/core-popups.el b/core/core-popups.el index 2a975826f..764bc30a7 100644 --- a/core/core-popups.el +++ b/core/core-popups.el @@ -27,7 +27,7 @@ (defvar-local doom-popup-rules nil "The shackle rule that caused this buffer to be recognized as a popup.") -(defvar doom-popup-window-parameters '(:noesc :modeline :autokill) +(defvar doom-popup-window-parameters '(:noesc :modeline :autokill :autoclose) "A list of window parameters that are set (and cleared) when `doom-popup-mode is enabled/disabled.'") @@ -46,15 +46,18 @@ is enabled/disabled.'") :init (setq shackle-default-alignment 'below ;;; Baseline popup-window rules - ;; :noesc, :modeline and :autokill are custom settings and are not part - ;; of shackle: - ;; :noesc determines if pressing ESC in this popup will close it. - ;; Used by `doom/popup-close-maybe'. - ;; :modeline By default, mode-lines are hidden in popups unless this is - ;; non-nil. If it is a symbol, it'll use `doom-modeline' to - ;; fetch a modeline config. Set in `doom-popup-mode'. - ;; :autokill If non-nil, the buffer in these popups will be killed when - ;; their popup is closed. Used in `doom*delete-popup-window' + ;; Several custom properties have been added that are not part of + ;; shackle and are used by doom's popup system. They are: + ;; + ;; :noesc Determines if pressing ESC *inside* the popup should + ;; close it. Used by `doom/popup-close-maybe'. + ;; :modeline By default, mode-lines are hidden in popups unless this + ;; is non-nil. If it is a symbol, it'll use `doom-modeline' + ;; to fetch a modeline config. Set in `doom-popup-mode'. + ;; :autokill If non-nil, the buffer in these popups will be killed + ;; when their popup is closed. Used by + ;; `doom*delete-popup-window' + ;; :autoclose If non-nil, close popup if ESC is pressed from any buffer. shackle-rules '(("^ ?\\*doom:.+\\*$" :size 40 :modeline t :regexp t) ("^ ?\\*doom .+\\*$" :size 30 :noselect t :regexp t) @@ -64,8 +67,8 @@ is enabled/disabled.'") ("*Pp Eval Output*" :size 16 :noselect t :autokill t) ("*Apropos*" :size 0.3) ("*Backtrace*" :size 25 :noselect t) - ("*Help*" :size 16) - ("*Messages*" :size 10) + ("*Help*" :size 16 :autoclose t) + ("*Messages*" :size 10 :noselect t :autoclose t) ("*Warnings*" :size 10 :noselect t :autokill t) ("*command-log*" :size 28 :noselect t :align right) ("*Shell Command Output*" :size 20 :noselect t :autokill t) @@ -226,6 +229,15 @@ properties." (define-key map [remap evil-window-vsplit] 'ignore) (define-key map [remap evil-force-normal-state] 'doom/popup-close-maybe)) + (defun doom*popup-close-all-maybe () + "Close popups with an :autoclose property when pressing ESC from normal +mode in any evil-mode buffer." + (unless (or (minibuffer-window-active-p (minibuffer-window)) + (and (bound-and-true-p evil-mode) + (evil-ex-hl-active-p 'evil-ex-search))) + (doom/popup-close-all))) + (advice-add 'evil-force-normal-state :after 'doom*popup-close-all-maybe) + ;; Make evil-mode cooperate with popups (advice-add 'evil-command-window :override 'doom*popup-evil-command-window) (advice-add 'evil-command-window-execute :override 'doom*popup-evil-command-window-execute)