Skip to content

Commit 1513020

Browse files
committed
Add reader conditional support to the add arity refactoring.
1 parent 721287c commit 1513020

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

clojure-mode.el

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,10 +2740,10 @@ With a numeric prefix argument the let is introduced N lists up."
27402740
(defun clojure-add-arity ()
27412741
"Add an arity to a function."
27422742
(interactive)
2743-
(let ((end (save-excursion (end-of-defun)
2744-
(point)))
2745-
(beg (progn (beginning-of-defun)
2746-
(point))))
2743+
(let ((beg (progn (re-search-backward "(defn")
2744+
(point)))
2745+
(end (save-excursion (forward-sexp)
2746+
(point))))
27472747
(down-list 2)
27482748
(when (looking-back "{" 1) ;; skip metadata if present
27492749
(up-list)
@@ -2757,16 +2757,15 @@ With a numeric prefix argument the let is introduced N lists up."
27572757
(let* ((bol (save-excursion (beginning-of-line) (point)))
27582758
(same-line (save-excursion (re-search-backward "defn" bol t)))
27592759
(new-arity-text (concat (when same-line "\n") "([])\n[")))
2760-
(re-search-backward " +\\[")
2761-
(replace-match new-arity-text)
27622760
(save-excursion
2763-
(end-of-defun)
2764-
(re-search-backward ")")
2761+
(goto-char end)
27652762
(insert ")"))
2766-
(left-char)
2767-
(insert "(")
2763+
2764+
(re-search-backward " +\\[")
2765+
(replace-match new-arity-text)
2766+
27682767
(indent-region beg end)
2769-
(left-char 6))))))
2768+
(left-char 7))))))
27702769

27712770

27722771
;;; ClojureScript

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,54 @@ DESCRIPTION is a string with the description of the spec."
149149
([arg]
150150
body))"
151151

152+
(clojure-add-arity))
153+
154+
(when-refactoring-with-point-it "should handle a defn inside a reader conditional"
155+
"#?(:clj
156+
(defn foo
157+
\"some docstring\"
158+
^{:bla \"meta\"}
159+
|([arg]
160+
body)))"
161+
162+
"#?(:clj
163+
(defn foo
164+
\"some docstring\"
165+
^{:bla \"meta\"}
166+
([|])
167+
([arg]
168+
body)))"
169+
170+
(clojure-add-arity))
171+
172+
(when-refactoring-with-point-it "should handle a defn inside a reader conditional with 2 platform tags"
173+
"#?(:clj
174+
(defn foo
175+
\"some docstring\"
176+
^{:bla \"meta\"}
177+
|([arg]
178+
body))
179+
:cljs
180+
(defn foo
181+
\"some docstring\"
182+
^{:bla \"meta\"}
183+
([arg]
184+
body)))"
185+
186+
"#?(:clj
187+
(defn foo
188+
\"some docstring\"
189+
^{:bla \"meta\"}
190+
([|])
191+
([arg]
192+
body))
193+
:cljs
194+
(defn foo
195+
\"some docstring\"
196+
^{:bla \"meta\"}
197+
([arg]
198+
body)))"
199+
152200
(clojure-add-arity)))
153201

154202
(provide 'clojure-mode-refactor-add-arity-test)

0 commit comments

Comments
 (0)