popups: :fixed => :static, major changes to popup API

+ New command: doom/popup-kill-all
+ Update references to :fixed (now named :static)
+ Simplified doom-popup-p; moved :static filtering to
  doom-popup-windows.
+ New :autofit popup property, which resizes the popup to fit its
  content, if possible.
+ doom-popup-windows now takes one boolean argument: whether to ignore
  static popups or not.
This commit is contained in:
Henrik Lissner 2017-09-26 19:41:11 +02:00
parent e1d5e48d46
commit cf7b27f4eb
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
4 changed files with 66 additions and 45 deletions

View file

@ -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 If PROJECT-P (universal argument), kill only buffers that belong to the current
project." project."
(interactive "P") (interactive "P")
(doom/popup-close-all t) (doom/popup-kill-all)
(let ((buffers (if project-p (doom-project-buffer-list) (doom-buffer-list)))) (let ((buffers (if project-p (doom-project-buffer-list) (doom-buffer-list))))
(mapc #'doom-kill-buffer-and-windows buffers) (mapc #'doom-kill-buffer-and-windows buffers)
(unless (doom-real-buffer-p) (unless (doom-real-buffer-p)

View file

@ -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." is closed. If a region is active, copy it to the scratch buffer."
(interactive) (interactive)
(doom-popup-buffer (doom--create-scratch-buffer) (doom-popup-buffer (doom--create-scratch-buffer)
'(:size 12 :autokill t :fixed t) t)) '(:size 12 :autokill t :static t) t))
;;;###autoload ;;;###autoload
(defun doom/open-project-scratch-buffer () (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." region is active, copy it to the scratch buffer."
(interactive) (interactive)
(doom-popup-buffer (doom--create-scratch-buffer t) (doom-popup-buffer (doom--create-scratch-buffer t)
'(:size 12 :autokill t :fixed t) t)) '(:size 12 :autokill t :static t) t))

View file

@ -8,11 +8,9 @@
omitted." omitted."
(when-let (target (or target (selected-window))) (when-let (target (or target (selected-window)))
(cond ((bufferp target) (cond ((bufferp target)
(and (buffer-local-value 'doom-popup-mode target) (buffer-local-value 'doom-popup-mode target))
(not (plist-get (buffer-local-value 'doom-popup-rules target) :fixed))))
((windowp target) ((windowp target)
(and (window-parameter target 'popup) (window-parameter target 'popup)))))
(not (doom-popup-property :fixed target)))))))
;;;###autoload ;;;###autoload
(defun doom-popup-buffer (buffer &optional plist extend-p) (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)) (doom-popup-buffer (find-file-noselect file t) plist extend-p))
;;;###autoload ;;;###autoload
(defun doom-popup-windows () (defun doom-popup-windows (&optional filter-static-p)
"Get a list of open pop up windows." "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 ;;;###autoload
(defun doom/popup-restore () (defun doom/popup-restore ()
@ -92,7 +94,7 @@ Returns t if popups were restored, nil otherwise."
(if doom-popup-other-window (if doom-popup-other-window
(select-window doom-popup-other-window) (select-window doom-popup-other-window)
(other-window 1))) (other-window 1)))
(if (doom-popup-windows) (if (doom-popup-windows t)
(let ((doom-popup-inhibit-autokill t)) (let ((doom-popup-inhibit-autokill t))
(doom/popup-close-all t)) (doom/popup-close-all t))
(doom/popup-restore))) (doom/popup-restore)))
@ -108,21 +110,34 @@ property."
;;;###autoload ;;;###autoload
(defun doom/popup-close-all (&optional force-p) (defun doom/popup-close-all (&optional force-p)
"Closes all open popups. If FORCE-P is non-nil, or this function is called "Closes most open popups.
interactively, it will close all popups without question. Otherwise, it will
only close popups that have an :autoclose property in their rule (see Does not close popups that are :static or don't have an :autoclose property (see
`shackle-rules')." `shackle-rules').
(interactive)
(when-let (popups (doom-popup-windows)) 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) (let (success doom-popup-remember-history)
(setq doom-popup-history (delq nil (mapcar #'doom--popup-data popups))) (setq doom-popup-history (delq nil (mapcar #'doom--popup-data popups)))
(dolist (window popups) (dolist (window popups success)
(when (or force-p (when (or force-p (doom-popup-property :autoclose window))
(called-interactively-p 'interactive)
(doom-popup-property :autoclose window))
(delete-window window) (delete-window window)
(setq success t))) (setq success t))))))
success)))
;;;###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 ;;;###autoload
(defun doom/popup-close-maybe () (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-move-right () "See `doom-popup-move'." (interactive) (doom-popup-move 'right))
(defun doom--popup-data (window) (defun doom--popup-data (window)
(unless (doom-popup-property :fixed window) (when-let (buffer (window-buffer window))
(when-let (buffer (window-buffer window)) `(,(buffer-name buffer)
`(,(buffer-name buffer) :file ,(buffer-file-name buffer)
:file ,(buffer-file-name buffer) :rules ,(window-parameter window 'popup)
:rules ,(window-parameter window 'popup) :size ,(doom-popup-size window))))
:size ,(doom-popup-size window)))))

View file

@ -35,7 +35,7 @@
"The shackle rule that caused this buffer to be recognized as a popup.") "The shackle rule that caused this buffer to be recognized as a popup.")
(defvar doom-popup-window-parameters (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 "A list of window parameters that are set (and cleared) when `doom-popup-mode
is enabled/disabled.'") is enabled/disabled.'")
@ -50,22 +50,25 @@ property.")
Several custom properties have been added that are not part of shackle, but are Several custom properties have been added that are not part of shackle, but are
recognized by DOOM's popup system. They are: recognized by DOOM's popup system. They are:
:noesc If non-nil, pressing ESC *inside* the popup will close it. :noesc If non-nil, pressing ESC *inside* the popup will close it. Used by
Used by `doom/popup-close-maybe'. `doom/popup-close-maybe'.
:modeline By default, mode-lines are hidden in popups unless this :modeline By default, mode-lines are hidden in popups unless this is non-nil. If
is non-nil. If it is a symbol, it'll use `doom-modeline' it is a symbol, it'll use `doom-modeline' to fetch a modeline config
to fetch a modeline config (in `doom-popup-mode'). (in `doom-popup-mode').
:autokill If non-nil, the popup's buffer will be killed when the :autokill If non-nil, the popup's buffer will be killed when the popup is
popup is closed. Used by `doom*delete-popup-window'. closed. Used by `doom*delete-popup-window'. NOTE
NOTE `doom/popup-restore' can't restore non-file popups `doom/popup-restore' can't restore non-file popups that have an
that have an :autokill property. :autokill property.
:autoclose If non-nil, close popup if ESC is pressed from outside :autoclose If non-nil, close popup if ESC is pressed from outside the popup
the popup window. 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 impervious to being automatically closed or tracked in popup
history. Excellent for permanent sidebars." history. Excellent for permanent sidebars."
(if (cl-every #'listp (mapcar #'doom-unquote rules)) (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) '(("^\\*ftp " :noselect t :autokill t :noesc t)
;; doom ;; doom
("^\\*doom:" :regexp t :size 0.35 :noesc t :select t :modeline t) ("^\\*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) ;; built-in (emacs)
("*ert*" :same t :modeline t) ("*ert*" :same t :modeline t)
("*info*" :size 0.5 :select t :autokill 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) (profiler-report-mode :size 0.3 :regexp t :autokill t :modeline minimal)
(tabulated-list-mode :noesc t) (tabulated-list-mode :noesc t)
(special-mode :noselect t :autokill t :autoclose 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))) ("^ \\*" :regexp t :size 12 :noselect t :autokill t :autoclose t)))
:config :config
@ -231,7 +234,11 @@ and setting `doom-popup-rules' within it. Returns the window."
(with-selected-window window (with-selected-window window
(unless (eq plist t) (unless (eq plist t)
(setq-local doom-popup-rules plist)) (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)) window))
(defun doom*popups-save (orig-fn &rest args) (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 ;; 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. ;; 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) (defun +evil-neotree-display-fn (buf _alist)
"Hand neotree off to shackle." "Hand neotree off to shackle."