Skip to content

Commit dc66d67

Browse files
rrudakovbbatsov
authored andcommitted
[#77] Update grammars
1 parent a0b01b2 commit dc66d67

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- [#72](https://github.com/clojure-emacs/clojure-ts-mode/pull/72): Pass fully qualified symbol to `clojure-ts-get-indent-function`.
2121
- [#76](https://github.com/clojure-emacs/clojure-ts-mode/pull/76): Improve performance of semantic indentation by caching rules.
2222
- [#74](https://github.com/clojure-emacs/clojure-ts-mode/issues/74): Add imenu support for keywords definitions.
23+
- [#77](https://github.com/clojure-emacs/clojure-ts-mode/issues/77): Update grammars to the latest versions.
2324

2425
## 0.2.3 (2025-03-04)
2526

Diff for: README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Once installed, evaluate clojure-ts-mode.el and you should be ready to go.
124124
`clojure-ts-mode` makes use of two TreeSitter grammars to work properly:
125125

126126
- The Clojure grammar, mentioned earlier
127-
- [markdown_inline](https://github.com/MDeiml/tree-sitter-markdown), which
127+
- [markdown-inline](https://github.com/MDeiml/tree-sitter-markdown), which
128128
will be used for docstrings if available and if `clojure-ts-use-markdown-inline` is enabled.
129129

130130
If you have `git` and a C compiler (`cc`) available on your system's `PATH`,
@@ -137,6 +137,17 @@ option to install it manually, Please, refer to the installation instructions of
137137
each required grammar and make sure you're install the versions expected. (see
138138
`clojure-ts-grammar-recipes` for details)
139139

140+
### Upgrading tree-sitter grammars
141+
142+
To reinstall or upgrade TreeSitter grammars, you can execute:
143+
144+
```emacs-lisp
145+
M-x clojure-ts-reinstall-grammars
146+
```
147+
148+
This will install the latest compatible grammars, even if they are already
149+
installed.
150+
140151
## Configuration
141152

142153
To see a list of available configuration options do `M-x customize-group <RET> clojure-ts`.

Diff for: clojure-ts-mode.el

+27-17
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,14 @@ if a third argument (the value) is provided.
343343

344344
(defvar clojure-ts--treesit-range-settings
345345
(treesit-range-rules
346-
:embed 'markdown_inline
346+
:embed 'markdown-inline
347347
:host 'clojure
348348
(clojure-ts--docstring-query '@capture)))
349349

350350
(defun clojure-ts--font-lock-settings (markdown-available)
351351
"Return font lock settings suitable for use in `treesit-font-lock-settings'.
352352
When MARKDOWN-AVAILABLE is non-nil, includes rules for highlighting docstrings
353-
with the markdown_inline grammar."
353+
with the markdown-inline grammar."
354354
(append
355355
(treesit-font-lock-rules
356356
:feature 'string
@@ -512,11 +512,9 @@ with the markdown_inline grammar."
512512
(when markdown-available
513513
(treesit-font-lock-rules
514514
:feature 'doc
515-
:language 'markdown_inline
515+
:language 'markdown-inline
516516
:override t
517-
`((inline
518-
(code_span (code_span_delimiter) :* @font-lock-delimiter-face)
519-
@font-lock-constant-face))))
517+
`((code_span) @font-lock-constant-face)))
520518

521519
(treesit-font-lock-rules
522520
:feature 'quote
@@ -985,7 +983,7 @@ and (:defn) is converted to (:inner 1)."
985983
(t nil))))
986984

987985
(defun clojure-ts--dynamic-indent-for-symbol (sym &optional ns)
988-
"Returns the dynamic indentation specification for SYM, if found.
986+
"Return the dynamic indentation specification for SYM, if found.
989987
990988
If the function `clojure-ts-get-indent-function' is defined, call it and
991989
produce a valid indentation specification from its return value.
@@ -1019,7 +1017,7 @@ If NS is defined, then the fully qualified symbol is passed to
10191017
(equal (car spec1) :block)))))))))
10201018

10211019
(defun clojure-ts--find-semantic-rule (node parent current-depth)
1022-
"Returns a suitable indentation rule for NODE, considering the CURRENT-DEPTH.
1020+
"Return a suitable indentation rule for NODE, considering the CURRENT-DEPTH.
10231021
10241022
Attempts to find an indentation rule by examining the symbol name of the
10251023
PARENT's first child. If a rule is not found, it navigates up the
@@ -1153,21 +1151,21 @@ according to the rule. If NODE is nil, use next node after BOL."
11531151
(clojure-ts--metadata-node-p prev-sibling))))
11541152

11551153
(defun clojure-ts--anchor-parent-skip-metadata (_node parent _bol)
1156-
"Anchor function that returns position of PARENT start for NODE.
1154+
"Return position of PARENT start for NODE.
11571155
11581156
If PARENT has optional metadata we skip it and return starting position
11591157
of the first child's opening paren.
11601158
1161-
NOTE: This anchor is used to fix indentation issue for forms with type
1162-
hints."
1159+
NOTE: This serves as an anchor function to resolve an indentation issue
1160+
for forms with type hints."
11631161
(let ((first-child (treesit-node-child parent 0 t)))
11641162
(if (clojure-ts--metadata-node-p first-child)
11651163
;; We don't need named node here
11661164
(treesit-node-start (treesit-node-child parent 1))
11671165
(treesit-node-start parent))))
11681166

11691167
(defun clojure-ts--match-collection-item-with-metadata (node-type)
1170-
"Returns a matcher for a collection item with metadata by NODE-TYPE.
1168+
"Return a matcher for a collection item with metadata by NODE-TYPE.
11711169
11721170
The returned matcher accepts NODE, PARENT and BOL and returns true only
11731171
if NODE has metadata and its parent has type NODE-TYPE."
@@ -1296,9 +1294,9 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph."
12961294

12971295
(defconst clojure-ts-grammar-recipes
12981296
'((clojure "https://github.com/sogaiu/tree-sitter-clojure.git"
1299-
"v0.0.12")
1300-
(markdown_inline "https://github.com/MDeiml/tree-sitter-markdown"
1301-
"v0.1.6"
1297+
"v0.0.13")
1298+
(markdown-inline "https://github.com/MDeiml/tree-sitter-markdown"
1299+
"v0.4.1"
13021300
"tree-sitter-markdown-inline/src"))
13031301
"Intended to be used as the value for `treesit-language-source-alist'.")
13041302

@@ -1316,6 +1314,18 @@ If JUSTIFY is non-nil, justify as well as fill the paragraph."
13161314
(let ((treesit-language-source-alist clojure-ts-grammar-recipes))
13171315
(treesit-install-language-grammar grammar)))))))
13181316

1317+
(defun clojure-ts-reinstall-grammars ()
1318+
"Install the required versions of language grammars.
1319+
1320+
If the grammars are already installed, they will be reinstalled. This
1321+
function can also be used to upgrade the grammars if they are outdated."
1322+
(interactive)
1323+
(dolist (recipe clojure-ts-grammar-recipes)
1324+
(let ((grammar (car recipe)))
1325+
(message "Installing %s tree-sitter grammar" grammar)
1326+
(let ((treesit-language-source-alist clojure-ts-grammar-recipes))
1327+
(treesit-install-language-grammar grammar)))))
1328+
13191329
(defun clojure-ts-mode-variables (&optional markdown-available)
13201330
"Initialize buffer-local variables for `clojure-ts-mode'.
13211331
See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE."
@@ -1361,9 +1371,9 @@ See `clojure-ts--font-lock-settings' for usage of MARKDOWN-AVAILABLE."
13611371
:syntax-table clojure-ts-mode-syntax-table
13621372
(clojure-ts--ensure-grammars)
13631373
(let ((use-markdown-inline (and clojure-ts-use-markdown-inline
1364-
(treesit-ready-p 'markdown_inline t))))
1374+
(treesit-ready-p 'markdown-inline t))))
13651375
(when use-markdown-inline
1366-
(treesit-parser-create 'markdown_inline)
1376+
(treesit-parser-create 'markdown-inline)
13671377
(setq-local treesit-range-settings clojure-ts--treesit-range-settings))
13681378

13691379
(when (treesit-ready-p 'clojure)

0 commit comments

Comments
 (0)