(use-package treesit-auto :demand t :config (progn (setq treesit-auto-install t) (global-treesit-auto-mode +1)
(defun treesit-auto-for-each (fn) (cl-loop for recipe in treesit-auto-recipe-list do (let ((from (treesit-auto-recipe-remap recipe)) (to (treesit-auto-recipe-ts-mode recipe))) (funcall fn from to))))
(defun treesit-auto-get-mode-hook-symbol (mode) (intern (concat (symbol-name mode) “-hook”)))
(defvar treesit-auto-run-original-hooks t) (defvar treesit-auto-hook-copy-blacklist ‘((rust-mode . rust-ts-mode)))
(treesit-auto-for-each (lambda (from to) (let ((targets (if (listp from) from (list from)))) (cl-loop for from in targets do (letrec ((to-hook (treesit-auto-get-mode-hook-symbol to)) (from-hook (treesit-auto-get-mode-hook-symbol from)) (treesit-auto-hook-name (intern (concat “treesit-auto-run-” (symbol-name from-hook) “-for-” (symbol-name to))))) (defalias treesit-auto-hook-name `(lambda () (when (and treesit-auto-run-original-hooks (boundp ‘,from-hook) (not (memq ‘(,from . ,to) treesit-auto-hook-copy-blacklist))) (message “Running hooks from %s for %s” ‘,from-hook ‘,to) (run-mode-hooks ‘,from-hook)))) (add-hook to-hook treesit-auto-hook-name))))))))