Skip to content

Commit 47a9a5c

Browse files
authored
Expand cljr magic require namespaces documentation (#555)
* alias `edn` to clojure.edn * Add minimal documentation of `:only` keyword * limit `io` to `clj` * backport `:only` keyword support for `cljr-magic-require-namespaces` This is handled by the suggest-libspec middleware automatically, so should not be user visible on latest versions. However, if cljr-slash-uses-suggest-libspec is disabled, the alist format was broken with an :only keyword when parsed by cljr--magic-requires-lookup-alias. This fixes that lookup and extracts the libspec from the first element of the list if it's not a dotted pair.
1 parent 0a2a6cb commit 47a9a5c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
* [#555](https://github.com/clojure-emacs/clj-refactor.el/pull/555): expand default `cljr-magic-require-namespaces` aliases.
6+
* Handle an edge case for `cljr-slash`.
7+
58
## 3.11.0
69

710
* [#554](https://github.com/clojure-emacs/clj-refactor.el/pull/554): Enable `cljr-slash-uses-suggest-libspec` by default.

clj-refactor.el

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,17 @@ paths once this flag is removed."
9191
:safe #'booleanp)
9292

9393
(defcustom cljr-magic-require-namespaces
94-
'(("io" . "clojure.java.io")
94+
'(("edn" . "clojure.edn")
95+
("io" "clojure.java.io" :only ("clj"))
9596
("math" . "clojure.math")
9697
("set" . "clojure.set")
9798
("str" . "clojure.string")
9899
("walk" . "clojure.walk")
99100
("zip" . "clojure.zip"))
100-
"Alist of aliases and namespaces used by `cljr-slash'."
101+
"Alist of aliases to namespace libspec recommendations for `\\[cljr-slash]'.
102+
103+
An optional keyword `:only` can limit a recommendation to the set of
104+
language contexts (clj, cljs) the libspec is available in."
101105
:type '(repeat (cons (string :tag "Short alias")
102106
(string :tag "Full namespace")))
103107
:safe #'listp)
@@ -2103,8 +2107,13 @@ match. Returns a structure of (alias (ns1 ns2 ...))."
21032107
(string-match-p (cljr--magic-requires-re) short))
21042108
;; This when-let might seem unnecessary but the regexp match
21052109
;; isn't perfect.
2106-
(when-let (long (cljr--aget cljr-magic-require-namespaces short))
2107-
(list short (list long))))))
2110+
(let ((long (cljr--aget cljr-magic-require-namespaces short)))
2111+
(when-let (libspec (cond ((stringp long)
2112+
(list long))
2113+
;; handle ("io" "clojure.java.io" :only ("clj"))
2114+
((and (listp long) (stringp (car long)))
2115+
(list (car long)))))
2116+
(list short libspec))))))
21082117

21092118
(defun cljr--in-keyword-sans-alias-p ()
21102119
"Checks if thing at point is keyword without an alias."

0 commit comments

Comments
 (0)