Skip to content

Commit

Permalink
feat: New option to display VC branch name
Browse files Browse the repository at this point in the history
Closes #731.
  • Loading branch information
seagle0128 committed Aug 3, 2024
1 parent 5788d2c commit ef80381
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
21 changes: 16 additions & 5 deletions doom-modeline-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,16 @@ It respects option `doom-modeline-icon'."
:type 'boolean
:group 'doom-modeline)

(defcustom doom-modeline-vcs-max-length 12
"The maximum displayed length of the branch name of version control."
:type 'integer
:group 'doom-modeline)

(defcustom doom-modeline-vcs-display-function #'doom-modeline-vcs-name
"The function to display the branch name."
:type 'function
:group 'doom-modeline)

(defcustom doom-modeline-check-icon t
"Whether display the icon of check segment.
Expand All @@ -499,11 +509,6 @@ It respects option `doom-modeline-icon'."
:type 'integer
:group 'doom-modeline)

(defcustom doom-modeline-vcs-max-length 12
"The maximum displayed length of the branch name of version control."
:type 'integer
:group 'doom-modeline)

(defcustom doom-modeline-workspace-name t
"Whether display the workspace name.
Expand Down Expand Up @@ -1429,6 +1434,12 @@ ARGS is same as `nerd-icons-octicon' and others."
(propertize text 'face `(:inherit (mode-line-inactive
,(get-text-property 0 'face text))))))

(defun doom-modeline-vcs-name ()
"Display the vcs name."
(if vc-mode
(or (cadr (split-string vc-mode ":")) "")
""))

(defun doom-modeline--create-bar-image (face width height)
"Create the bar image.
Expand Down
16 changes: 13 additions & 3 deletions doom-modeline-segments.el
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,10 @@ Uses `nerd-icons-octicon' to fetch the icon."
((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 (if vc-display-status
(substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))
""))
(str (or (and vc-display-status
(functionp #'doom-modeline-vcs-name)
(funcall #'doom-modeline-vcs-name))
""))
(face (cond ((eq state 'needs-update)
'(doom-modeline-warning bold))
((memq state '(removed conflict unregistered))
Expand Down Expand Up @@ -736,6 +737,15 @@ Uses `nerd-icons-octicon' to fetch the icon."
(with-current-buffer buf
(doom-modeline-update-vcs))))))

(doom-modeline-add-variable-watcher
'vc-display-status
(lambda (_sym val op _where)
(when (eq op 'set)
(setq vc-display-status val)
(dolist (buf (buffer-list))
(with-current-buffer buf
(doom-modeline-update-vcs))))))

(doom-modeline-def-segment vcs
"Displays the current branch, colored based on its state."
(when doom-modeline--vcs
Expand Down

0 comments on commit ef80381

Please sign in to comment.