From ae678b30546e578cb271a9b3420994d10bfe7994 Mon Sep 17 00:00:00 2001 From: Roman Rudakov Date: Thu, 14 Aug 2025 21:48:19 +0200 Subject: [PATCH] Fix clojure-ts-add-arity bug when body has more than one expression --- CHANGELOG.md | 3 ++- clojure-ts-mode.el | 7 ++++++- test/clojure-ts-mode-refactor-add-arity-test.el | 16 ++++++++++++++++ test/samples/refactoring.clj | 3 ++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bfc74a..15087a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ - [#116](https://github.com/clojure-emacs/clojure-ts-mode/pull/116): Extend built-in completion to complete all imported symbols from an `ns` form. - Add documentation and bug reporting commands from `clojure-mode`. -- Add some ns manipulation functions from `clojure-mode`. +- [#118](https://github.com/clojure-emacs/clojure-ts-mode/pull/118): Add some ns manipulation functions from `clojure-mode`. +- Fix a bug in `clojure-ts-add-arity` when body has more than one expression. ## 0.5.1 (2025-06-17) diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el index bcb0107..3152e39 100644 --- a/clojure-ts-mode.el +++ b/clojure-ts-mode.el @@ -2325,7 +2325,12 @@ type, etc. See `treesit-thing-settings' for more details." (when same-line-p (newline-and-indent)) (when single-arity-p - (insert-pair 2 ?\( ?\)) + (save-excursion + (backward-up-list) + (forward-list) + (down-list -1) + (insert ")")) + (insert "(") (backward-up-list)) (insert "([])\n") ;; Put the point between square brackets. diff --git a/test/clojure-ts-mode-refactor-add-arity-test.el b/test/clojure-ts-mode-refactor-add-arity-test.el index f119607..10c0528 100644 --- a/test/clojure-ts-mode-refactor-add-arity-test.el +++ b/test/clojure-ts-mode-refactor-add-arity-test.el @@ -80,6 +80,22 @@ (clojure-ts-add-arity)) + (when-refactoring-with-point-it "should handle a single-arity defn with multiple body expressions" + "(defn fo|o + ^{:bla \"meta\"} + [arg] + body + second-expr)" + + "(defn foo + ^{:bla \"meta\"} + ([|]) + ([arg] + body + second-expr))" + + (clojure-ts-add-arity)) + (when-refactoring-with-point-it "should add an arity to a multi-arity defn" "(defn foo ([arg1]) diff --git a/test/samples/refactoring.clj b/test/samples/refactoring.clj index c2346ee..499d3e0 100644 --- a/test/samples/refactoring.clj +++ b/test/samples/refactoring.clj @@ -133,7 +133,8 @@ (defn foo ^{:bla "meta"} [arg] - body) + body + second-expr) (if ^boolean (= 2 2) true