Decouple :modeline popup rule from modeline API

The :modeline property still takes:

  t => default modeline
  nil => no modeline (the default)

But now also accepts:

  function => uses its return value as the mode-line-format
  anything non-nil => used directly as the mode-line-format

This is to decouple the popup API from the modeline API. You can still
use them compositionally:

  (set-popup-rule "abc" :modeline (lambda () (set-modeline! :project)))
This commit is contained in:
Henrik Lissner 2018-07-29 18:36:12 +02:00
parent cb7e471c90
commit 1205db0f73
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 19 additions and 19 deletions

View file

@ -215,23 +215,24 @@ restoring it if `+popup-buffer-mode' is disabled."
;;;###autoload ;;;###autoload
(defun +popup|set-modeline-on-enable () (defun +popup|set-modeline-on-enable ()
"Don't show modeline in popup windows without a `modeline' window-parameter. "Don't show modeline in popup windows without a `modeline' window-parameter.
Possible values for this parameter are:
+ If one exists and it's a symbol, use `doom-modeline' to grab the format. t show the mode-line as normal
+ If non-nil, show the mode-line as normal. nil hide the modeline entirely (the default)
+ If nil (or omitted), then hide the modeline entirely (the default). a function `mode-line-format' is set to its return value
+ If a function, it takes the current buffer as its argument and must return one
of the above values." Any non-nil value besides the above will be used as the raw value for
`mode-line-format'."
(when (bound-and-true-p +popup-buffer-mode) (when (bound-and-true-p +popup-buffer-mode)
(let ((modeline (+popup-parameter 'modeline))) (let ((modeline (+popup-parameter 'modeline)))
(cond ((eq modeline 't)) (cond ((eq modeline 't))
((or (eq modeline 'nil) ((null modeline)
(null modeline))
;; TODO use `mode-line-format' window parameter instead (emacs 26+) ;; TODO use `mode-line-format' window parameter instead (emacs 26+)
(hide-mode-line-mode +1)) (hide-mode-line-mode +1))
((functionp modeline) ((let ((hide-mode-line-format
(funcall modeline)) (if (functionp modeline)
((symbolp modeline) (funcall modeline)
(when-let* ((hide-mode-line-format (doom-modeline modeline))) modeline)))
(hide-mode-line-mode +1))))))) (hide-mode-line-mode +1)))))))
(put '+popup|set-modeline-on-enable 'permanent-local-hook t) (put '+popup|set-modeline-on-enable 'permanent-local-hook t)

View file

@ -143,11 +143,11 @@ PLIST can be made up of any of the following properties:
(where you were before the popup opened). The popup system does nothing else (where you were before the popup opened). The popup system does nothing else
and ignores the function's return value. and ignores the function's return value.
:modeline BOOL|SYMBOL|FN :modeline BOOL|FN|LIST
Can be t (show the default modeline), a symbol representing the name of a Can be t (show the default modeline), nil (show no modeline), a function that
modeline defined with `def-modeline!', nil (show no modeline) or a function returns a modeline format or a valid value for `mode-line-format' to be used
that returns a modeline format. The function takes no arguments and is run in verbatim. The function takes no arguments and is run in the context of the
the context of the popup buffer. popup buffer.
:autosave BOOL|FN :autosave BOOL|FN
This parameter determines what to do with modified buffers when closing popup This parameter determines what to do with modified buffers when closing popup

View file

@ -140,10 +140,9 @@
(display-buffer a) (display-buffer a)
(expect mode-line-format :to-equal (default-value 'mode-line-format))) (expect mode-line-format :to-equal (default-value 'mode-line-format)))
(it "uses a predefined mode-line if passed a symbol" (it "uses a predefined mode-line if passed a symbol"
(def-modeline! test-popup-modeline ("x") ()) (set-popup-rule! "a" :modeline '("x") :select t)
(set-popup-rule! "a" :modeline 'test-popup-modeline :select t)
(display-buffer a) (display-buffer a)
(expect mode-line-format :to-equal (doom-modeline 'test-popup-modeline))) (expect mode-line-format :to-equal '("x")))
(it "runs the handler if passed a function" (it "runs the handler if passed a function"
(set-popup-rule! "a" :modeline (lambda () (setq mode-line-format '("x"))) :select t) (set-popup-rule! "a" :modeline (lambda () (setq mode-line-format '("x"))) :select t)
(display-buffer a) (display-buffer a)