Polish & move new modeline into :ui modeline
Removes modeline library out of core-ui and contains them in :ui doom-modeline and :ui modeline. :ui modeline will eventually replace :ui doom-modeline, but is still considered experimental. This update provides makes it much more stable and closer to being feature complete.
This commit is contained in:
parent
db8ed4aac6
commit
088480047c
10 changed files with 1429 additions and 1272 deletions
|
@ -116,94 +116,6 @@ Also see `doom-exit-buffer-hook'.")
|
|||
(defun define-fringe-bitmap (&rest _)))
|
||||
|
||||
|
||||
;;
|
||||
;; Modeline library
|
||||
;;
|
||||
|
||||
(defvar doom--modeline-fn-alist ())
|
||||
(defvar doom--modeline-var-alist ())
|
||||
|
||||
(defmacro def-modeline-segment! (name &rest body)
|
||||
"Defines a modeline segment and byte compiles it."
|
||||
(declare (indent defun) (doc-string 2))
|
||||
(let ((sym (intern (format "doom-modeline-segment--%s" name)))
|
||||
(docstring (if (stringp (car body))
|
||||
(pop body)
|
||||
(format "%s modeline segment" name))))
|
||||
(cond ((and (symbolp (car body))
|
||||
(not (cdr body)))
|
||||
(add-to-list 'doom--modeline-var-alist (cons name (car body)))
|
||||
`(add-to-list 'doom--modeline-var-alist (cons ',name ',(car body))))
|
||||
(t
|
||||
(add-to-list 'doom--modeline-fn-alist (cons name sym))
|
||||
`(progn
|
||||
(fset ',sym (lambda () ,docstring ,@body))
|
||||
(add-to-list 'doom--modeline-fn-alist (cons ',name ',sym))
|
||||
,(unless (bound-and-true-p byte-compile-current-file)
|
||||
`(let (byte-compile-warnings)
|
||||
(byte-compile #',sym))))))))
|
||||
|
||||
(defun doom--prepare-modeline-segments (segments)
|
||||
(let (forms it)
|
||||
(dolist (seg segments)
|
||||
(cond ((stringp seg)
|
||||
(push seg forms))
|
||||
((symbolp seg)
|
||||
(cond ((setq it (cdr (assq seg doom--modeline-fn-alist)))
|
||||
(push (list :eval (list it)) forms))
|
||||
((setq it (cdr (assq seg doom--modeline-var-alist)))
|
||||
(push it forms))
|
||||
((error "%s is not a defined segment" seg))))
|
||||
((error "%s is not a valid segment" seg))))
|
||||
(nreverse forms)))
|
||||
|
||||
(defun def-modeline! (name lhs &optional rhs)
|
||||
"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
|
||||
'(bar matches \" \" buffer-info)
|
||||
'(media-info major-mode))
|
||||
(doom-set-modeline 'minimal t)"
|
||||
(let ((sym (intern (format "doom-modeline-format--%s" name)))
|
||||
(lhs-forms (doom--prepare-modeline-segments lhs))
|
||||
(rhs-forms (doom--prepare-modeline-segments rhs)))
|
||||
(defalias sym
|
||||
(lambda ()
|
||||
(let ((rhs-str (format-mode-line rhs-forms)))
|
||||
(list lhs-forms
|
||||
(propertize
|
||||
" " 'display
|
||||
`((space :align-to (- (+ right right-fringe right-margin)
|
||||
,(+ 1 (string-width rhs-str))))))
|
||||
rhs-str)))
|
||||
(concat "Modeline:\n"
|
||||
(format " %s\n %s"
|
||||
(prin1-to-string lhs)
|
||||
(prin1-to-string rhs))))
|
||||
(unless (bound-and-true-p byte-compile-current-file)
|
||||
(let (byte-compile-warnings)
|
||||
(byte-compile sym)))))
|
||||
|
||||
(defun doom-modeline (key)
|
||||
"Returns a mode-line configuration associated with KEY (a symbol). Throws an
|
||||
error if it doesn't exist."
|
||||
(let ((fn (intern-soft (format "doom-modeline-format--%s" key))))
|
||||
(when (functionp fn)
|
||||
`(:eval (,fn)))))
|
||||
|
||||
(defun doom-set-modeline (key &optional default)
|
||||
"Set the modeline format. Does nothing if the modeline KEY doesn't exist. If
|
||||
DEFAULT is non-nil, set the default mode-line for all buffers."
|
||||
(when-let* ((modeline (doom-modeline key)))
|
||||
(setf (if default
|
||||
(default-value 'mode-line-format)
|
||||
(buffer-local-value 'mode-line-format (current-buffer)))
|
||||
(list "%e" modeline))))
|
||||
|
||||
|
||||
;;
|
||||
;; Plugins
|
||||
;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue