@@ -470,7 +470,7 @@ if a third argument (the value) is provided.
470
470
:* )
471
471
(:match , clojure-ts--interface-def-symbol-regexp @_def_symbol))))
472
472
473
- (defconst clojure-ts--match-docstring-query-compiled
473
+ (defconst clojure-ts--match-docstring-query
474
474
(treesit-query-compile 'clojure (clojure-ts--docstring-query '@font-lock-doc-face ))
475
475
" Precompiled query that matches a Clojure docstring." )
476
476
@@ -839,9 +839,14 @@ Skip the optional metadata node at pos 0 if present."
839
839
t )))
840
840
841
841
(defun clojure-ts--first-value-child (node )
842
- " Return the first value child of the NODE.
843
-
844
- This will skip metadata and comment nodes."
842
+ " Returns the first value child of the given NODE.
843
+
844
+ In the syntax tree, there are a few types of possible child nodes:
845
+ unnamed standalone nodes (e.g., comments), anonymous nodes (e.g.,
846
+ opening or closing parentheses), and named nodes. Named nodes are
847
+ standalone nodes that are labeled by a specific name. The most common
848
+ names are meta and value. This function skips any unnamed, anonymous,
849
+ and metadata nodes and returns the first value node."
845
850
(treesit-node-child-by-field-name node " value" ))
846
851
847
852
(defun clojure-ts--symbol-matches-p (symbol-regexp node )
@@ -1363,7 +1368,7 @@ according to the rule. If NODE is nil, use next node after BOL."
1363
1368
" Match PARENT when it is a docstring node."
1364
1369
(when-let* ((top-level-node (treesit-parent-until parent 'defun t ))
1365
1370
(result (treesit-query-capture top-level-node
1366
- clojure-ts--match-docstring-query-compiled )))
1371
+ clojure-ts--match-docstring-query)))
1367
1372
(seq-find (lambda (elt )
1368
1373
(and (eq (car elt) 'font-lock-doc-face )
1369
1374
(treesit-node-eq (cdr elt) parent)))
@@ -1529,6 +1534,9 @@ function literal."
1529
1534
`((clojure
1530
1535
(sexp ,(regexp-opt clojure-ts--sexp-nodes))
1531
1536
(list ,(regexp-opt clojure-ts--list-nodes))
1537
+ ; ; `sexp-default' thing allows to fallback to the default implementation of
1538
+ ; ; `forward-sexp' function where `treesit-forward-sexp' produces undesired
1539
+ ; ; results.
1532
1540
(sexp-default
1533
1541
; ; For `C-M-f' in "#|(a)" or "#|{1 2 3}"
1534
1542
(,(rx (or " (" " {" )) . ,#'clojure-ts--default-sexp-node-p ))
@@ -2470,8 +2478,13 @@ before DELIM-OPEN."
2470
2478
" v0.24.3" ))
2471
2479
" Intended to be used as the value for `treesit-language-source-alist' ." )
2472
2480
2473
- (defun clojure-ts--grammar-outdated-p ()
2474
- " Return TRUE if currently installed grammar is outdated."
2481
+ (defun clojure-ts--clojure-grammar-outdated-p ()
2482
+ " Return TRUE if currently installed grammar is outdated.
2483
+
2484
+ This function checks if `clojure-ts-mode' is compatible with the
2485
+ currently installed grammar. The simplest way to do this is to validate
2486
+ a query that is valid in a previous grammar version but invalid in the
2487
+ required version."
2475
2488
(treesit-query-valid-p 'clojure '((sym_lit (meta_lit)))))
2476
2489
2477
2490
(defun clojure-ts--ensure-grammars ()
@@ -2483,7 +2496,7 @@ before DELIM-OPEN."
2483
2496
; ; If Clojure grammar is available, but outdated, re-install
2484
2497
; ; it.
2485
2498
(and (equal grammar 'clojure )
2486
- (clojure-ts--grammar-outdated-p)))
2499
+ (clojure-ts--clojure- grammar-outdated-p)))
2487
2500
(message " Installing %s Tree-sitter grammar " grammar)
2488
2501
; ; `treesit-language-source-alist' is dynamically scoped.
2489
2502
; ; Binding it in this let expression allows
0 commit comments