From c5b5a4d2d24b67239993c398e5631e54908fe815 Mon Sep 17 00:00:00 2001 From: Vincent Zhang Date: Sat, 6 Apr 2019 15:12:11 +0800 Subject: [PATCH] Fix #154: shorten branch name of vcs segment. --- README.md | 3 +++ doom-modeline-core.el | 3 +++ doom-modeline-segments.el | 13 +++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fdc5460..37d181c 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,9 @@ Strongly recommend to use ;; If non-nil, only display one number for checker information if applicable. (setq doom-modeline-checker-simple-format t) +;; The maximum displayed length of the branch name of version control. +(setq doom-modeline-vcs-max-length 12) + ;; Whether display perspective name or not. Non-nil to display in mode-line. (setq doom-modeline-persp-name t) diff --git a/doom-modeline-core.el b/doom-modeline-core.el index b61120c..b272c00 100644 --- a/doom-modeline-core.el +++ b/doom-modeline-core.el @@ -105,6 +105,9 @@ The icons may not be showed correctly in terminal.") (defvar doom-modeline-checker-simple-format t "If non-nil, only display one number for checker information if applicable.") +(defvar doom-modeline-vcs-max-length 12 + "The maximum displayed length of the branch name of version control.") + (defvar doom-modeline-persp-name t "Whether display perspective name or not. Non-nil to display in mode-line.") diff --git a/doom-modeline-segments.el b/doom-modeline-segments.el index 6a96e17..0c6b886 100644 --- a/doom-modeline-segments.el +++ b/doom-modeline-segments.el @@ -545,7 +545,7 @@ Uses `all-the-icons-octicon' to fetch the icon." (defvar-local doom-modeline--vcs-icon nil) (defun doom-modeline-update-vcs-icon (&rest _) - "Update icon of vsc state in mode-line." + "Update icon of vcs state in mode-line." (setq doom-modeline--vcs-icon (when (and vc-mode buffer-file-name) (let* ((backend (vc-backend buffer-file-name)) @@ -583,12 +583,17 @@ Uses `all-the-icons-octicon' to fetch the icon." (defvar-local doom-modeline--vcs-text nil) (defun doom-modeline-update-vcs-text (&rest _) - "Update text of vsc state in mode-line." + "Update text of vcs state in mode-line." (setq doom-modeline--vcs-text (when (and vc-mode buffer-file-name) (let* ((backend (vc-backend buffer-file-name)) - (state (vc-state buffer-file-name backend))) - (propertize (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)) + (state (vc-state buffer-file-name backend)) + (str (substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2)))) + (propertize (if (> (length str) doom-modeline-vcs-max-length) + (concat + (substring str 0 (- doom-modeline-vcs-max-length 3)) + "...") + str) 'face (cond ((eq state 'needs-update) 'doom-modeline-warning) ((memq state '(removed conflict unregistered))