It seems like some variables that I set at one place in my init file could potentially be modified by other packages that are loaded later.

One place where this has come up for me is the variable yas-snippet-dirs which I set after I load yasnippet, but which is then modified when I load elpy (elpy appends its own snippet directory to the list).

If I want to ensure that all that is contained in yas-snippet-dirs is "~/.emacs.d/snippets", I can simply make sure that I set

(setq yas-snippet-dirs '("~/.emacs.d/snippets"))

after I load elpy.

However, I am wondering if there is a general way to tell packages not to modify a variable. Thank you!

  • 1
    Sadly, or thankfully (depending upon how you see things), the answer is "no". I would just modify the source of whatever makes the changes that I don't like, but most people prefer to use a major or minor mode hook to set it back to what it was beforehand.
    – lawlist
    Jan 7, 2016 at 20:07
  • It appears that elpy provides snippets for python mode, which are stored in a separate elpy snippet directory that gets added to yas-snippet-dirs. This seems like an appropriate thing to do, and shouldn't break your snippets for other modes. It also looks like you can disable this feature via the elpy module system. What problem is it causing?
    – Tyler
    Jan 7, 2016 at 20:38
  • @Tyler, yes, this is exactly what elpy does AFAIK. It doesn't break my snippets unless I have a snippet with the exact same key. The problem is, that while I find some of the elpy snippets very useful, others I don't like, and since I have it configured so that snippets expand on SPC (to fix other issues), I find myself constantly expanding elpy snippets accidentally.
    – elethan
    Jan 7, 2016 at 20:43
  • If you like some of the elpy snippets, then removing the elpy snippets from yas-snippet-dirs makes a new problem. It doesn't look like there's a good solution, either you take all the snippets, or you get none. I think this is an issue to take up with the elpy developer.
    – Tyler
    Jan 7, 2016 at 21:01
  • 1
    @elethan You can customize the elpy-modules variable and remove elpy-module-yasnippet from it. Jan 7, 2016 at 21:59

1 Answer 1


No, there is no "general way to tell packages not to modify a variable".

Or put differently: The way to tell packages not to modify a variable is for it to be a user option.

And if I understand right, yas-snippet-dirs is a user option. If so:

  1. Packages should, in general, not change its value, once it has been set. The general rule is that user options are for users to customize.

  2. If they do so then presumably it is because they must or they have some other very good reason.

For #1: Contact the package maintainer if you think this is a bug.

For #2: Contact the package maintainer if this is not documented extremely prominently. Case #2 should be a rare exception. It really needs good justification, which should be well documented.

Your Answer

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

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