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 '17 at 0:58

That's not possible I am afraid. Git itself replaces a tab with eight spaces and it does not appear that this is configurable (but it cannot hurt to double-check).

When git diff uses a pager, then it apparently leaves the tabs alone and you can then use git config core.pager 'less -x1,5'. But since Magit does not use a pager when getting output from Git, this won't work here.

  • 1
    When I set tab-width variable in *magit-diff* buffer it does change how tabs are displayed. So, this is not git replacing tabs with 8 spaces, rather emacs. – Maxim Egorushkin Jan 19 '17 at 10:48
  • I'll have to look into that. – tarsius Jan 26 '17 at 9:03

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, privacy policy and cookie policy

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