In my init.el, I have something like
(use-package racket-mode :mode "\\.rkt\\'") However, when I open a .rkt file, racket-mode does not start. Running (alist-get "\\.rkt\\'" auto-mode-alist nil nil #'equal) returns scheme-mode (because it hooks too on the .rkt file extension, God knows why every Lisp dialect hooks into each-other extensions...), so I though maybe it "overwrites" racket-mode, ie. it was added after racket-mode in auto-mode-alist. However, I have ruled that out with
(require 'dash) (-filter (lambda (x) (equal (car x) "\\.rkt\\'")) auto-mode-alist) which only shows (("\\.rkt\\'" . scheme-mode)).
If, then, I:
- manually run
racket-modeonce, or - I re-execute any
(use-package racket-mode), or - M-x
load-file~/.emacs.d/init.el
it works, in the sense that opening a .rkt file loads the racket-mode, and (alist-get "\\.rkt\\'" auto-mode-alist nil nil #'equal) returns racket-mode. So it seems that forcing racket-mode to load makes use-package insert it in the auto-mode-alist. However, I don't understand why re-calling use-package, or re-evaluating the init.el file would do that...
Reading the documentation of the :mode keyword of use-package, it says that it implies :defer, so that the addition to the auto-mode-alist is deferred until actually required. I tried adding
(use-package racket-mode :mode "\\.rkt\\'" :commands racket-mode) because I read somewhere that could help, but it did not.
In a last, desperate measure, I tried
(use-package racket-mode :init (add-to-list 'auto-mode-alist '("\\.rkt\\'" . racket-mode))) but that didn't work either. It almost looks like this code doesn't get executed, because if I launch a fresh emacs instance with emacs -q, then eval
(require 'use-package) (use-package racket-mode) it Just Works™. So it's just as if the use-package in my init.el was simply not executed... Btw, just to be clear: I am sure my init.el file is evaluated, since it changes the theme, a lot of key bindings and what is shown first when opening Emacs.
Edit: set use-package-verbose as recommended in the comments.
The result is, indeed, strange. My init.el file contains the following snippet:
(use-package lsp-haskell) (use-package racket-mode :mode "\\.rkt\\'") (use-package scheme-complete) but in the *Messages*, I see the following:
Loading package lsp-haskell...done Loading package scheme-complete...done So it really seems like it simply skips racket-mode. Searching for racket-mode in the rest of the log did not reveal any match.
use-packageis doing by placing point at the end of the(use-package racket-mode ...)form and doingM-x pp-macroexpand-last-sexp. It seems that it does(add-to-list 'auto-mode-alist '("\\.rkt\\'" . racket-mode))whether or not:deferis non-nil..rktextension. Are you loadinggeiseras well? That seems to associate rkt files with scheme-mode.use-package-verbosein your init file to get some additional detail about when things are happening.(use-package ...). @glucas I havegeisertoo indeed, even though I'm not too sure about what it does exactly (it was recommended alongside racket-mode and scheme-mode).