jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.42k stars 260 forks source link

`:config` on major-mode runs when major-mode's feature is available #1078

Open KarlJoad opened 4 months ago

KarlJoad commented 4 months ago

I am trying to use scala-ts-mode for Scala buffers. These files contain Scala code and the Chisel EDSL for hardware (this means that there is usually no good way to know if a particular file is Scala or Chisel).

The default settings for scala-ts-mode do not match what I am used to from scala-mode's "mis-handling" of Chisel code, and I am trying to see if I can restore it. The main goal is to alter treesit-font-lock-feature-list so that I highlight what I care about as Chisel code.

After some discussion on IRC, we narrowed down the issue to the :config in my use-package invocation. :config runs after the feature is available, which is distinctly different than when the major-mode is invoked. I am currently working around this by attaching a hook, but wanted to make sure that this :config behavior is intended.

ELISP> (macroexpand-1 '(use-package scala-ts-mode
  :ensure t
  :defer t
  :config
    (setq-local treesit-font-lock-feature-list
                '((comment doc-comment definition)
                  (keyword type)
                  (variable function import literal)
                  (operator interpolation extra)))
    (setq-local treesit-font-lock-level 3)
    (treesit-font-lock-recompute-features)))

(elpaca scala-ts-mode
  (defvar use-package--warning99
    #'(lambda
        (keyword err)
        (let
            ((msg
              (format "%s/%s: %s" 'scala-ts-mode keyword
                      (error-message-string err))))
          (display-warning 'use-package msg :error))))
  (condition-case-unless-debug err
      (eval-after-load 'scala-ts-mode
        '(condition-case-unless-debug err
             (progn
               (setq-local treesit-font-lock-feature-list
                           '((comment doc-comment definition)
                             (keyword type)
                             (variable function import literal)
                             (operator interpolation extra)))
               (setq-local treesit-font-lock-level 3)
               (treesit-font-lock-recompute-features)
               t)
           (error
            (funcall use-package--warning99 :config err))))
    (error
     (funcall use-package--warning99 :catch err))))