I have customized the variable sh-indentation with 4, but in one file I would like to use a different value. So I defined a file variable:

# -*- mode: sh; sh-indentation: 2; -*-

But the result is not what I have expected. When I open the file the values are:

sh-indentation is a variable defined in `sh-script.el'.
Its value is 2
Original value was 4
Local in buffer .szi; global value is 4

The file variable seems to set the global value but not the buffer local value.

How can I set the buffer local value with the file variable?

  • It says the global value is still 4 so I think it didn't override it.
    – clemera
    Commented Oct 19, 2015 at 11:55
  • @hatschipuh But sh-mode uses 4 and not 2, if I do a indent-region. Is it a bug in sh-mode, that it ignores the local value?
    – ceving
    Commented Oct 19, 2015 at 12:13
  • I tested it shortly on my side and it seems to accept the local value on my side.
    – clemera
    Commented Oct 19, 2015 at 12:58
  • Your describe-variable result looks fine.. it says "Its value is 2". May be you should provide a full recipe on how one can recreate this issue from an emacs -Q session. Can you see the problem in an emacs -Q session? What is your emacs version? Commented Oct 19, 2015 at 21:42
  • Also what do you get when you do C-h v indent-region-function? Commented Oct 19, 2015 at 21:46

1 Answer 1


Firstly, all file-local and directory-local variables are (necessarily) buffer-local.

Here, Emacs is telling you that sh-indentation is buffer-local (with a value of 2) in that buffer.

You can trust that Emacs isn't lying to you, and that it's not ignoring the local value.

This should suggest to you that maybe the behaviour you're looking for is not entirely dependent on the variable you've set.

The most important variable you've missed is sh-basic-offset, but there's a whole section on indentation in the Commentary of sh-script.el which you should read:

M-x find-library RET sh-script RET

  • @ceving If this answer helps, please update the question title and explanation so that it is useful to other users. Commented Oct 20, 2015 at 21:46

Your Answer

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

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