I'm looking for a way to set a variable that isn't buffer local in such a way that it will act like one.

It's possible to do it with file local variables, but I haven't found a way to set a variable in this way from elisp.

I don't want to rely on defining file local variables with comments inside of them.


If you want to set a buffer-local value for a variable, use setq-local.

Depending on what you are actually trying to accomplish, you may also want to look at the help for make-local-variable and make-variable-buffer-local. These functions do not actually set a value, but arrange for a variable to have a buffer-local value when set.

  • Neither make-local-variable nor make-variable-buffer-local "set[s] a buffer-local value for a variable."
    – Drew
    Jan 20 '17 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy