1

It works when using setq-default in place of setq or when customizing through C-h v. C-h v reports that it is set in 'C source code'.

I was thinking it might be affected by my c-default-style, but my setq appears after it:

(setq c-default-style                   
              '((c-mode . "stroustrup") 
                (other . "stroustrup")))

...

(setq indent-tabs-mode nil)

I have made sure I am not using smart tabs or any other tab settings.

My understanding of setq:
1. Creates and sets the local variable if not present.
2. Sets local variable if present.
3. Does not affect default.

My understanding of setq-default:
1. If local variable is present only the default is affected.
2. If no local variable present default and local are set.

With this understanding in mind and assuming the local variable takes precedence, why would changing the default value have an effect, but not changing the local value?

1 Answer 1

1

You ask, "assuming the local variable takes precedence, why would changing the default value have an effect, but not changing the local value?"

If you use setq in your init file, and if the variable is buffer-local in the buffer that is current when your init file is evaluated, then only the value in that buffer gets set.

Probably the problem is that the buffer you expect to be current is not current when that expression is evaluated.

C-h v indent-tabs-mode tells you this:

Automatically becomes buffer-local when set.

That means that it is buffer-local, always. And that means that if you want to set the default value for all buffers then you need to use setq-default. After setting that default value, you can use setq in any given buffer to set its value to something else.

6
  • Thank you, Drew. This raises some more questions to be answered before I can mark as the solution. As for the init and what is the current buffer is there a way to output or view this info? The init is not called on opening each new buffer? Does this mean I should be using setq-default in my init general? Regarding your buffer-local always statement, is the need for setq-default related to the fact that setq is not necessary being called in that buffer?
    – mcp
    Commented Apr 28, 2020 at 18:31
  • In general, you won't know what buffer is current at any point in your init file, unless you have set the current buffer there explicitly. No, your init file is not evaluated (loaded) anew each time you use make a given buffer current. It is loaded once, when you start Emacs. For variables that are automatically buffer-local, yes, if you want to set their default value then use setq-default. For such a variable, setq only sets the value for the current bufffer.
    – Drew
    Commented Apr 28, 2020 at 18:50
  • Is this a typo "...anew each time you use make a given buffer current."?
    – mcp
    Commented Apr 28, 2020 at 19:07
  • I'm focusing on "...you use make a given buffer current".
    – mcp
    Commented Apr 29, 2020 at 19:56
  • Yes, sorry, that's a typo - "use" doesn't belong there. (I can't edit the comment any more.)
    – Drew
    Commented Apr 29, 2020 at 20:51

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.