File tree 2 files changed +58
-11
lines changed
2 files changed +58
-11
lines changed Original file line number Diff line number Diff line change @@ -2740,10 +2740,10 @@ With a numeric prefix argument the let is introduced N lists up."
2740
2740
(defun clojure-add-arity ()
2741
2741
" Add an arity to a function."
2742
2742
(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 ))))
2747
2747
(down-list 2 )
2748
2748
(when (looking-back " {" 1 ) ; ; skip metadata if present
2749
2749
(up-list )
@@ -2757,16 +2757,15 @@ With a numeric prefix argument the let is introduced N lists up."
2757
2757
(let* ((bol (save-excursion (beginning-of-line ) (point )))
2758
2758
(same-line (save-excursion (re-search-backward " defn" bol t )))
2759
2759
(new-arity-text (concat (when same-line " \n " ) " ([])\n [" )))
2760
- (re-search-backward " +\\ [" )
2761
- (replace-match new-arity-text)
2762
2760
(save-excursion
2763
- (end-of-defun )
2764
- (re-search-backward " )" )
2761
+ (goto-char end)
2765
2762
(insert " )" ))
2766
- (left-char )
2767
- (insert " (" )
2763
+
2764
+ (re-search-backward " +\\ [" )
2765
+ (replace-match new-arity-text)
2766
+
2768
2767
(indent-region beg end)
2769
- (left-char 6 ))))))
2768
+ (left-char 7 ))))))
2770
2769
2771
2770
2772
2771
; ;; ClojureScript
Original file line number Diff line number Diff line change @@ -149,6 +149,54 @@ DESCRIPTION is a string with the description of the spec."
149
149
([arg]
150
150
body))"
151
151
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
+
152
200
(clojure-add-arity)))
153
201
154
202
(provide 'clojure-mode-refactor-add-arity-test )
You can’t perform that action at this time.
0 commit comments