Skip to content

Commit 832cc5c

Browse files
rrudakovbbatsov
authored andcommitted
Speed-up docstrings matching by pre-compiling regexps
1 parent 65c2fd7 commit 832cc5c

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +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.
814

915
## 0.4.0 (2025-05-15)
1016

clojure-ts-mode.el

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -371,18 +371,22 @@ Only intended for use at development time.")
371371
"Return a regular expression that matches one of SYMBOLS exactly."
372372
(concat "^" (regexp-opt symbols) "$"))
373373

374-
(defvar clojure-ts-function-docstring-symbols
375-
'("definline"
376-
"defmulti"
377-
"defmacro"
378-
"defn"
379-
"defn-"
380-
"defprotocol"
381-
"ns")
374+
(defconst clojure-ts-function-docstring-symbols
375+
(eval-and-compile
376+
(rx line-start
377+
(or "definline"
378+
"defmulti"
379+
"defmacro"
380+
"defn"
381+
"defn-"
382+
"defprotocol"
383+
"ns")
384+
line-end))
382385
"Symbols that accept an optional docstring as their second argument.")
383386

384-
(defvar clojure-ts-definition-docstring-symbols
385-
'("def")
387+
(defconst clojure-ts-definition-docstring-symbols
388+
(eval-and-compile
389+
(rx line-start "def" line-end))
386390
"Symbols that accept an optional docstring as their second argument.
387391
Any symbols added here should only treat their second argument as a docstring
388392
if a third argument (the value) is provided.
@@ -428,7 +432,7 @@ if a third argument (the value) is provided.
428432
:anchor (str_lit (str_content) ,capture-symbol) @font-lock-doc-face
429433
;; The variable's value
430434
:anchor (_))
431-
(:match ,(clojure-ts-symbol-regexp clojure-ts-definition-docstring-symbols)
435+
(:match ,clojure-ts-definition-docstring-symbols
432436
@_def_symbol))
433437
;; Captures docstrings in metadata of definitions
434438
((list_lit :anchor [(comment) (meta_lit) (old_meta_lit)] :*
@@ -456,7 +460,7 @@ if a third argument (the value) is provided.
456460
:anchor (sym_lit)
457461
:anchor [(comment) (meta_lit) (old_meta_lit)] :*
458462
:anchor (str_lit (str_content) ,capture-symbol) @font-lock-doc-face)
459-
(:match ,(clojure-ts-symbol-regexp clojure-ts-function-docstring-symbols)
463+
(:match ,clojure-ts-function-docstring-symbols
460464
@_def_symbol))
461465
;; Captures docstrings in defprotcol, definterface
462466
((list_lit :anchor [(comment) (meta_lit) (old_meta_lit)] :*
@@ -1498,7 +1502,15 @@ function literal."
14981502
"definline"
14991503
"defrecord"
15001504
"defmacro"
1501-
"defmulti")
1505+
"defmulti"
1506+
"defonce"
1507+
"defprotocol"
1508+
"deftest"
1509+
"deftest-"
1510+
"ns"
1511+
"definterface"
1512+
"deftype"
1513+
"defstruct")
15021514
eol)))
15031515

15041516
(defconst clojure-ts--markdown-inline-sexp-nodes
@@ -1509,7 +1521,7 @@ function literal."
15091521

15101522
(defun clojure-ts--default-sexp-node-p (node)
15111523
"Return TRUE if point is after the # marker of set or function literal NODE."
1512-
(and (eq (char-before (point)) ?\#)
1524+
(and (eq (char-before) ?\#)
15131525
(string-match-p (rx bol (or "anon_fn_lit" "set_lit") eol)
15141526
(treesit-node-type (treesit-node-parent node)))))
15151527

test/clojure-ts-mode-refactor-threading-test.el

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@
205205
(clojure-ts-unwind)
206206
(clojure-ts-unwind))
207207

208+
(when-refactoring-it "should work correctly when there is only one expression"
209+
"(->> (filter even? [1 2 3 4]))"
210+
211+
"(filter even? [1 2 3 4])"
212+
213+
(clojure-ts-unwind))
214+
208215
(when-refactoring-it "should unwind N steps with numeric prefix arg"
209216
"(->> [1 2 3 4 5]
210217
(filter even?)

0 commit comments

Comments
 (0)