Skip to content

Commit a82ce55

Browse files
committed
[Fix clojure-emacs#103] Prefix forms using lists
These are allowed even though they are unidiomatic. Still, we should support them, and rewrite the code so the user doesn't have to manually spend time adhering to convention. This used to work, but I introduced a regression when I rewrote the ns-parser and eliminated the instaparse dependency. The tests have been updated to guard against this regression happening again.
1 parent 1a9b181 commit a82ce55

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/refactor_nrepl/ns/helpers.clj

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
(symbol? thing)))
1010

1111
(defn prefix-form?
12-
"True if the vector is of the form [prefix libspec1 libspec2...]"
13-
[v]
14-
(and (vector? v)
15-
(symbol? (first v))
16-
(not-any? keyword? v)
17-
(> (count v) 1)
18-
(every? libspec? (rest v))))
12+
"Does the form represent a libspec using prefix notation
13+
like: [prefix libspec1 libspec2 ...] ?"
14+
[form]
15+
(and (or (list? form) (vector? form))
16+
(symbol? (first form))
17+
(not-any? keyword? form)
18+
(> (count form) 1)
19+
(every? libspec? (rest form))))
1920

2021
(defn index-of-component [ns-form type]
2122
(first (keep-indexed #(when (and (sequential? %2) (= (first %2) type)) %1)

src/refactor_nrepl/ns/ns_parser.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
{:ns (symbol libspec)}))
1919

2020
(defn- expand-prefix-specs
21-
"Eliminate prefix vectors."
21+
"Eliminate prefix lists."
2222
[libspecs]
23-
(let [add-prefix (fn add-prefix [prefix libspec]
24-
(if (vector? libspec)
23+
(let [prepend-prefix (fn add-prefix [prefix libspec]
24+
(if (prefix-form? libspec)
2525
(apply vector
2626
(str prefix "." (first libspec))
2727
(rest libspec))
2828
(str prefix "." libspec)))
2929
normalize-libspec-vector (fn [libspec]
3030
(if (prefix-form? libspec)
3131
(let [prefix (first libspec)]
32-
(map (partial add-prefix prefix)
32+
(map (partial prepend-prefix prefix)
3333
(rest libspec)))
3434
[libspec]))]
3535
(mapcat normalize-libspec-vector libspecs)))

test/resources/ns1.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
(:require
1010
[clojure.instant :as inst :refer [read-instant-date]]
1111
[clojure.walk :refer [prewalk postwalk]]
12-
[clojure data edn]
12+
(clojure data edn)
1313
[clojure.pprint :refer [get-pretty-writer formatter cl-format]]
1414
clojure.test.junit
1515
[clojure.xml])

0 commit comments

Comments
 (0)