Skip to content

Commit

Permalink
CLJ-1673 Improve clojure.repl/dir-fn.
Browse files Browse the repository at this point in the history
dir-fn will now work on namespace aliases in addition to canonical
namespaces. Add test for same, compatible with direct linking,
introduced in Clojure 1.8.0-alpha3.

Signed-off-by: Stuart Halloway <[email protected]>
  • Loading branch information
jwhitlark authored and stuarthalloway committed Sep 7, 2016
1 parent edf869a commit 1318655
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/clj/clojure/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ str-or-pattern."

(defn dir-fn
"Returns a sorted seq of symbols naming public vars in
a namespace"
a namespace or namespace alias. Looks for aliases in *ns*"
[ns]
(sort (map first (ns-publics (the-ns ns)))))
(sort (map first (ns-publics (the-ns (get (ns-aliases *ns*) ns ns))))))

(defmacro dir
"Prints a sorted directory of public vars in a namespace"
Expand Down
2 changes: 2 additions & 0 deletions test/clojure/test_clojure/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
(deftest test-dir
(is (thrown? Exception (dir-fn 'non-existent-ns)))
(is (= '[bar foo] (dir-fn 'clojure.test-clojure.repl.example)))
(binding [*ns* (the-ns 'clojure.test-clojure.repl)]
(is (= (dir-fn 'clojure.string) (dir-fn 'str))))
(is (= (platform-newlines "bar\nfoo\n") (with-out-str (dir clojure.test-clojure.repl.example)))))

(deftest test-apropos
Expand Down

0 comments on commit 1318655

Please sign in to comment.