core-ui: clean up + refactor modeline functions/macros
This commit is contained in:
parent
ab07120ea6
commit
beb92b0e97
1 changed files with 35 additions and 31 deletions
|
@ -205,24 +205,28 @@ file."
|
|||
;; Modeline
|
||||
;;
|
||||
|
||||
;; TODO Improve docstrings
|
||||
(defmacro def-modeline-segment! (name &rest forms)
|
||||
"Defines a modeline segment function and byte compiles it."
|
||||
"Defines a modeline segment and byte compiles it."
|
||||
(declare (indent defun) (doc-string 2))
|
||||
`(defun ,(intern (format "doom-modeline-segment--%s" name)) ()
|
||||
,@forms))
|
||||
(let ((sym (intern (format "doom-modeline-segment--%s" name))))
|
||||
`(progn
|
||||
(defun ,sym () ,@forms)
|
||||
,(unless (bound-and-true-p byte-compile-current-file)
|
||||
`(let (byte-compile-warnings)
|
||||
(byte-compile ',sym))))))
|
||||
|
||||
(defsubst doom--prepare-modeline-segments (segments)
|
||||
(delq
|
||||
nil
|
||||
(mapcar (lambda (seg)
|
||||
(if (stringp seg)
|
||||
(let (segs)
|
||||
(dolist (seg segments (nreverse segs))
|
||||
(push (if (stringp seg)
|
||||
seg
|
||||
(list (intern (format "doom-modeline-segment--%s" (symbol-name seg))))))
|
||||
segments)))
|
||||
(list (intern (format "doom-modeline-segment--%s" (symbol-name seg)))))
|
||||
segs))))
|
||||
|
||||
(defmacro def-modeline! (name lhs &optional rhs)
|
||||
"Defines a modeline format and byte-compiles it.
|
||||
"Defines a modeline format and byte-compiles it. NAME is a symbol to identify
|
||||
it (used by `doom-modeline' for retrieval). LHS and RHS are lists of symbols of
|
||||
modeline segments defined with `def-modeline-segment!'.
|
||||
|
||||
Example:
|
||||
(def-modeline! minimal
|
||||
|
@ -232,7 +236,6 @@ Example:
|
|||
(let ((sym (intern (format "doom-modeline-format--%s" name)))
|
||||
(lhs-forms (doom--prepare-modeline-segments lhs))
|
||||
(rhs-forms (doom--prepare-modeline-segments rhs)))
|
||||
(prog1
|
||||
`(progn
|
||||
(defun ,sym ()
|
||||
(let ((lhs (list ,@lhs-forms))
|
||||
|
@ -245,10 +248,11 @@ Example:
|
|||
rhs)))
|
||||
,(unless (bound-and-true-p byte-compile-current-file)
|
||||
`(let (byte-compile-warnings)
|
||||
(byte-compile ',sym)))))))
|
||||
(byte-compile ',sym))))))
|
||||
|
||||
(defun doom-modeline (key)
|
||||
"TODO"
|
||||
"Returns a mode-line configuration associated with KEY (a symbol). Throws an
|
||||
error if it doesn't exist."
|
||||
(let ((fn (intern (format "doom-modeline-format--%s" key))))
|
||||
(unless (functionp fn)
|
||||
(error "Modeline format doesn't exist: %s" key))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue