mirror of
https://github.com/doomemacs/doomemacs
synced 2025-09-02 14:53:38 -05:00
fix(tree-sitter): backport treesit-{enabled-modes,major-mode-remap-alist}
And ignore `treesit-major-mode-remap-alist`, because they could interfere with our UX improvements.
This commit is contained in:
@@ -40,4 +40,32 @@ Tree-sitter grammar for `%s' is missing; install it?"
|
|||||||
;; Check that the grammar was installed successfully
|
;; Check that the grammar was installed successfully
|
||||||
(treesit-ready-p lang))))
|
(treesit-ready-p lang))))
|
||||||
|
|
||||||
|
;;; Introduced in later commits of 31.X
|
||||||
|
;;;###autoload
|
||||||
|
(unless (boundp 'treesit-major-mode-remap-alist)
|
||||||
|
(defvar treesit-major-mode-remap-alist nil))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defcustom treesit-enabled-modes nil
|
||||||
|
"Specify what treesit modes to enable by default.
|
||||||
|
The value can be either a list of ts-modes to enable,
|
||||||
|
or t to enable all ts-modes."
|
||||||
|
:type `(choice
|
||||||
|
(const :tag "Disable all automatic associations" nil)
|
||||||
|
(const :tag "Enable all available ts-modes" t)
|
||||||
|
(set :tag "List of enabled ts-modes"
|
||||||
|
,@(when (treesit-available-p)
|
||||||
|
(sort (mapcar (lambda (m) `(function-item ,m))
|
||||||
|
(seq-uniq (mapcar #'cdr treesit-major-mode-remap-alist)))))))
|
||||||
|
:initialize #'custom-initialize-default
|
||||||
|
:set (lambda (sym val)
|
||||||
|
(set-default sym val)
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(dolist (m treesit-major-mode-remap-alist)
|
||||||
|
(setq major-mode-remap-alist
|
||||||
|
(if (or (eq val t) (memq (cdr m) val))
|
||||||
|
(cons m major-mode-remap-alist)
|
||||||
|
(delete m major-mode-remap-alist))))))
|
||||||
|
:version "31.1")
|
||||||
|
|
||||||
;;; compat-30.el ends here
|
;;; compat-30.el ends here
|
||||||
|
@@ -39,6 +39,8 @@ Note that COMMIT is only available in Emacs >=31."
|
|||||||
((and (fboundp 'treesit-available-p)
|
((and (fboundp 'treesit-available-p)
|
||||||
(treesit-available-p)
|
(treesit-available-p)
|
||||||
(fboundp ts-mode)
|
(fboundp ts-mode)
|
||||||
|
(or (eq treesit-enabled-modes t)
|
||||||
|
(memq ts-mode treesit-enabled-modes))
|
||||||
;; Only prompt once, and log other times.
|
;; Only prompt once, and log other times.
|
||||||
(cl-every (if ensured?
|
(cl-every (if ensured?
|
||||||
(doom-rpartial #'treesit-ready-p 'message)
|
(doom-rpartial #'treesit-ready-p 'message)
|
||||||
|
@@ -7,7 +7,32 @@
|
|||||||
:when (fboundp 'treesit-available-p)
|
:when (fboundp 'treesit-available-p)
|
||||||
:when (treesit-available-p)
|
:when (treesit-available-p)
|
||||||
:defer t
|
:defer t
|
||||||
|
:preface
|
||||||
|
(setq treesit-enabled-modes t)
|
||||||
|
|
||||||
|
;; HACK: These *-ts-mode-maybe functions all treat `treesit-enabled-modes'
|
||||||
|
;; strangely in the event the language's grammar is unavailable. Plus, they
|
||||||
|
;; add yet-another-layer of complexity for users to be cognicent of. Get rid
|
||||||
|
;; of them.
|
||||||
|
;; REVIEW: Handle this during the 'doom sync' process instead.
|
||||||
|
(setq auto-mode-alist
|
||||||
|
(save-match-data
|
||||||
|
(cl-loop for (src . fn) in auto-mode-alist
|
||||||
|
unless (and (functionp fn)
|
||||||
|
(string-match "-ts-mode-maybe$" (symbol-name fn)))
|
||||||
|
collect (cons src fn))))
|
||||||
|
|
||||||
:config
|
:config
|
||||||
|
;; HACK: The implementation of `treesit-enabled-modes's setter and
|
||||||
|
;; `treesit-major-mode-remap-alist' are intrusively opinionated, so I
|
||||||
|
;; disable it altogether as to not unexpectedly modify
|
||||||
|
;; `major-mode-remap-alist' at runtime. What's more, there's no guarantee
|
||||||
|
;; this will be populated correctly unless the user is on a particular
|
||||||
|
;; commit of Emacs 31 or newer. Best we simply ignore it.
|
||||||
|
(dolist (m treesit-major-mode-remap-alist)
|
||||||
|
(setq major-mode-remap-alist (delete m major-mode-remap-alist)))
|
||||||
|
(setq treesit-major-mode-remap-alist nil)
|
||||||
|
|
||||||
;; HACK: treesit lacks any way to dictate where to install grammars.
|
;; HACK: treesit lacks any way to dictate where to install grammars.
|
||||||
(add-to-list 'treesit-extra-load-path (concat doom-profile-data-dir "tree-sitter"))
|
(add-to-list 'treesit-extra-load-path (concat doom-profile-data-dir "tree-sitter"))
|
||||||
(defadvice! +tree-sitter--install-grammar-to-local-dir-a (fn &rest args)
|
(defadvice! +tree-sitter--install-grammar-to-local-dir-a (fn &rest args)
|
||||||
|
Reference in New Issue
Block a user