diff --git a/core/autoload/buffers.el b/core/autoload/buffers.el index b9a54fd37..a052c2dd6 100644 --- a/core/autoload/buffers.el +++ b/core/autoload/buffers.el @@ -268,7 +268,7 @@ regex PATTERN. Returns the number of killed buffers." If PROJECT-P (universal argument), kill only buffers that belong to the current project." (interactive "P") - (doom/popup-close-all t) + (doom/popup-kill-all) (let ((buffers (if project-p (doom-project-buffer-list) (doom-buffer-list)))) (mapc #'doom-kill-buffer-and-windows buffers) (unless (doom-real-buffer-p) diff --git a/core/autoload/editor.el b/core/autoload/editor.el index 050e0a8d9..98a88d1e2 100644 --- a/core/autoload/editor.el +++ b/core/autoload/editor.el @@ -268,7 +268,7 @@ consistent throughout a selected region, depending on `indent-tab-mode'." is closed. If a region is active, copy it to the scratch buffer." (interactive) (doom-popup-buffer (doom--create-scratch-buffer) - '(:size 12 :autokill t :fixed t) t)) + '(:size 12 :autokill t :static t) t)) ;;;###autoload (defun doom/open-project-scratch-buffer () @@ -277,4 +277,4 @@ popup window. Scratch buffers are stored in `doom-scratch-files-dir'. If a region is active, copy it to the scratch buffer." (interactive) (doom-popup-buffer (doom--create-scratch-buffer t) - '(:size 12 :autokill t :fixed t) t)) + '(:size 12 :autokill t :static t) t)) diff --git a/core/autoload/popups.el b/core/autoload/popups.el index d54ab5cf3..e56083289 100644 --- a/core/autoload/popups.el +++ b/core/autoload/popups.el @@ -8,11 +8,9 @@ omitted." (when-let (target (or target (selected-window))) (cond ((bufferp target) - (and (buffer-local-value 'doom-popup-mode target) - (not (plist-get (buffer-local-value 'doom-popup-rules target) :fixed)))) + (buffer-local-value 'doom-popup-mode target)) ((windowp target) - (and (window-parameter target 'popup) - (not (doom-popup-property :fixed target))))))) + (window-parameter target 'popup))))) ;;;###autoload (defun doom-popup-buffer (buffer &optional plist extend-p) @@ -51,9 +49,13 @@ possible rules." (doom-popup-buffer (find-file-noselect file t) plist extend-p)) ;;;###autoload -(defun doom-popup-windows () +(defun doom-popup-windows (&optional filter-static-p) "Get a list of open pop up windows." - (cl-remove-if-not #'doom-popup-p doom-popup-windows)) + (cl-loop for window in doom-popup-windows + if (and (doom-popup-p window) + (not (and filter-static-p + (doom-popup-property :static window)))) + collect window)) ;;;###autoload (defun doom/popup-restore () @@ -92,7 +94,7 @@ Returns t if popups were restored, nil otherwise." (if doom-popup-other-window (select-window doom-popup-other-window) (other-window 1))) - (if (doom-popup-windows) + (if (doom-popup-windows t) (let ((doom-popup-inhibit-autokill t)) (doom/popup-close-all t)) (doom/popup-restore))) @@ -108,21 +110,34 @@ property." ;;;###autoload (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) - (when-let (popups (doom-popup-windows)) + "Closes most open popups. + +Does not close popups that are :static or don't have an :autoclose property (see +`shackle-rules'). + +If FORCE-P is non-nil (or this function is called interactively), ignore popups' +:autoclose property. This command will never close :static popups." + (interactive + (list (called-interactively-p 'interactive))) + (when-let (popups (cl-loop for window in (doom-popup-windows) + unless (doom-popup-property :static window) + collect window)) (let (success doom-popup-remember-history) (setq doom-popup-history (delq nil (mapcar #'doom--popup-data popups))) - (dolist (window popups) - (when (or force-p - (called-interactively-p 'interactive) - (doom-popup-property :autoclose window)) + (dolist (window popups success) + (when (or force-p (doom-popup-property :autoclose window)) (delete-window window) - (setq success t))) - success))) + (setq success t)))))) + +;;;###autoload +(defun doom/popup-kill-all () + "Like `doom/popup-close-all', but kill *all* popups, including :static ones, +without leaving any trace behind (muahaha)." + (interactive) + (when-let (popups (doom-popup-windows)) + (let (doom-popup-remember-history) + (setq doom-popup-history nil) + (mapc #'delete-window popups)))) ;;;###autoload (defun doom/popup-close-maybe () @@ -260,9 +275,8 @@ one of the following: 'left 'right 'above 'below" (defun doom/popup-move-right () "See `doom-popup-move'." (interactive) (doom-popup-move 'right)) (defun doom--popup-data (window) - (unless (doom-popup-property :fixed window) - (when-let (buffer (window-buffer window)) - `(,(buffer-name buffer) - :file ,(buffer-file-name buffer) - :rules ,(window-parameter window 'popup) - :size ,(doom-popup-size window))))) + (when-let (buffer (window-buffer window)) + `(,(buffer-name buffer) + :file ,(buffer-file-name buffer) + :rules ,(window-parameter window 'popup) + :size ,(doom-popup-size window)))) diff --git a/core/core-popups.el b/core/core-popups.el index 37773f38e..fdee96632 100644 --- a/core/core-popups.el +++ b/core/core-popups.el @@ -35,7 +35,7 @@ "The shackle rule that caused this buffer to be recognized as a popup.") (defvar doom-popup-window-parameters - '(:noesc :modeline :autokill :autoclose :fixed) + '(:noesc :modeline :autokill :autoclose :autofit :static) "A list of window parameters that are set (and cleared) when `doom-popup-mode is enabled/disabled.'") @@ -50,22 +50,25 @@ property.") Several custom properties have been added that are not part of shackle, but are recognized by DOOM's popup system. They are: -:noesc If non-nil, pressing ESC *inside* the popup will close it. - Used by `doom/popup-close-maybe'. +:noesc If non-nil, pressing ESC *inside* the 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 (in `doom-popup-mode'). +: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 + (in `doom-popup-mode'). -:autokill If non-nil, the popup's buffer will be killed when the - popup is closed. Used by `doom*delete-popup-window'. - NOTE `doom/popup-restore' can't restore non-file popups - that have an :autokill property. +:autokill If non-nil, the popup's buffer will be killed when the popup is + closed. Used by `doom*delete-popup-window'. NOTE + `doom/popup-restore' can't restore non-file popups that have an + :autokill property. -:autoclose If non-nil, close popup if ESC is pressed from outside - the popup window. +:autoclose If non-nil, close popup if ESC is pressed from outside the popup + window. -:fixed If non-nil, don't treat this window like a popup. This makes it +:autofit If non-nil, resize the popup to fit its content. Uses the value of + the :size property as the maximum height/width. + +:static If non-nil, don't treat this window like a popup. This makes it impervious to being automatically closed or tracked in popup history. Excellent for permanent sidebars." (if (cl-every #'listp (mapcar #'doom-unquote rules)) @@ -86,7 +89,7 @@ recognized by DOOM's popup system. They are: '(("^\\*ftp " :noselect t :autokill t :noesc t) ;; doom ("^\\*doom:" :regexp t :size 0.35 :noesc t :select t :modeline t) - ("^\\*doom " :regexp t :noselect t :autokill t :autoclose t) + ("^\\*doom " :regexp t :noselect t :autokill t :autoclose t :autofit t) ;; built-in (emacs) ("*ert*" :same t :modeline t) ("*info*" :size 0.5 :select t :autokill t) @@ -102,7 +105,7 @@ recognized by DOOM's popup system. They are: (profiler-report-mode :size 0.3 :regexp t :autokill t :modeline minimal) (tabulated-list-mode :noesc t) (special-mode :noselect t :autokill t :autoclose t) - ("^\\*" :regexp t :noselect t :autokill t) + ("^\\*" :regexp t :noselect t :autokill t :autofit t) ("^ \\*" :regexp t :size 12 :noselect t :autokill t :autoclose t))) :config @@ -231,7 +234,11 @@ and setting `doom-popup-rules' within it. Returns the window." (with-selected-window window (unless (eq plist t) (setq-local doom-popup-rules plist)) - (doom-popup-mode +1)) + (doom-popup-mode +1) + (when (and (plist-get plist :autofit) + (not (string-empty-p (buffer-string)))) + (let ((max-size (plist-get plist :size))) + (fit-window-to-buffer window max-size nil max-size)))) window)) (defun doom*popups-save (orig-fn &rest args) @@ -502,7 +509,7 @@ the command buffer." ;; ;; By handing neotree over to shackle, which is better integrated into the ;; rest of my config (and persp-mode), this is no longer a problem. - (set! :popup " *NeoTree*" :align neo-window-position :size neo-window-width :fixed t) + (set! :popup " *NeoTree*" :align neo-window-position :size neo-window-width :static t) (defun +evil-neotree-display-fn (buf _alist) "Hand neotree off to shackle."