reddit / emacs

Emacs is broken even after restart

EmilySeville7cfg · 2022-08-02 05:16
After I've tried to execute `(setq package-load-list nil)` Emacs 28.1 become broken. When I start it I obtain this weird error: `Symbol's function definition is void: nil`. How can I fix it? Here is my `.emacs`: (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (setq packages '(soft-stone-theme flycheck)) (dolist (package packages) (package-install package)) (add-hook 'after-init-hook (lambda () (load-theme 'soft-stone t))) (add-hook 'after-init-hook global-flycheck-mode) (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. '(display-line-numbers 'relative) No error happens when I start Emacs via `emacs -Q`. I thought that removing `~/.emacs.d/` will help but Emacs became more broken than it was after start: https://preview.redd.it/cgg9uw3ek8f91.png?width=1920&format=png&auto=webp&s=dc418d4daf151515206c8bb632bacdde1216787d
Faerryn · 2022-08-02 05:26
`(add-hook 'after-init-hook global-flycheck-mode)` should be `(add-hook 'after-init-hook #'global-flycheck-mode)`, since `global-flycheck-mode` is being interpreted as the variable rather than the function.
EmilySeville7cfg · 2022-08-02 05:32
Strange things: it worked perfectly some time without `#'`. Do you know why I obtained errors for compiling internal forms (they are now disappeared)?
Faerryn · 2022-08-02 17:03
You are putting those things off until after emacs has run the init file, which is strange (IMO). Maybe Emacs didn't consistently catch the error since it technically happens after the init file has been run. ``` (add-hook 'after-init-hook (lambda () (load-theme 'soft-stone t))) (add-hook 'after-init-hook global-flycheck-mode) ``` Could perhaps be replaced with: ``` (load-theme 'soft-stone t) (global-flycheck-mode +1) ```
EmilySeville7cfg · 2022-08-03 02:34
But the official Flycheck docs [told me](https://www.flycheck.org/en/latest/user/quickstart.html#enable-flycheck) to use `(add-hook 'after-init-hook #'global-flycheck-mode)`. I am confused now - are docs wrong or not? When should I use hooks and when not?
Faerryn · 2022-08-03 03:37
Using hooks and not using hooks in this instance are both perfectly valid. I just don't use them when I don't have to, since it is simpler and less error-prone. In this instance you encountered an error due to mistyping the add-hook syntax, which may have been avoided if you just activated `global-flycheck-mode` directly. Hooks are useful if you have a reason to delay execution of code to a certain time during startup or during certain events; there is little point in using them if you don't have to.
7890yuiop · 2022-08-03 10:56
Prior to Emacs 27.1, `package-initialize` was not *automatically* called until *after* your init file had been processed, so that documentation is preventing problems for people using Emacs 26 (or earlier), who are not forcibly initializing the package system.