ui/modeline: minor refactor

Add +modeline-segment-active-p predicate function.
This commit is contained in:
Henrik Lissner 2018-07-31 18:40:11 +02:00
parent b62e40b10b
commit b3f2a8cd54
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 20 additions and 10 deletions

View file

@ -2,6 +2,18 @@
(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
(defun def-modeline-format! (name left &optional right)
"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))))
(append `((fset ',setterfn
(lambda (&rest _)
(when (or (memq ',name +modeline-format-left)
(memq ',name +modeline-format-right))
(when (+modeline-segment-active-p ',name)
(setq-local ,realvar ,(macroexp-progn body)))))
(byte-compile ',setterfn))
(mapcar (lambda (hook) `(add-hook ',hook #',setterfn))
@ -61,7 +72,7 @@ keep them left and right aligned respectively."
(with-current-buffer where
(set sym val)
(,setterfn)))))
,@(mapcar (lambda (var) `(add-variable-watcher ',var #',varsetterfn))
,@(mapcan (lambda (var) `((add-variable-watcher ',var #',varsetterfn)))
on-set)))))
(setq init `(quote (:eval ,(macroexp-progn body))))
nil))

View file

@ -316,8 +316,7 @@ buffers.")
(let ((face 'mode-line-inactive)
(active (active))
(all-the-icons-default-adjust -0.1))
(concat " "
(cond ((memq state '(edited added))
(concat (cond ((memq state '(edited added))
(if active (setq face 'doom-modeline-info))
(all-the-icons-octicon
"git-compare"
@ -340,8 +339,7 @@ buffers.")
:v-adjust -0.05)))
" "
(propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
'face (if active face))
" ")))))
'face (if active face)))))))
(def-modeline-segment! +modeline-encoding
:on-hooks (after-revert-hook after-save-hook find-file-hook)
@ -495,9 +493,10 @@ segment.")
+modeline-buffer-state
+modeline-buffer-id
" %2l:%c %p ")
'(+modeline-encoding
+modeline-major-mode
+modeline-vcs))
`(+modeline-encoding
+modeline-major-mode " "
mode-line-misc-info
(+modeline-vcs (" " +modeline-vcs " "))))
(def-modeline-format! :minimal
'(+modeline-matches " "