Skip to content

Commit 7e359ed

Browse files
rrudakovbbatsov
authored andcommitted
Extend docstrings and fix some small issues
1 parent 832cc5c commit 7e359ed

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
- [#96](https://github.com/clojure-emacs/clojure-ts-mode/pull/96): Highlight function name properly in `extend-protocol` form.
66
- [#96](https://github.com/clojure-emacs/clojure-ts-mode/pull/96): Add support for extend-protocol forms to `clojure-ts-add-arity` refactoring
77
command.
8-
- Improve navigation by s-expression by switching to an experimental Clojure
9-
grammar.
10-
- More consistent docstrings highlighting and `fill-paragraph` behavior.
11-
- Fix bug in `clojure-ts-align` when nested form has extra spaces.
12-
- Fix bug in `clojure-ts-unwind` when there is only one expression after threading
13-
symbol.
8+
- [#99](https://github.com/clojure-emacs/clojure-ts-mode/pull/99): Improve navigation by s-expression by switching to an experimental
9+
Clojure grammar.
10+
- [#99](https://github.com/clojure-emacs/clojure-ts-mode/pull/99): More consistent docstrings highlighting and `fill-paragraph` behavior.
11+
- [#99](https://github.com/clojure-emacs/clojure-ts-mode/pull/99): Fix bug in `clojure-ts-align` when nested form has extra spaces.
12+
- [#99](https://github.com/clojure-emacs/clojure-ts-mode/pull/99): Fix bug in `clojure-ts-unwind` when there is only one expression after
13+
threading symbol.
1414

1515
## 0.4.0 (2025-05-15)
1616

clojure-ts-mode.el

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ if a third argument (the value) is provided.
470470
:*)
471471
(:match ,clojure-ts--interface-def-symbol-regexp @_def_symbol))))
472472

473-
(defconst clojure-ts--match-docstring-query-compiled
473+
(defconst clojure-ts--match-docstring-query
474474
(treesit-query-compile 'clojure (clojure-ts--docstring-query '@font-lock-doc-face))
475475
"Precompiled query that matches a Clojure docstring.")
476476

@@ -839,9 +839,14 @@ Skip the optional metadata node at pos 0 if present."
839839
t)))
840840

841841
(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."
845850
(treesit-node-child-by-field-name node "value"))
846851

847852
(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."
13631368
"Match PARENT when it is a docstring node."
13641369
(when-let* ((top-level-node (treesit-parent-until parent 'defun t))
13651370
(result (treesit-query-capture top-level-node
1366-
clojure-ts--match-docstring-query-compiled)))
1371+
clojure-ts--match-docstring-query)))
13671372
(seq-find (lambda (elt)
13681373
(and (eq (car elt) 'font-lock-doc-face)
13691374
(treesit-node-eq (cdr elt) parent)))
@@ -1529,6 +1534,9 @@ function literal."
15291534
`((clojure
15301535
(sexp ,(regexp-opt clojure-ts--sexp-nodes))
15311536
(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.
15321540
(sexp-default
15331541
;; For `C-M-f' in "#|(a)" or "#|{1 2 3}"
15341542
(,(rx (or "(" "{")) . ,#'clojure-ts--default-sexp-node-p))
@@ -2470,8 +2478,13 @@ before DELIM-OPEN."
24702478
"v0.24.3"))
24712479
"Intended to be used as the value for `treesit-language-source-alist'.")
24722480

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."
24752488
(treesit-query-valid-p 'clojure '((sym_lit (meta_lit)))))
24762489

24772490
(defun clojure-ts--ensure-grammars ()
@@ -2483,7 +2496,7 @@ before DELIM-OPEN."
24832496
;; If Clojure grammar is available, but outdated, re-install
24842497
;; it.
24852498
(and (equal grammar 'clojure)
2486-
(clojure-ts--grammar-outdated-p)))
2499+
(clojure-ts--clojure-grammar-outdated-p)))
24872500
(message "Installing %s Tree-sitter grammar" grammar)
24882501
;; `treesit-language-source-alist' is dynamically scoped.
24892502
;; Binding it in this let expression allows

test/samples/indentation.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@
228228
:foo
229229
"bar"}
230230

231-
;; NOTE: It works well now with the alternative grammar.
232231
'(one
233232
two ^:foo
234233
three)

0 commit comments

Comments
 (0)