0

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-mode once, or
  • I re-execute any (use-package racket-mode), or
  • M-xload-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.

8
  • 1
    Given the last paragraph - how are you loading use-package into your init files?
    – mmmmmm
    Commented Mar 6, 2022 at 17:13
  • You can get insight into what use-package is doing by placing point at the end of the (use-package racket-mode ...) form and doing M-x pp-macroexpand-last-sexp. It seems that it does (add-to-list 'auto-mode-alist '("\\.rkt\\'" . racket-mode)) whether or not :defer is non-nil. Commented Mar 6, 2022 at 21:00
  • I don't see scheme-mode registered for the .rkt extension. Are you loading geiser as well? That seems to associate rkt files with scheme-mode.
    – glucas
    Commented Mar 7, 2022 at 17:02
  • You might try setting use-package-verbose in your init file to get some additional detail about when things are happening.
    – glucas
    Commented Mar 7, 2022 at 17:09
  • @mmmmmm I'm not sure what the question is. My init file mostly contains a bunch of (use-package ...). @glucas I have geiser too indeed, even though I'm not too sure about what it does exactly (it was recommended alongside racket-mode and scheme-mode).
    – jthulhu
    Commented Mar 7, 2022 at 17:13

1 Answer 1

1

The culprit was quack, which overwrote auto-mode-alist to prefer scheme-mode to racket-mode when opening .rkt files. Disabling it worked perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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