6

Q: how can I abbreviate the version control information in the mode line?

Buffers visiting a file under version control display branch information in the mode line as VCtype-branch. That's fine, but my mode line is already quite cluttered, so I'd like to abbreviate that information if possible. I can always use short branch names, but I'm wondering if I can at least shorten the VCtype information (eg, Git-mybranch => G-mybranch). How would I do this?

PS My understanding (which could be wrong) is that diminish would not be relevant in this situation.

1
  • 3
    It's not worthy of an answer, but if you know exactly what you want and don't want in your modeline, writing your own mode-line-format might be a great option for you. Jul 9, 2015 at 14:23

1 Answer 1

8

Here is a piece of advice that shortens Git to G, while leaving mode line strings for other version control systems unchanged:

(defun my-shorten-vc-mode-line (string)
  (cond
   ((string-prefix-p "Git" string)
    (concat "G" (substring string 3)))
   (t
    string)))

(advice-add 'vc-git-mode-line-string :filter-return 'my-shorten-vc-mode-line)

It uses the new advice facility introduced in Emacs 24.4.


On earlier Emacs versions, you need to use defadvice to define an around advice that modifies ad-return-value:

(defadvice vc-git-mode-line-string (around shorten compile activate)
  (let ((string ad-do-it))
    (when (string-prefix-p "Git" string)
      (setq ad-return-value (concat "G" (substring string 3))))))
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.