0

I'm getting back in to emacs after a few years away, and my old init.el is throwing up warnings like this:

⛔ Warning (comp): init.el:114:7: Warning: assignment to free variable ‘c-basic-offset’ ⛔ Warning (comp): init.el:115:7: Warning: assignment to free variable ‘c-default-style’ ⛔ Warning (comp): init.el:173:7: Warning: assignment to free variable ‘helm-ff-search-library-in-sexp’ ⛔ Warning (comp): init.el:175:7: Warning: assignment to free variable ‘helm-ff-file-name-history-use-recentf’ 

I know that, in general, the right solution is to (require 'packagename) to import the package these variables are from. How can I figure out which package these un-defvared variables came from?

0

1 Answer 1

4

From the names. The variable helm-blah-blah-blah is, by convention, defined in the package Helm. c-basic-offset is defined in a package called cc-mode (Ok, they didn’t always follow today’s rules way back in the beginning, so some old stuff doesn’t quite match). If you aren’t sure, you can use C-h v. It will say something like “c-basic-offset is a customizable variable defined in cc-vars.el.gz.”.

However, you are incorrect about the best way to fix these warnings. This is one of those X–Y questions; knowing what package the variable comes from is not important.

Calling require to load a package is a blunt instrument. It forces Emacs to stop and do something expensive, and Emacs must already run your init file before it even shows the initial frame. Add enough calls to require here and Emacs startup will be annoyingly slow.

Instead, once you have verified that these variables do exist and that you have made no typos, just call defvar to declare that these variables exist and are not lexical. Later on the real definition will be loaded and all will be well.

3
  • 1
    The helm variables were "misnamed" as well (I needed to (require 'helm-files)), but I'd forgotten about C-h v and it solved all my problems. Thanks! Commented Jul 5, 2024 at 6:08
  • 1
    You’re welcome, but did you see where I say that you should not use require? Don’t use require, use defvar! Commented Jul 5, 2024 at 7:17
  • 1
    D'oh! Thanks for catching that. Commented Jul 5, 2024 at 16:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.