Skip to content

Commit abadad9

Browse files
[Fix #362] clean-ns: Preserve all shorthand style metadata
1 parent 6315889 commit abadad9

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [clojure-emacs/clj-refactor.el#330](https://github.com/clojure-emacs/clj-refactor.el/issues/332) `clean-ns` removes imported inner inner classes.
1212
* [clojure-emacs/clj-refactor.el#330](https://github.com/clojure-emacs/clj-refactor.el/issues/330) `clean-ns` ignores namespaced keywords.
1313
* [#160](https://github.com/clojure-emacs/refactor-nrepl/issues/160) Make `resolve-missing` find newly defined vars and types (clj). Because of a stale cache, newly added vars or types would not be found. This fix takes into account vars/types added by eval-ing code (rescan affected namespace), and by hotloading dependencies (reset the cache).
14+
* [#362](https://github.com/clojure-emacs/refactor-nrepl/issues/362) Preserve all shorthand style metadata when `clean-ns` is used.
1415

1516
### Changes
1617

src/refactor_nrepl/core.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@
261261
(PushbackReader.)
262262
parse/read-ns-decl
263263
second)
264-
shorthand-meta? (second (re-find #"\^:([^\s]+)\s" ns-string))]
264+
shorthand-meta? (re-seq #"\^:([^\s]+)\s" ns-string)]
265265
(cond
266266
(map? meta?) meta?
267-
shorthand-meta? {::shorthand-meta (keyword shorthand-meta?)}
267+
shorthand-meta? {::shorthand-meta-coll (map (comp keyword second) shorthand-meta?)}
268268
:else nil)))
269269

270270
(defn read-ns-form-with-meta

src/refactor_nrepl/ns/pprint.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@
7878

7979
(defn pprint-meta
8080
[m]
81-
(if-let [shorthand-meta (::core/shorthand-meta m)]
82-
(print (str "^" shorthand-meta " "))
81+
(if-let [shorthand-meta-coll (::core/shorthand-meta-coll m)]
82+
(doseq [shorthand-meta shorthand-meta-coll]
83+
(print (str "^" shorthand-meta " ")))
8384
(printf (.replaceAll (str "^" (into (sorted-map) m) "\n")
8485
", " "\n"))))
8586

test/refactor_nrepl/ns/clean_ns_test.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
(def ns-with-shorthand-meta (clean-msg "test/resources/ns_with_shorthand_meta.clj"))
4141

42+
(def ns-with-multiple-shorthand-meta (clean-msg "test/resources/ns_with_multiple_shorthand_meta.clj"))
43+
4244
(deftest combines-requires
4345
(let [requires (core/get-ns-component (clean-ns ns2) :require)
4446
combined-requires (core/get-ns-component ns2-cleaned :require)]
@@ -192,3 +194,8 @@
192194
(deftest preserves-shorthand-meta
193195
(let [cleaned (pprint-ns (clean-ns ns-with-shorthand-meta))]
194196
(is (re-find #"\^:automation" cleaned))))
197+
198+
(deftest preservres-multiple-shortand-meta
199+
(let [cleaned (pprint-ns (clean-ns ns-with-multiple-shorthand-meta))]
200+
(is (re-find #"\^:automation" cleaned))
201+
(is (re-find #"\^:multiple" cleaned))))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(ns ^:automation ^:multiple ns-with-multiple-shorthand-meta
2+
(:require [clojure.string]))

0 commit comments

Comments
 (0)