2

Launch Emacs using runemacs --debug-init and the following error occurred. any idea on how to locate the file/script of the error or how to fix it? Thanks in advance.

Debugger entered--Lisp error: (invalid-read-syntax ")")
  read(#<buffer  *load*>)
  eval-buffer(#<buffer  *load*> nil "c:/Users/user/.emacs" nil t)  ; Reading at buffer position 1709
  load-with-code-conversion("c:/Users/user/.emacs" "c:/Users/user/.emacs" t t)
  load("~/.emacs" t t)
  #f(compiled-function () #<bytecode 0x1000be22d>)()
  command-line()
  normal-top-level()
5

You have an extra right paren, ), somewhere in your init file. Here's one way to find it:

  1. Start Emacs using emacs -Q (no init file).

  2. Visit this file - the one that Emacs was trying to load when it barfed:

     C-x C-f /Users/user/.emacs
    
  3. Comment out 1/2 of that file (roughly), using M-x comment-region.

  4. Do M-x eval-buffer.

    If you get an error, then comment out half of uncommented part. If you didn't get an error, uncomment half of the commented part.

Repeat step 4 till you find the problem in your init file. This is a binary search: 1/2, 1/4, 1/8, 1/16, 1/32,...


If your init file is small, you might want to instead just look for the extra right paren directly. You might start at the file beginning and use C-M-f to move past each sexp. Sooner or later you'll get to the one with an extra ).


As @NickD mentioned in a comment, here's another thing to try, and it's quick:

If you just byte-compile the file, the compiler should tell you where it sees the error (no guarantees that it will actually be there, but it doesn't hurt to check it first, before starting a binary search):

Compiling file /tmp/foo.el at Mon Nov 25 17:15:31 2019
foo.el:6:3:Error: Invalid read syntax: ")" 

And as @phils mentions in another comment, unmatched parens can be found by using

 M-x check-parens

which takes you directly to the culprit, so it is quicker.

| improve this answer | |
  • If you just byte-compile the file, the compiler should tell you where it sees the error (no guarantees that it will actually be there, but it doesn't hurt to check it first, before starting a binary search): Compiling file /tmp/foo.el at Mon Nov 25 17:15:31 2019 foo.el:6:3:Error: Invalid read syntax: ")" – NickD Nov 25 '19 at 22:17
  • @NickD: Good suggestion. I've added it here, but if you post it as an answer I'll remove it from this answer. Thx. – Drew Nov 26 '19 at 1:00
  • 1
    M-x check-parens will frequently take you there directly. – phils Nov 26 '19 at 8:58
  • Thanks @Drew - I located the extra right paren ) at the very end of .emacs file by going through the whole file which is small. Also it's very good to know the binary search. – YiC Nov 26 '19 at 13:10
  • Thanks @NickD too for the compiling file approach. I get a .emacs.elc file ater M-x byte-compile-file and don't know how to check further. can you maybe add details to your foo.el example? Appreciated. – YiC Nov 26 '19 at 13:10

Your Answer

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

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