Skip to content

Commit 32490c8

Browse files
rrudakovbbatsov
authored andcommitted
Fix clojure-ts-add-arity bug when body has more than one expression
1 parent ee94f1e commit 32490c8

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
- [#116](https://github.com/clojure-emacs/clojure-ts-mode/pull/116): Extend built-in completion to complete all imported symbols from an `ns`
1010
form.
1111
- Add documentation and bug reporting commands from `clojure-mode`.
12-
- Add some ns manipulation functions from `clojure-mode`.
12+
- [#118](https://github.com/clojure-emacs/clojure-ts-mode/pull/118): Add some ns manipulation functions from `clojure-mode`.
13+
- Fix a bug in `clojure-ts-add-arity` when body has more than one expression.
1314

1415
## 0.5.1 (2025-06-17)
1516

clojure-ts-mode.el

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,12 @@ type, etc. See `treesit-thing-settings' for more details."
23252325
(when same-line-p
23262326
(newline-and-indent))
23272327
(when single-arity-p
2328-
(insert-pair 2 ?\( ?\))
2328+
(save-excursion
2329+
(backward-up-list)
2330+
(forward-list)
2331+
(down-list -1)
2332+
(insert ")"))
2333+
(insert "(")
23292334
(backward-up-list))
23302335
(insert "([])\n")
23312336
;; Put the point between square brackets.

test/clojure-ts-mode-refactor-add-arity-test.el

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@
8080

8181
(clojure-ts-add-arity))
8282

83+
(when-refactoring-with-point-it "should handle a single-arity defn with multiple body expressions"
84+
"(defn fo|o
85+
^{:bla \"meta\"}
86+
[arg]
87+
body
88+
second-expr)"
89+
90+
"(defn foo
91+
^{:bla \"meta\"}
92+
([|])
93+
([arg]
94+
body
95+
second-expr))"
96+
97+
(clojure-ts-add-arity))
98+
8399
(when-refactoring-with-point-it "should add an arity to a multi-arity defn"
84100
"(defn foo
85101
([arg1])

test/samples/refactoring.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@
133133
(defn foo
134134
^{:bla "meta"}
135135
[arg]
136-
body)
136+
body
137+
second-expr)
137138

138139
(if ^boolean (= 2 2)
139140
true

0 commit comments

Comments
 (0)