0

When I start Emacs, I get the error message: Symbol's value as variable is void: n I am pretty sure, it is just a typo in my init.el, but how can I find it?

Shouldn't there be a debugger, which tells me exactly where this variable n shows up?

My question is, whether it exists, and if it exists, where it is?

I would also appreciate best practices for debugging the init.el (or elisp in general) and also resources to learn this.

I loaded emacs with --debug-init and the backtrace gives me:

Debugger entered--Lisp error: (void-variable n)
load-with-code-conversion("/home/xx/.emacs.d/init.el" "/home/xx/.emacs.d/init.el" t t)
load("/home/xx/.emacs.d/init" noerror nomessage)
startup--load-user-init-file(#f(compiled-function () #<bytecode -0xfb4a62eb1ee4990>)   #f(compiled-function () #<bytecode -0x1f3c686ddc0ca9b5>) t)
command-line()
normal-top-level()

Which is unhelpful. What does it try to communicate to me?

4
  • I added a random n at top level of one of the files that I load when I start emacs and then I invoked emacs with emacs --debug-init. I got the following message: Debugger entered--Lisp error: (void-variable n) eval-buffer(#<buffer *load*-97476> nil "/some/path/org-config.el" nil t) ; Reading at buffer position 32678. Opening the file and going to position 32678 (with M-g c 32678) took me directly to the errant n. I don't understand why the buffer position is missing from your backtrace. Did you leave it out by any chance?
    – NickD
    Apr 10 at 22:06
  • 1
    @NickD: That position comes from backtrace--print-func-and-args (since 27.1) and from the comments is specific to eval-buffer usage -- which is happening in your case, but seemingly not for Sinthoras. Maybe load is doing something slightly different in different versions/cases?
    – phils
    Apr 10 at 23:02
  • Yes, maybe - the OP can perhaps add to the question the Emacs version they are running.
    – NickD
    Apr 11 at 1:11
  • I am on Emacs 27.1. And I did not leave out that line on my backtrace (since it was one of the points of the question, how I can make it show up, such that the computer tells me where the errant is, and I don't have to search it by myself.)
    – Sinthoras
    Apr 11 at 8:04

1 Answer 1

1

I would also appreciate best practices for debugging the init.el (or elisp in general) and also resources to learn this.

In a case like this, I'd say start by bisecting your init file. Use command comment-region to comment out 1/2, then 3/4, 7/8,... of your init file, to find the culprit. With C-u it uncomments, instead of comments, the region.

If you want, if you've narrowed the problem down to some function (something within that function is causing the problem), then use M-x debug-on-entry for that function.

That opens the debugger for each invocation of that function. Step through the debugger with d (or c to skip diving down inside a function). You'll see exactly what's going on and what goes wrong.


That said, there are lots of questions on this site about Symbol's value as a variable is void. Try searching for that on the site, to see if your question is a duplicate. If it is, please delete it.

2
  • Before posting, I already searched on this site about my question, and was surprised that I did not find it. The questions I found were all quite specific about specific Symbol's value as a variable is void errors, while I am asking about general principles.
    – Sinthoras
    Apr 11 at 8:01
  • Good. Thanks for searching.
    – Drew
    Apr 11 at 14:57

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.