diff --git a/modules/ui/modeline/autoload/settings.el b/modules/ui/modeline/autoload/settings.el index 26aa59a77..f4891edba 100644 --- a/modules/ui/modeline/autoload/settings.el +++ b/modules/ui/modeline/autoload/settings.el @@ -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)) diff --git a/modules/ui/modeline/config.el b/modules/ui/modeline/config.el index 9b53dfeac..90b6dd29a 100644 --- a/modules/ui/modeline/config.el +++ b/modules/ui/modeline/config.el @@ -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 " "