Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
KarlJoad opened this issue Jul 18, 2024 · 0 comments
Open

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

KarlJoad opened this issue Jul 18, 2024 · 0 comments

Comments

@KarlJoad
Copy link

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))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant