branch: elpa/clojure-ts-mode
commit 832cc5c127f64162ca72cff4a2e943a6d3a259b6
Author: Roman Rudakov <rruda...@fastmail.com>
Commit: Bozhidar Batsov <bozhi...@batsov.dev>

    Speed-up docstrings matching by pre-compiling regexps
---
 CHANGELOG.md                                    |  6 ++++
 clojure-ts-mode.el                              | 40 ++++++++++++++++---------
 test/clojure-ts-mode-refactor-threading-test.el |  7 +++++
 3 files changed, 39 insertions(+), 14 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4022bcba70..18eb45ed74 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@
 - [#96](https://github.com/clojure-emacs/clojure-ts-mode/pull/96): Highlight 
function name properly in `extend-protocol` form.
 - [#96](https://github.com/clojure-emacs/clojure-ts-mode/pull/96): Add support 
for extend-protocol forms to `clojure-ts-add-arity` refactoring
   command.
+- Improve navigation by s-expression by switching to an experimental Clojure
+  grammar.
+- More consistent docstrings highlighting and `fill-paragraph` behavior.
+- Fix bug in `clojure-ts-align` when nested form has extra spaces.
+- Fix bug in `clojure-ts-unwind` when there is only one expression after 
threading
+  symbol.
 
 ## 0.4.0 (2025-05-15)
 
diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el
index ba6380d883..53e8ffb182 100644
--- a/clojure-ts-mode.el
+++ b/clojure-ts-mode.el
@@ -371,18 +371,22 @@ Only intended for use at development time.")
   "Return a regular expression that matches one of SYMBOLS exactly."
   (concat "^" (regexp-opt symbols) "$"))
 
-(defvar clojure-ts-function-docstring-symbols
-  '("definline"
-    "defmulti"
-    "defmacro"
-    "defn"
-    "defn-"
-    "defprotocol"
-    "ns")
+(defconst clojure-ts-function-docstring-symbols
+  (eval-and-compile
+    (rx line-start
+        (or "definline"
+            "defmulti"
+            "defmacro"
+            "defn"
+            "defn-"
+            "defprotocol"
+            "ns")
+        line-end))
   "Symbols that accept an optional docstring as their second argument.")
 
-(defvar clojure-ts-definition-docstring-symbols
-  '("def")
+(defconst clojure-ts-definition-docstring-symbols
+  (eval-and-compile
+    (rx line-start "def" line-end))
   "Symbols that accept an optional docstring as their second argument.
 Any symbols added here should only treat their second argument as a docstring
 if a third argument (the value) is provided.
@@ -428,7 +432,7 @@ if a third argument (the value) is provided.
                :anchor (str_lit (str_content) ,capture-symbol) 
@font-lock-doc-face
                ;; The variable's value
                :anchor (_))
-     (:match ,(clojure-ts-symbol-regexp 
clojure-ts-definition-docstring-symbols)
+     (:match ,clojure-ts-definition-docstring-symbols
              @_def_symbol))
     ;; Captures docstrings in metadata of definitions
     ((list_lit :anchor [(comment) (meta_lit) (old_meta_lit)] :*
@@ -456,7 +460,7 @@ if a third argument (the value) is provided.
                :anchor (sym_lit)
                :anchor [(comment) (meta_lit) (old_meta_lit)] :*
                :anchor (str_lit (str_content) ,capture-symbol) 
@font-lock-doc-face)
-     (:match ,(clojure-ts-symbol-regexp clojure-ts-function-docstring-symbols)
+     (:match ,clojure-ts-function-docstring-symbols
              @_def_symbol))
     ;; Captures docstrings in defprotcol, definterface
     ((list_lit :anchor [(comment) (meta_lit) (old_meta_lit)] :*
@@ -1498,7 +1502,15 @@ function literal."
                                              "definline"
                                              "defrecord"
                                              "defmacro"
-                                             "defmulti")
+                                             "defmulti"
+                                             "defonce"
+                                             "defprotocol"
+                                             "deftest"
+                                             "deftest-"
+                                             "ns"
+                                             "definterface"
+                                             "deftype"
+                                             "defstruct")
                                          eol)))
 
 (defconst clojure-ts--markdown-inline-sexp-nodes
@@ -1509,7 +1521,7 @@ function literal."
 
 (defun clojure-ts--default-sexp-node-p (node)
   "Return TRUE if point is after the # marker of set or function literal NODE."
-  (and (eq (char-before (point)) ?\#)
+  (and (eq (char-before) ?\#)
        (string-match-p (rx bol (or "anon_fn_lit" "set_lit") eol)
                        (treesit-node-type (treesit-node-parent node)))))
 
diff --git a/test/clojure-ts-mode-refactor-threading-test.el 
b/test/clojure-ts-mode-refactor-threading-test.el
index ce26d5d02c..35e1ebba0c 100644
--- a/test/clojure-ts-mode-refactor-threading-test.el
+++ b/test/clojure-ts-mode-refactor-threading-test.el
@@ -205,6 +205,13 @@
     (clojure-ts-unwind)
     (clojure-ts-unwind))
 
+  (when-refactoring-it "should work correctly when there is only one 
expression"
+    "(->> (filter even? [1 2 3 4]))"
+
+    "(filter even? [1 2 3 4])"
+
+    (clojure-ts-unwind))
+
   (when-refactoring-it "should unwind N steps with numeric prefix arg"
     "(->> [1 2 3 4 5]
      (filter even?)

Reply via email to