Function: doom-modeline-def-modeline

doom-modeline-def-modeline is a natively compiled function defined in doom-modeline-core.el.

Signature

(doom-modeline-def-modeline NAME LHS &optional RHS)

Documentation

Define 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 doom-modeline-def-segment.

Example:
  (doom-modeline-def-modeline 'minimal
    '(bar matches " " buffer-info)
    '(media-info major-mode))
  (doom-modeline-set-modeline 'minimal t)

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-def-modeline (name lhs &optional rhs)
  "Define 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
`doom-modeline-def-segment'.

Example:
  (doom-modeline-def-modeline \\='minimal
    \\='(bar matches \" \" buffer-info)
    \\='(media-info major-mode))
  (doom-modeline-set-modeline \\='minimal t)"
  ;; Register the modeline definition for runtime manipulation
  (let ((def (assq name doom-modeline--modelines)))
    (if def
        (setcdr def (list lhs rhs))
      (push (cons name (list lhs rhs)) doom-modeline--modelines)))
  (let ((sym (intern (format "doom-modeline-format--%s" name)))
        (lhs-forms (doom-modeline--prepare-segments lhs))
        (rhs-forms (doom-modeline--prepare-segments rhs)))
    (defalias sym
      (lambda ()
        (list lhs-forms
              (let* ((rhs-str (format-mode-line `("" ,@rhs-forms)))
                     (rhs-width (progn
                                  (add-face-text-property
                                   0 (length rhs-str) 'mode-line t rhs-str)
                                  (doom-modeline-string-pixel-width rhs-str))))
                (propertize
                 " "
                 'face (doom-modeline-face)
                 'display
                 ;; Backport from `mode-line-right-align-edge' in 30
                 (if (and (display-graphic-p)
                          (not (eq mode-line-right-align-edge 'window)))
                             `(space :align-to (- ,mode-line-right-align-edge
                                          (,rhs-width)))
                           `(space :align-to (,(- (window-pixel-width)
                                          (window-scroll-bar-width)
                                          (window-right-divider-width)
                                          (* (or (car (window-margins)) 1)
                                             (frame-char-width))
                                          ;; Manually account for value of
                                          ;; `mode-line-right-align-edge' even
                                          ;; when display is non-graphical
                                          (pcase mode-line-right-align-edge
                                            ('right-margin
                                             (or (cdr (window-margins)) 0))
                                            ('right-fringe
                                             (or (cadr (window-fringes)) 0))
                                            (_ 0))
                                          rhs-width))))))
              rhs-forms))
      (concat "Modeline:\n"
              (format "  %s\n  %s"
                      (prin1-to-string lhs)
                      (prin1-to-string rhs))))))