feature/popup: make parameters support functions
Now, the transient, quit, select and modeline parameters now accept a function FN. See `+popup-window-parameters` for details. (transient . (FN popup-buffer)) (quit . (FN popup-window)) (select . (FN popup-window)) (modeline . (FN popup-buffer))
This commit is contained in:
parent
60fdbf8643
commit
25a2973c52
2 changed files with 56 additions and 30 deletions
|
@ -53,8 +53,8 @@ and enables `+popup-buffer-mode'."
|
||||||
+ Either kills the buffer or sets a transient timer, if the window has a
|
+ Either kills the buffer or sets a transient timer, if the window has a
|
||||||
`transient' window parameter (see `+popup-window-parameters').
|
`transient' window parameter (see `+popup-window-parameters').
|
||||||
+ And finally deletes the window!"
|
+ And finally deletes the window!"
|
||||||
(let ((ttl (+popup-parameter 'transient window))
|
(let ((buffer (window-buffer window))
|
||||||
(buffer (window-buffer window)))
|
ttl)
|
||||||
(let ((ignore-window-parameters t))
|
(let ((ignore-window-parameters t))
|
||||||
(delete-window window))
|
(delete-window window))
|
||||||
(unless (window-live-p window)
|
(unless (window-live-p window)
|
||||||
|
@ -63,14 +63,17 @@ and enables `+popup-buffer-mode'."
|
||||||
;; t = default
|
;; t = default
|
||||||
;; integer = ttl
|
;; integer = ttl
|
||||||
;; nil = no timer
|
;; nil = no timer
|
||||||
(when (and ttl (not +popup--inhibit-transient))
|
(unless +popup--inhibit-transient
|
||||||
|
(setq ttl (+popup-parameter-fn 'transient window buffer))
|
||||||
|
(when ttl
|
||||||
(when (eq ttl t)
|
(when (eq ttl t)
|
||||||
(setq ttl +popup-ttl))
|
(setq ttl +popup-ttl))
|
||||||
(cl-assert (integerp ttl) t)
|
(cl-assert (integerp ttl) t)
|
||||||
(if (= ttl 0)
|
(if (= ttl 0)
|
||||||
(+popup--kill-buffer buffer 0)
|
(+popup--kill-buffer buffer 0)
|
||||||
(setq +popup--timer
|
(setq +popup--timer
|
||||||
(run-at-time ttl nil #'+popup--kill-buffer buffer ttl))))))))
|
(run-at-time ttl nil #'+popup--kill-buffer
|
||||||
|
buffer ttl)))))))))
|
||||||
|
|
||||||
(defun +popup--normalize-alist (alist)
|
(defun +popup--normalize-alist (alist)
|
||||||
"Merge `+popup-default-alist' and `+popup-default-parameters' with ALIST."
|
"Merge `+popup-default-alist' and `+popup-default-parameters' with ALIST."
|
||||||
|
@ -110,10 +113,10 @@ current buffer."
|
||||||
(new-window (or (display-buffer-reuse-window buffer alist)
|
(new-window (or (display-buffer-reuse-window buffer alist)
|
||||||
(display-buffer-in-side-window buffer alist))))
|
(display-buffer-in-side-window buffer alist))))
|
||||||
(+popup--init new-window)
|
(+popup--init new-window)
|
||||||
(select-window
|
(let ((select (+popup-parameter 'select new-window)))
|
||||||
(if (+popup-parameter 'select new-window)
|
(if (functionp select)
|
||||||
new-window
|
(funcall select new-window old-window)
|
||||||
old-window))
|
(select-window (if select new-window old-window))))
|
||||||
new-window))
|
new-window))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -121,6 +124,15 @@ current buffer."
|
||||||
"Fetch the window parameter of WINDOW"
|
"Fetch the window parameter of WINDOW"
|
||||||
(window-parameter (or window (selected-window)) parameter))
|
(window-parameter (or window (selected-window)) parameter))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +popup-parameter-fn (parameter &optional window &rest args)
|
||||||
|
"Fetch the window PARAMETER (symbol) of WINDOW. If it is a function, run it
|
||||||
|
with ARGS to get its return value."
|
||||||
|
(let ((val (+popup-parameter parameter window)))
|
||||||
|
(if (functionp val)
|
||||||
|
(apply val args)
|
||||||
|
val)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +popup-windows ()
|
(defun +popup-windows ()
|
||||||
"Returns a list of all popup windows."
|
"Returns a list of all popup windows."
|
||||||
|
@ -178,15 +190,17 @@ disabled."
|
||||||
|
|
||||||
+ If one exists and it's a symbol, use `doom-modeline' to grab the format.
|
+ If one exists and it's a symbol, use `doom-modeline' to grab the format.
|
||||||
+ If non-nil, show the mode-line as normal.
|
+ If non-nil, show the mode-line as normal.
|
||||||
+ If nil (or omitted), then hide the modeline entirely (the default)."
|
+ If nil (or omitted), then hide the modeline entirely (the default).
|
||||||
|
+ If a function, it takes the current buffer as its argument and must return one
|
||||||
|
of the above values."
|
||||||
(if +popup-buffer-mode
|
(if +popup-buffer-mode
|
||||||
(let ((modeline (+popup-parameter 'modeline)))
|
(let ((modeline (+popup-parameter-fn 'modeline nil (current-buffer))))
|
||||||
(cond ((or (eq modeline 'nil)
|
(cond ((eq modeline 't))
|
||||||
|
((or (eq modeline 'nil)
|
||||||
(not modeline))
|
(not modeline))
|
||||||
(doom-hide-modeline-mode +1))
|
(doom-hide-modeline-mode +1))
|
||||||
((and (symbolp modeline)
|
((symbolp modeline)
|
||||||
(not (eq modeline 't)))
|
(setq doom--modeline-format (doom-modeline modeline))
|
||||||
(setq-local doom--modeline-format (doom-modeline modeline))
|
|
||||||
(when doom--modeline-format
|
(when doom--modeline-format
|
||||||
(doom-hide-modeline-mode +1)))))
|
(doom-hide-modeline-mode +1)))))
|
||||||
(when doom-hide-modeline-mode
|
(when doom-hide-modeline-mode
|
||||||
|
@ -237,7 +251,7 @@ This will do nothing if the popup's `quit' window parameter is either nil or
|
||||||
(setq window (selected-window)))
|
(setq window (selected-window)))
|
||||||
(when (and (+popup-p window)
|
(when (and (+popup-p window)
|
||||||
(or force-p
|
(or force-p
|
||||||
(memq (+popup-parameter 'quit window)
|
(memq (+popup-parameter-fn 'quit window window)
|
||||||
'(t current))))
|
'(t current))))
|
||||||
(when +popup--remember-last
|
(when +popup--remember-last
|
||||||
(+popup--remember (list window)))
|
(+popup--remember (list window)))
|
||||||
|
@ -254,7 +268,7 @@ This window parameter is ignored if FORCE-P is non-nil."
|
||||||
(let (targets +popup--remember-last)
|
(let (targets +popup--remember-last)
|
||||||
(dolist (window (+popup-windows))
|
(dolist (window (+popup-windows))
|
||||||
(when (or force-p
|
(when (or force-p
|
||||||
(memq (+popup-parameter 'quit window)
|
(memq (+popup-parameter-fn 'quit window window)
|
||||||
'(t other)))
|
'(t other)))
|
||||||
(push window targets)))
|
(push window targets)))
|
||||||
(when targets
|
(when targets
|
||||||
|
|
|
@ -6,16 +6,20 @@
|
||||||
Modifying this has no effect, unless done before feature/popup loads.
|
Modifying this has no effect, unless done before feature/popup loads.
|
||||||
|
|
||||||
(transient . CDR)
|
(transient . CDR)
|
||||||
CDR can be t, an integer or nil. It represents the number of seconds before
|
CDR can be t, an integer, nil or a function that returns one of these. It
|
||||||
the buffer belonging to a closed popup window is killed.
|
represents the number of seconds before the buffer belonging to a closed popup
|
||||||
|
window is killed.
|
||||||
|
|
||||||
If t, CDR will default to `+popup-ttl'.
|
If t, CDR will default to `+popup-ttl'.
|
||||||
If 0, the buffer is immediately killed.
|
If 0, the buffer is immediately killed.
|
||||||
If nil, the buffer won't be killed.
|
If nil, the buffer won't be killed.
|
||||||
|
If a function, it must return one of the other possible values above. It takes
|
||||||
|
the popup buffer as its sole argument.
|
||||||
|
|
||||||
(quit . CDR)
|
(quit . CDR)
|
||||||
CDR can be t, 'other, 'current or nil. This determines the behavior of the
|
CDR can be t, 'other, 'current, nil, or a function that returns one of these.
|
||||||
ESC/C-g keys in or outside of popup windows.
|
This determines the behavior of the ESC/C-g keys in or outside of popup
|
||||||
|
windows.
|
||||||
|
|
||||||
If t, close the popup if ESC/C-g is pressed inside or outside of popups.
|
If t, close the popup if ESC/C-g is pressed inside or outside of popups.
|
||||||
If 'other, close this popup if ESC/C-g is pressed outside of any popup. This
|
If 'other, close this popup if ESC/C-g is pressed outside of any popup. This
|
||||||
|
@ -24,14 +28,22 @@ Modifying this has no effect, unless done before feature/popup loads.
|
||||||
If 'current, close the current popup if ESC/C-g is pressed from inside of the
|
If 'current, close the current popup if ESC/C-g is pressed from inside of the
|
||||||
popup.
|
popup.
|
||||||
If nil, pressing ESC/C-g will never close this buffer.
|
If nil, pressing ESC/C-g will never close this buffer.
|
||||||
|
If a function, it is checked each time ESC/C-g is pressed to determine the
|
||||||
|
fate of the popup window. This function takes one argument: the popup
|
||||||
|
window and must return one of the other possible values.
|
||||||
|
|
||||||
(select . BOOl)
|
(select . CDR)
|
||||||
CDR is a boolean that determines whether to focus the popup window after it
|
CDR can be a boolean or function. The boolean determines whether to focus the
|
||||||
opens.
|
popup window after it opens (non-nil) or focus the origin window (nil).
|
||||||
|
|
||||||
|
If a function, it takes two arguments: the popup window and the source window
|
||||||
|
(where you were before the popup was opened). It does nothing else, and
|
||||||
|
ignores its return value.
|
||||||
|
|
||||||
(modeline . CDR)
|
(modeline . CDR)
|
||||||
CDR can be t (show the default modeline), a symbol representing the name of a
|
CDR can be t (show the default modeline), a symbol representing the name of a
|
||||||
modeline defined with `def-modeline!', or nil (show no modeline).
|
modeline defined with `def-modeline!', nil (show no modeline) or a function
|
||||||
|
that returns one of these. The function takes one argument: the popup buffer.
|
||||||
|
|
||||||
(popup . t)
|
(popup . t)
|
||||||
This is for internal use, do not change this. It simply marks a window as a
|
This is for internal use, do not change this. It simply marks a window as a
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue