0

I wanted to add a new display setting to init.el file, but didn't like it and removed the line. Now when I start emacs I get this error:

Invalid read syntax: . in wrong context

Here is the init.el file:

((require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/" t)))
(package-initialize)
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages '(solarized-theme)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
)
(load-theme 'solarized-dark t)
(custom-set-variables
  '(default-frame-alist
      '((background-color . "#1b1c1f")
        (background-mode . dark))))
(global-set-key (kbd "<home>") 'move-beginning-of-line)
(global-set-key (kbd "<end>") 'move-end-of-line)
(global-set-key (kbd "<Control>space") 'set-mark-command)

I am not familiar with lisp. Is there a typo here? Debug-init mode gives me the below:

Debugger entered--Lisp error: (invalid-read-syntax ". in wrong context")
read(#<buffer  *load*>)
eval-buffer(#<buffer  *load*> nil "/Users/admin/.emacs.d/init.el" nil t) ; 
Reading at buffer position 103
load-with-code-conversion("/Users/admin/.emacs.d/init.el" 
"/Users/ozandernek/.emacs.d/init.el" t t)
load("/Users/ozandernek/.emacs.d/init" noerror nomessage)
startup--load-user-init-file(#f(compiled-function () #<bytecode 0x4e46592b>) 
#f(compiled-function () #<bytecode 0x4e465941>) t)
command-line()
normal-top-level()
4
  • The t at the end of the second line is wrong: delete it. It was trying to read a dotted pair ("melpa" . "https://etc") and it found a t where it expected a closing paren. Since dotted pairs are relatively rare, it chose to believe that you were trying to enter a list ("melpa" "https://etc" t) but it guessed wrong (I guess :-) )
    – NickD
    Apr 12 at 0:17
  • @NickD Removing the t gives "Invalid function: (require 'package)".
    – user175924
    Apr 12 at 0:28
  • 1
    ((require 'package) has too many (. The syntax (foo ...) calls a function foo passing it arguments .... So ((require 'package) (add-to-list...) ...) is an attempt to call a function named (require 'package), hence the error message "Invalid function: (require 'package)".
    – phils
    Apr 12 at 1:00
  • The moral of the story is that if there is one error, then there are likely more than one :-)
    – NickD
    Apr 12 at 1:09

1 Answer 1

1

The answer to how to debug this is to bisect your init file. Comment out 1/2 the lines, then 3/4, 7/8,...

That will narrow down the offending code (e.g., to the sexp that @NickD pointed to in his comment).

@NickD recognized that because he knows what the various sexps in your init file are for - what they're expected to look like. If you don't, then bisecting is a good way to find the needle in the haystack.

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.