Skip to content

Commit 06cb69d

Browse files
committed
tweak(treesit-auto): fix grammars and refactor
1 parent de31e49 commit 06cb69d

File tree

1 file changed

+55
-33
lines changed

1 file changed

+55
-33
lines changed

modules/me-prog.el

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,62 @@
2020
:custom
2121
(treesit-auto-install 'prompt)
2222
:config
23+
;; Add extra grammars
2324
;; BUG+FIX: Remove the C++ grammar to force using v0.22.0, newer versions
24-
;; cause problems with syntax highlighting in `c++-ts-mode' buffers.
25-
;; See: https://github.com/abougouffa/minemacs/discussions/135
26-
(cl-callf2 cl-delete-if
27-
(lambda (lang) (eq 'cpp (treesit-auto-recipe-lang lang)))
28-
treesit-auto-recipe-list)
29-
(let ((extra-recipes (list (make-treesit-auto-recipe
30-
:lang 'xml
31-
:ts-mode 'xml-ts-mode
32-
:remap '(nxml-mode xml-mode)
33-
:url "https://github.com/tree-sitter-grammars/tree-sitter-xml"
34-
:source-dir "xml/src"
35-
:ext "\\.xml\\'")
36-
(make-treesit-auto-recipe
37-
:lang 'cpp
38-
:ts-mode 'c++-ts-mode
39-
:remap 'c++-mode
40-
:url "https://github.com/tree-sitter/tree-sitter-cpp"
41-
:revision "v0.22.0"
42-
:ext "\\.cpp\\'")
43-
(make-treesit-auto-recipe
44-
:lang 'llvm
45-
:ts-mode 'llvm-ts-mode
46-
:remap 'llvm-mode
47-
:url "https://github.com/benwilliamgraham/tree-sitter-llvm"
48-
:ext "\\.ll\\'")
49-
(make-treesit-auto-recipe
50-
:lang 'zig
51-
:ts-mode 'zig-ts-mode
52-
:remap 'zig-mode
53-
:url "https://github.com/GrayJack/tree-sitter-zig"
54-
:ext "\\.\\(zig\\|zon\\)\\'"))))
55-
(cl-callf append treesit-auto-langs (mapcar #'treesit-auto-recipe-lang extra-recipes))
56-
(cl-callf append treesit-auto-recipe-list extra-recipes))
25+
;; cause problems with syntax highlighting in `c++-ts-mode' buffers (abougouffa/minemacs#135)
26+
;; BUG+FIX: Remove the Markdown grammar to install it correctly (renzmann/treesit-auto#102)
27+
(let* ((extra-recipes
28+
(list (make-treesit-auto-recipe
29+
:lang 'xml
30+
:ts-mode 'xml-ts-mode
31+
:remap '(nxml-mode xml-mode)
32+
:url "https://github.com/tree-sitter-grammars/tree-sitter-xml"
33+
:source-dir "xml/src"
34+
:ext "\\.xml\\'")
35+
(make-treesit-auto-recipe
36+
:lang 'markdown
37+
:ts-mode 'markdown-ts-mode
38+
:remap '(poly-markdown-mode markdown-mode)
39+
:requires 'markdown-inline
40+
:url "https://github.com/tree-sitter-grammars/tree-sitter-markdown"
41+
:revision "split_parser"
42+
:source-dir "tree-sitter-markdown/src"
43+
:ext "\\.md\\'")
44+
(make-treesit-auto-recipe
45+
:lang 'markdown-inline
46+
:ts-mode 'markdown-inline-mode ; Fake mode to make `treesit-auto' happy
47+
:remap 'markdown-inline-ts-mode
48+
:requires 'markdown
49+
:url "https://github.com/tree-sitter-grammars/tree-sitter-markdown"
50+
:revision "split_parser"
51+
:source-dir "tree-sitter-markdown-inline/src")
52+
(make-treesit-auto-recipe
53+
:lang 'cpp
54+
:ts-mode 'c++-ts-mode
55+
:remap 'c++-mode
56+
:requires 'c
57+
:url "https://github.com/tree-sitter/tree-sitter-cpp"
58+
:revision "v0.22.0"
59+
:ext "\\.cpp\\'")
60+
(make-treesit-auto-recipe
61+
:lang 'llvm
62+
:ts-mode 'llvm-ts-mode
63+
:remap 'llvm-mode
64+
:url "https://github.com/benwilliamgraham/tree-sitter-llvm"
65+
:ext "\\.ll\\'")
66+
(make-treesit-auto-recipe
67+
:lang 'zig
68+
:ts-mode 'zig-ts-mode
69+
:remap 'zig-mode
70+
:url "https://github.com/GrayJack/tree-sitter-zig"
71+
:ext "\\.\\(zig\\|zon\\)\\'"))))
72+
;; First, delete the duplicate recipes already present in the list, if any
73+
(cl-callf2 cl-delete-if
74+
(lambda (lang) (memq (treesit-auto-recipe-lang lang) (mapcar #'treesit-auto-recipe-lang extra-recipes)))
75+
treesit-auto-recipe-list)
76+
;; Then, add the extra recipes to the list
77+
(cl-callf append treesit-auto-recipe-list extra-recipes)
78+
(setq treesit-auto-langs (mapcar #'treesit-auto-recipe-lang treesit-auto-recipe-list)))
5779

5880
;; Ensure that installed tree-sitter languages have their corresponding `x-ts-mode' added to `auto-mode-alist'
5981
(treesit-auto-add-to-auto-mode-alist 'all)

0 commit comments

Comments
 (0)