ui/modeline: minor refactor
Add +modeline-segment-active-p predicate function.
This commit is contained in:
parent
b62e40b10b
commit
b3f2a8cd54
2 changed files with 20 additions and 10 deletions
|
@ -2,6 +2,18 @@
|
||||||
|
|
||||||
(defvar +modeline--alist nil)
|
(defvar +modeline--alist nil)
|
||||||
|
|
||||||
|
(defun +modeline--segment-active-p (segment xs)
|
||||||
|
(cond ((null xs) nil)
|
||||||
|
((listp xs)
|
||||||
|
(or (+modeline--segment-active-p segment (car xs))
|
||||||
|
(+modeline--segment-active-p segment (cdr xs))))
|
||||||
|
((eq xs segment))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun +modeline-segment-active-p (segment)
|
||||||
|
(or (+modeline--segment-active-p segment +modeline-format-left)
|
||||||
|
(+modeline--segment-active-p segment +modeline-format-right)))
|
||||||
|
|
||||||
;;;###autodef
|
;;;###autodef
|
||||||
(defun def-modeline-format! (name left &optional right)
|
(defun def-modeline-format! (name left &optional right)
|
||||||
"Define a preset modeline format by name.
|
"Define a preset modeline format by name.
|
||||||
|
@ -48,8 +60,7 @@ keep them left and right aligned respectively."
|
||||||
(varsetterfn (intern (format "+modeline--setvar-%s" name))))
|
(varsetterfn (intern (format "+modeline--setvar-%s" name))))
|
||||||
(append `((fset ',setterfn
|
(append `((fset ',setterfn
|
||||||
(lambda (&rest _)
|
(lambda (&rest _)
|
||||||
(when (or (memq ',name +modeline-format-left)
|
(when (+modeline-segment-active-p ',name)
|
||||||
(memq ',name +modeline-format-right))
|
|
||||||
(setq-local ,realvar ,(macroexp-progn body)))))
|
(setq-local ,realvar ,(macroexp-progn body)))))
|
||||||
(byte-compile ',setterfn))
|
(byte-compile ',setterfn))
|
||||||
(mapcar (lambda (hook) `(add-hook ',hook #',setterfn))
|
(mapcar (lambda (hook) `(add-hook ',hook #',setterfn))
|
||||||
|
@ -61,7 +72,7 @@ keep them left and right aligned respectively."
|
||||||
(with-current-buffer where
|
(with-current-buffer where
|
||||||
(set sym val)
|
(set sym val)
|
||||||
(,setterfn)))))
|
(,setterfn)))))
|
||||||
,@(mapcar (lambda (var) `(add-variable-watcher ',var #',varsetterfn))
|
,@(mapcan (lambda (var) `((add-variable-watcher ',var #',varsetterfn)))
|
||||||
on-set)))))
|
on-set)))))
|
||||||
(setq init `(quote (:eval ,(macroexp-progn body))))
|
(setq init `(quote (:eval ,(macroexp-progn body))))
|
||||||
nil))
|
nil))
|
||||||
|
|
|
@ -316,8 +316,7 @@ buffers.")
|
||||||
(let ((face 'mode-line-inactive)
|
(let ((face 'mode-line-inactive)
|
||||||
(active (active))
|
(active (active))
|
||||||
(all-the-icons-default-adjust -0.1))
|
(all-the-icons-default-adjust -0.1))
|
||||||
(concat " "
|
(concat (cond ((memq state '(edited added))
|
||||||
(cond ((memq state '(edited added))
|
|
||||||
(if active (setq face 'doom-modeline-info))
|
(if active (setq face 'doom-modeline-info))
|
||||||
(all-the-icons-octicon
|
(all-the-icons-octicon
|
||||||
"git-compare"
|
"git-compare"
|
||||||
|
@ -340,8 +339,7 @@ buffers.")
|
||||||
:v-adjust -0.05)))
|
:v-adjust -0.05)))
|
||||||
" "
|
" "
|
||||||
(propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
|
(propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
|
||||||
'face (if active face))
|
'face (if active face)))))))
|
||||||
" ")))))
|
|
||||||
|
|
||||||
(def-modeline-segment! +modeline-encoding
|
(def-modeline-segment! +modeline-encoding
|
||||||
:on-hooks (after-revert-hook after-save-hook find-file-hook)
|
:on-hooks (after-revert-hook after-save-hook find-file-hook)
|
||||||
|
@ -495,9 +493,10 @@ segment.")
|
||||||
+modeline-buffer-state
|
+modeline-buffer-state
|
||||||
+modeline-buffer-id
|
+modeline-buffer-id
|
||||||
" %2l:%c %p ")
|
" %2l:%c %p ")
|
||||||
'(+modeline-encoding
|
`(+modeline-encoding
|
||||||
+modeline-major-mode
|
+modeline-major-mode " "
|
||||||
+modeline-vcs))
|
mode-line-misc-info
|
||||||
|
(+modeline-vcs (" " +modeline-vcs " "))))
|
||||||
|
|
||||||
(def-modeline-format! :minimal
|
(def-modeline-format! :minimal
|
||||||
'(+modeline-matches " "
|
'(+modeline-matches " "
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue