Some of Python files I work on have the following file-local variables:

# Local Variables:
# mode: python
# python-indent-offset: 4
# tab-width: 4
# indent-tabs-mode: t
# coding: utf-8
# End:

When viewing diffs in magit it displays tabs using tab-width 8, rather than the file local variable.

Is there a way to make magit honour file-local tab-width variable?

  • 1
    You want to know how to get magit to automatically read the tab-width value from the file-local variables in the underlying file, but I don't know that this makes much sense. A git diff can include pieces from multiple files, but tab-width can only be set for the entire buffer, not individual pieces of it. Can you clarify what you want to do exactly?
    – kini
    Jan 26, 2017 at 0:58

1 Answer 1


As you say, it appears that you are just seeing the tabs from the git output being expanded using the default Emacs value for tab-width (8), so you can set it to your desired value in any magit buffer and see it how you like.

If you want to do this for every magit status buffer, you could do something like this:

(defun my-magit-status-mode-hook ()
  (setq tab-width 4))
(add-hook 'magit-status-mode-hook 'my-magit-status-mode-hook)

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.