mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
fix(tree-sitter): discard COMMIT recipe argument on <=30.x
Otherwise `treesit--install-language-grammar-1` will throw an arity error on Emacs <=30.x when installing grammars. Fix: #8393
This commit is contained in:
@ -5,16 +5,21 @@
|
|||||||
(message "Old tree-sitter.el support is deprecated!"))
|
(message "Old tree-sitter.el support is deprecated!"))
|
||||||
|
|
||||||
;;;###autodef (fset 'set-tree-sitter! #'ignore)
|
;;;###autodef (fset 'set-tree-sitter! #'ignore)
|
||||||
(defun set-tree-sitter! (mode ts-mode &optional langs)
|
(defun set-tree-sitter! (mode ts-mode &optional recipes)
|
||||||
"Remap major MODE to TS-MODE.
|
"Remap major MODE to TS-MODE.
|
||||||
|
|
||||||
MODE and TS-MODE are major mode symbols. If LANGS is provided, fall back to MODE
|
MODE and TS-MODE are major mode symbols. If RECIPES is provided, fall back to
|
||||||
if LANGS don't pass `treesit-ready-p' when activating TS-MODE. Use this for ts
|
MODE if RECIPES don't pass `treesit-ready-p' when activating TS-MODE. Use this
|
||||||
modes that error out instead of failing gracefully."
|
for ts modes that error out instead of failing gracefully.
|
||||||
|
|
||||||
|
RECIPES are an alist of plists with the format (LANG &key URL REV SOURCE-DIR CC
|
||||||
|
CPP COMMIT), which will be transformed into entries for
|
||||||
|
`treesit-language-source-alist' (which descrie what each of these keys mean).
|
||||||
|
Note that COMMIT is only available in Emacs >=31."
|
||||||
(declare (indent 2))
|
(declare (indent 2))
|
||||||
(cl-check-type mode symbol)
|
(cl-check-type mode symbol)
|
||||||
(cl-check-type ts-mode symbol)
|
(cl-check-type ts-mode symbol)
|
||||||
(setq langs (ensure-list langs))
|
(setq recipes (ensure-list recipes))
|
||||||
(dolist (m (ensure-list mode))
|
(dolist (m (ensure-list mode))
|
||||||
(add-to-list
|
(add-to-list
|
||||||
'major-mode-remap-defaults
|
'major-mode-remap-defaults
|
||||||
@ -24,7 +29,7 @@ modes that error out instead of failing gracefully."
|
|||||||
(funcall
|
(funcall
|
||||||
;; Because standard major-mode remapping doesn't offer graceful
|
;; Because standard major-mode remapping doesn't offer graceful
|
||||||
;; failure in some cases, I implement it myself:
|
;; failure in some cases, I implement it myself:
|
||||||
(cond ((null langs) m)
|
(cond ((null recipes) m)
|
||||||
((not (fboundp ts-mode))
|
((not (fboundp ts-mode))
|
||||||
(message "Couldn't find %S, using %S instead" ts-mode m)
|
(message "Couldn't find %S, using %S instead" ts-mode m)
|
||||||
m)
|
m)
|
||||||
@ -35,19 +40,25 @@ modes that error out instead of failing gracefully."
|
|||||||
(cl-every (if ensured?
|
(cl-every (if ensured?
|
||||||
(doom-rpartial #'treesit-ready-p 'message)
|
(doom-rpartial #'treesit-ready-p 'message)
|
||||||
#'treesit-ensure-installed)
|
#'treesit-ensure-installed)
|
||||||
(cl-loop for lang in langs
|
(cl-loop for r in recipes
|
||||||
if (listp lang)
|
if (listp r)
|
||||||
collect (car lang)
|
collect (car r)
|
||||||
else collect (list lang))))
|
else collect (list r))))
|
||||||
ts-mode)
|
ts-mode)
|
||||||
((setq ensured? t)
|
((setq ensured? t)
|
||||||
m))))))))
|
m))))))))
|
||||||
(with-eval-after-load 'treesit
|
(with-eval-after-load 'treesit
|
||||||
(dolist (lang langs)
|
(dolist (recipe recipes)
|
||||||
(when (and lang (listp lang))
|
(cl-destructuring-bind (name &key url rev source-dir cc cpp commit)
|
||||||
(cl-destructuring-bind (name &key url rev source-dir cc cpp commit) lang
|
(ensure-list recipe)
|
||||||
(setf (alist-get name treesit-language-source-alist)
|
(setf (alist-get name treesit-language-source-alist)
|
||||||
(list url rev source-dir cc cpp commit)))))))
|
(append (list url rev source-dir cc cpp)
|
||||||
|
;; COMPAT: 31.1 introduced a COMMIT recipe argument. On
|
||||||
|
;; <=30.x, extra arguments will trigger an arity error
|
||||||
|
;; when installing grammars.
|
||||||
|
(if (eq (cdr (func-arity 'treesit--install-language-grammar-1))
|
||||||
|
'many)
|
||||||
|
(list commit))))))))
|
||||||
|
|
||||||
;; ;; HACK: Remove and refactor when `use-package' eager macro expansion is solved or `use-package!' is removed
|
;; ;; HACK: Remove and refactor when `use-package' eager macro expansion is solved or `use-package!' is removed
|
||||||
;; ;;;###autoload
|
;; ;;;###autoload
|
||||||
|
Reference in New Issue
Block a user