Skip to main content
ertius.org

magit tab width

I've been writing a bunch of Go code lately, and one annoying thing I've found is that magit will show the diffs in the code with the massive 8-space default tab width. Turns out it's easy to make it not do that, though:

(setq magit-diff-adjust-tab-width t)

This tells magit to render tabs in diffs of fileX by looking for an existing buffer with fileX open and copying that tab-width. I've set my Go tab-width to 4 to stop it creeping right so fast, so it was a bit annoying to have the diff render differently.

It's a very emacs-y solution - it's not perfect (it only works for buffers that are open), but it's fast (magit can just riffle through the buffer list and do a hash lookup) and works in practice (I'm mostly only examining diffs for files I'm also already editing in Emacs).