Function: doom-modeline-update-vcs

doom-modeline-update-vcs is a natively compiled function defined in doom-modeline-segments.el.

Signature

(doom-modeline-update-vcs &rest _)

Documentation

Update VCS state in mode-line.

Source Code

;; Defined in /nix/store/1lcicrdd2r4b8rkc91nnn74ymk1jl6yd-emacs-packages-deps/share/emacs/site-lisp/elpa/doom-modeline-20260928.1632/doom-modeline-segments.el
(defun doom-modeline-update-vcs (&rest _)
  "Update VCS state in mode-line."
  ;; Clear states
  (setq doom-modeline--vcs nil
        doom-modeline--in-git-worktree-p nil)

  (when (and vc-mode buffer-file-name)
    (let* ((backend (vc-backend buffer-file-name))
           (state (vc-state buffer-file-name backend))
           (icon (cond ((memq state '(edited added))
                        (doom-modeline-vcs-icon "nf-dev-git_compare" "🔃" "*" 'doom-modeline-info))
                       ((eq state 'needs-merge)
                        (doom-modeline-vcs-icon "nf-dev-git_merge" "🔀" "?" 'doom-modeline-info))
                       ((eq state 'needs-update)
                        (doom-modeline-vcs-icon "nf-dev-git_pull_request" "⬇" "!" 'doom-modeline-warning))
                       ((memq state '(removed conflict unregistered))
                        (doom-modeline-icon 'octicon "nf-oct-alert" "⚠" "!" :face 'doom-modeline-urgent))
                       (t (doom-modeline-vcs-icon "nf-dev-git_branch" "" "@" 'doom-modeline-info))))
           (str (or (and vc-display-status
                         (functionp doom-modeline-vcs-display-function)
                         (funcall doom-modeline-vcs-display-function))
                    ""))
           (face (or (cdr (assq state doom-modeline-vcs-state-faces-alist))
                     'doom-modeline-vcs-default))
           (text (propertize (if (length> str doom-modeline-vcs-max-length)
                                 (concat
                                  (substring str 0 (- doom-modeline-vcs-max-length 3))
                                  doom-modeline-ellipsis)
                               str)
                             'face face)))
      ;; Check whether in git worktree
      (when (eq backend 'Git)
        (setq doom-modeline--in-git-worktree-p (doom-modeline--in-git-worktree-p)))
      ;; Set VCS state
      (setq doom-modeline--vcs `((icon . ,icon) (text . ,text))))))