Skip to content

Commit 050b9c2

Browse files
committed
Merge pull request #325 from clojure-emacs/declare-symbol-at-point
Give `ad` a prefix variant
2 parents a488350 + ed8e30c commit 050b9c2

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Up next
44

5+
- [#301] (https://github.com/clojure-emacs/clj-refactor.el/issues/301) `ad` has gained a prefix to declare the symbol under the cursor.
56
- [#312](https://github.com/clojure-emacs/clj-refactor.el/issues/312) Allow `sut` alias to be customized.
67
- [#305](https://github.com/clojure-emacs/clj-refactor.el/issues/305) Don't call lookup-alias for non namespaced keywords at all when slash is typed. However trigger lookup alias with the leading :: stripped off the prefix if the keyword is namespaced.
78

clj-refactor.el

+17-12
Original file line numberDiff line numberDiff line change
@@ -1430,23 +1430,28 @@ optionally including those that are declared private."
14301430
(re-search-backward def (cljr--point-after 'paredit-backward) :no-error)))
14311431

14321432
(defun cljr--add-declaration (def)
1433-
(cljr--goto-declare)
1434-
(backward-char)
1435-
(insert " " def)
1436-
(cljr--post-command-message "Added declaration for %s" def))
1433+
(when (cljr--already-declared-p def)
1434+
(user-error "%s is already declared" def))
1435+
(save-excursion
1436+
(cljr--goto-declare)
1437+
(backward-char)
1438+
(insert " " def)
1439+
(cljr--post-command-message "Added declaration for %s" def)))
14371440

14381441
;;;###autoload
1439-
(defun cljr-add-declaration ()
1442+
(defun cljr-add-declaration (for-thing-at-point-p)
14401443
"Add a declare for the current def near the top of the buffer.
14411444
1445+
With a prefix add a declaration for the symbol under the cursor instead.
1446+
14421447
See: https://github.com/clojure-emacs/clj-refactor.el/wiki/cljr-add-declaration"
1443-
(interactive)
1444-
(save-excursion
1445-
(-if-let (def (cljr--name-of-current-def))
1446-
(if (cljr--already-declared-p def)
1447-
(user-error "%s is already declared" def)
1448-
(cljr--add-declaration def))
1449-
(user-error "Not inside a def form."))))
1448+
(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.")))))
14501455

14511456
;; ------ extract constant ----------------
14521457

features/add-declaration.feature

+18
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,21 @@ Feature: Declare current top-level form
7171
[a b]
7272
(+ a b))
7373
"""
74+
75+
Scenario: Declare the thing at point
76+
When I insert:
77+
"""
78+
(ns cljr.core)
79+
80+
(foo :bar)
81+
"""
82+
And I place the cursor before " :bar"
83+
And I press "C-u C-! ad"
84+
Then I should see:
85+
"""
86+
(ns cljr.core)
87+
88+
(declare foo)
89+
90+
(foo :bar)
91+
"""

0 commit comments

Comments
 (0)