Skip to content

Commit c37b24d

Browse files
Enhance declare thing at point
If we are outside a def we default to declare thing at point as discussed on #325. The prefix is still needed to declare thing at point if inside a def.
1 parent a2a8355 commit c37b24d

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

clj-refactor.el

+4-6
Original file line numberDiff line numberDiff line change
@@ -1446,12 +1446,10 @@ With a prefix add a declaration for the symbol under the cursor instead.
14461446

14471447
See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-add-declaration"
14481448
(interactive "P")
1449-
(if for-thing-at-point-p
1450-
(cljr--add-declaration (cider-symbol-at-point))
1451-
(save-excursion
1452-
(-if-let (def (cljr--name-of-current-def))
1453-
(cljr--add-declaration def)
1454-
(user-error "Not inside a def form.")))))
1449+
(-if-let (def (and (not for-thing-at-point-p)
1450+
(save-excursion (cljr--name-of-current-def))))
1451+
(cljr--add-declaration def)
1452+
(cljr--add-declaration (cider-symbol-at-point))))
14551453

14561454
;; ------ extract constant ----------------
14571455

features/add-declaration.feature

+26-2
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ Feature: Declare current top-level form
7272
(+ a b))
7373
"""
7474

75-
Scenario: Declare the thing at point
75+
Scenario: Declare the thing at point if outside a def
7676
When I insert:
7777
"""
7878
(ns cljr.core)
7979
8080
(foo :bar)
8181
"""
8282
And I place the cursor before " :bar"
83-
And I press "C-u C-! ad"
83+
And I press "C-! ad"
8484
Then I should see:
8585
"""
8686
(ns cljr.core)
@@ -89,3 +89,27 @@ Feature: Declare current top-level form
8989
9090
(foo :bar)
9191
"""
92+
93+
Scenario: Declare the thing at point if inside a def
94+
When I insert:
95+
"""
96+
(ns cljr.core)
97+
98+
(declare foo)
99+
100+
(defn- ^{:meta :data} add
101+
[a b]
102+
(bar a b))
103+
"""
104+
And I place the cursor before " a b"
105+
And I press "C-u C-! ad"
106+
Then I should see:
107+
"""
108+
(ns cljr.core)
109+
110+
(declare foo bar)
111+
112+
(defn- ^{:meta :data} add
113+
[a b]
114+
(bar a b))
115+
"""

0 commit comments

Comments
 (0)