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.

Dan
  • 32,584
  • 6
  • 98
  • 168
  • 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. – Jordon Biondo Jul 09 '15 at 14:23

1 Answers1

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))))))
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
legoscia
  • 6,012
  • 29
  • 54