23 votes
Accepted

What does `setq-local` do, and when should I use it?

Most of your assumptions are close. I'll mention a few later. But, first the main question. The form setq-local is merely a convenience, it is the same as doing make-local-variable followed by setq....
  • 552
22 votes
Accepted

Mark a local variable safe for any value

Set the safe-local-variable property to a function that validates the value. For example, fill-column has a safe-local-variable property set to integerp. Use (lambda (x) t) as the validation function ...
15 votes
Accepted

How to modify-face for a specific buffer?

As noted by @phils in the comment below, the Emacs manual suggests not modifying the face-remapping-alist directly due to possible unintended side effects: . . .to avoid trampling on remappings ...
  • 17.9k
15 votes
Accepted

Make a buffer-local variable become global again

The comment from @Malabarba explains your problem. kill-local-variable does get rid of the local variable binding. But since in your case the variable is automatically local in any buffer, when you ...
  • 70.9k
9 votes

Set buffer-local variable in buffer other than the current one?

is there a way to do this without changing the current buffer No, but buffer-local-value is a Generalized Variable, so you can use setf to take care of the buffer switching for you: (setf (buffer-...
  • 8,853
8 votes
Accepted

org-mode: have flycheck resolve relative config while editing code blocks

Here's how you can tell org-mode to set buffer-file-name to an appropriate value for code buffers: (defadvice org-edit-src-code (around set-buffer-file-name activate compile) (let ((file-name (...
  • 14.3k
7 votes
Accepted

whitespace-mode ignores whitespace-line-column

First off, since you didn't mention it: Using the same version of Emacs (24.4.1), the behavior you describe can be reproduced in emacs -Q. Secondly, what you are doing should work (AFAICT). It seems ...
  • 14.3k
7 votes
Accepted

Use `.dir-locals.el' to append to `before-save-hook' as a buffer local variable

(add-hook 'before-save-hook #'clang-format-buffer nil t) This is the right way to add a function locally to a hook. This will set before-save-hook as a buffer local variable ignoring everything ...
  • 22.5k
7 votes
Accepted

How do you disable the buffer end/beginning warnings in the minibuffer?

This is very similar to the question Is there a way to disable the “buffer is read-only” warning?, so a very similar answer seems appropriate. You can disable these messages by setting command-error-...
  • 9,002
7 votes
Accepted

How can I get buffer-local environment variables via .dir-locals?

Both the buffer-local and the global variable are initially pointing to the same cons cell / list. If setenv pushes a new value to the front of the list, that would only be reflected in the local ...
  • 44.2k
7 votes

Buffer-local after-save-hook?

This is standard functionality built into add-hook: add-hook is a compiled Lisp function in ‘subr.el’. (add-hook HOOK FUNCTION &optional APPEND LOCAL) Add to the value of HOOK the ...
  • 44.2k
6 votes
Accepted

Why isn't face-remapping-alist permanent-local by default?

permanent-local is fundamentally a way to distinguish whether the variable's buffer-local value is really specific to this buffer or is specific to the mode currently in use in this buffer. Sadly, in ...
  • 25.5k
6 votes
Accepted

The default value of buffer-local variable not set until first `setq`

I, as a package author, bind case-fold-search to nil in the outer let, and I want to use the default value (it might or might not be set by the user) in the with-temp-buffer, In this case I would ...
  • 8,853
5 votes
Accepted

Set buffer-local variable in buffer other than the current one?

What you're doing is correct. is there a way to do this without changing the current buffer, i.e. can I explicitly specify the buffer whose value I want to change? While there is nothing built in, ...
  • 44.2k
5 votes
Accepted

Set a buffer/file local variable in elisp like a file local variable

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-...
  • 19.5k
4 votes
Accepted

What is the difference between setq-mode-local and setq-local

The immediate difference is that setq-mode-local will also affect already existing buffers, whereas adding a setq-local to the mode hook will only affect future buffers. Of course, there are other ...
  • 25.5k
4 votes
Accepted

Is it possible to associate minor modes with windows rather than buffers?

Not as such. Even 'global' minor modes are generally just buffer-local minor modes which are enabled or disabled for multiple buffers en masse. However there's nothing to stop you writing a global ...
  • 44.2k
4 votes
Accepted

How to get an insert-text-button 'action property accessing a dynamically-bound buffer-local variable

You can add not only action but any other attributes to a text-button, that can be referred later with button-get function. So saving the (reference to the) current buffer, together with action, seems ...
  • 446
4 votes
Accepted

How can I get the effect of buffer-local symbol plist property values?

I am certain that the answer is no, and that variables are the only kind of buffer-local bindings provided by elisp. (I'm sure one of the elisp language maintainers will correct me if I'm wrong about ...
  • 44.2k
3 votes
Accepted

Making a variable window-local

Save your data as a window-parameter. It will force you to use :eval inside your mode-line, but that's not something to be afraid of. If you want to discuss changes to the "core" Emacs features (...
  • 25.5k
3 votes

How to customize major mode initialization with local variables?

If you want to set a buffer-local value for a given mode, do so after the mode has been established. You do that by putting the value-assignment on the mode hook. For example, if you want to set ...
  • 70.9k
3 votes
Accepted

Buffer-local hook shadowing default value for subsequently loaded libraries

kill-buffer-hook is not automatically buffer-local. That it is, it does not automatically become buffer-local whenever its value is set. AFAICT, auto-revert-mode does not make kill-buffer-hook be ...
  • 70.9k
3 votes

How do buffer local bindings go into effect?

Not exactly sure what the question is, but this might help. It's hard to add to what is said in the doc section you cite - I think that section describes the situation well. A buffer is in a (major) ...
  • 70.9k
3 votes
Accepted

How to get an value from a buffer local variable

Sounds like my-package-insert turns on a major mode. Doing that calls kill-all-local-variables. You can give the variable a non-nil permanent-local property to protect it. But we would need more ...
  • 70.9k
3 votes
Accepted

How to set a variable on a single buffer?

eval: is a special form in the Local Variables section that evaluates the given Elisp-form. That is not what you want. The actual syntax for setting file local variables is: MAYBE_COMMENT ...
  • 30.7k
2 votes

How do you disable the buffer end/beginning warnings in the minibuffer?

You want to look at the functions that use line-move-visual / line-move-1 / line-move -- within the library simple.el. The error message occurs because the optional argument of noerror is not being ...
  • 17.9k
2 votes

How to find out if variable is buffer-local?

When you see Automatically becomes buffer-local when set you can rely on it meaning just what it says: whenever that variable is set (e.g., using setq), it becomes buffer-local if it was not already ...
  • 70.9k
2 votes
Accepted

buffer-local advice

The doc you show isn't for advice-add but for add-function (which is used internally by advice-add but offers other functionality, such as working on variables (which can be buffer-local) rather than ...
  • 25.5k
2 votes
Accepted

Have shell inherit buffer local process-environment

That's actually a bit tricky on account of how shell is written, so the following is quite implementation-specific and could break if things change upstream; however, give this a whirl: (defadvice ...
  • 44.2k
2 votes
Accepted

How can I change external program to open org URLs for one org file only

Error is caused by this quote: # -*- browse-url-browser-function: 'browse-url-chromium -*- ___________________________________| It shouldn't be there. Open video path in MPV on *nix OS's Add this ...

Only top scored, non community-wiki answers of a minimum length are eligible