Function: doom-modeline-add-segment
doom-modeline-add-segment is a natively compiled function defined in
doom-modeline-core.el.
Signature
(doom-modeline-add-segment SEGMENT ANCHOR &optional POSITION MODELINE)
Documentation
Add SEGMENT to modeline(s) relative to ANCHOR segment.
SEGMENT is the segment name to add (a symbol).
ANCHOR is the segment name to anchor to (a symbol).
POSITION can be :before or :after (default: :after).
MODELINE can be a modeline name (symbol) to add to a specific modeline,
or nil/'all to add to all modelines (respecting
doom-modeline-excluded-modelines).
Modelines listed in doom-modeline-excluded-modelines are not modified
when adding to all modelines.
Source Code
;; Defined in /nix/store/1lcicrdd2r4b8rkc91nnn74ymk1jl6yd-emacs-packages-deps/share/emacs/site-lisp/elpa/doom-modeline-20260928.1632/doom-modeline-core.el
(defun doom-modeline-add-segment (segment anchor &optional position modeline)
"Add SEGMENT to modeline(s) relative to ANCHOR segment.
SEGMENT is the segment name to add (a symbol).
ANCHOR is the segment name to anchor to (a symbol).
POSITION can be :before or :after (default: :after).
MODELINE can be a modeline name (symbol) to add to a specific modeline,
or nil/'all to add to all modelines (respecting
`doom-modeline-excluded-modelines').
Modelines listed in `doom-modeline-excluded-modelines' are not modified
when adding to all modelines."
(let ((modelines (if (or (null modeline) (eq modeline 'all))
doom-modeline--modelines
(list (assq modeline doom-modeline--modelines)))))
(dolist (modeline-def modelines)
(when modeline-def
(pcase-let ((`(,name . (,lhs ,rhs)) modeline-def))
(unless (memq name doom-modeline-excluded-modelines)
(let ((new-lhs lhs)
(new-rhs rhs))
;; Try to add to LHS
(when (memq anchor lhs)
(setq new-lhs (doom-modeline--insert-segment-in-list lhs anchor segment
(or position :after))))
;; Try to add to RHS
(when (memq anchor rhs)
(setq new-rhs (doom-modeline--insert-segment-in-list rhs anchor segment
(or position :after))))
;; Only redefine if at least one list was modified
(when (or (not (eq new-lhs lhs))
(not (eq new-rhs rhs)))
(doom-modeline-def-modeline name new-lhs new-rhs)))))))))