Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 101 lines (81 sloc) 3.027 kB
68d81a7 @scgilardi update my contribs to Eclipse Public License as requested
scgilardi authored
1 ;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and
2 ;; distribution terms for this software are covered by the Eclipse Public
3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
4 ;; be found in the file epl-v10.html at the root of this distribution. By
5 ;; using this software in any fashion, you are agreeing to be bound by the
6 ;; terms of this license. You must not remove this notice, or any other,
7 ;; from this software.
df1b195 marking deprecations in ns-utils
Aaron Bedra and Stuart Halloway authored
8
6f7a77e @scgilardi first cut at changes for Clojure SVN 1094+, my contribs and ones they…
scgilardi authored
9 ;; scgilardi (gmail)
10 ;; 23 April 2008
11
df1b195 marking deprecations in ns-utils
Aaron Bedra and Stuart Halloway authored
12 ;; DEPRECATED in 1.2: dir and print-dir. Use dir and dir-fn in
13 ;; clojure.repl.
14
86e9001 @tomfaulhaber Lots 'o doc strings
tomfaulhaber authored
15 (ns
b8d2743 use the 1.2 metadata reader macro ^ instead of #^
Aaron Bedra and Stuart Halloway authored
16 ^{:author "Stephen C. Gilardi",
df1b195 marking deprecations in ns-utils
Aaron Bedra and Stuart Halloway authored
17 :doc "Namespace utilities
18
19 get-ns returns the namespace named by a symbol or throws
20 if the namespace does not exist
21
22 ns-vars returns a sorted seq of symbols naming public vars
23 in a namespace
24
25 print-docs prints documentation for the public vars in a
26 namespace
27
28 immigrate Create a public var in this namespace for each
29 public var in the namespaces named by ns-names.
30 From James Reeves
31
32 vars returns a sorted seq of symbols naming public vars
33 in a namespace (macro)
34
35 docs prints documentation for the public vars in a
36 namespace (macro)"}
86e9001 @tomfaulhaber Lots 'o doc strings
tomfaulhaber authored
37 clojure.contrib.ns-utils
6f7a77e @scgilardi first cut at changes for Clojure SVN 1094+, my contribs and ones they…
scgilardi authored
38 (:use clojure.contrib.except))
39
40 ;; Namespace Utilities
41
42 (defn get-ns
43 "Returns the namespace named by ns-sym or throws if the
44 namespace does not exist"
45 [ns-sym]
46 (let [ns (find-ns ns-sym)]
47 (throw-if (not ns) "Unable to find namespace: %s" ns-sym)
48 ns))
49
50 (defn ns-vars
51 "Returns a sorted seq of symbols naming public vars in
52 a namespace"
53 [ns]
54 (sort (map first (ns-publics ns))))
55
56 (defn print-dir
57 "Prints a sorted directory of public vars in a namespace"
df1b195 marking deprecations in ns-utils
Aaron Bedra and Stuart Halloway authored
58 {:deprecated "1.2"}
6f7a77e @scgilardi first cut at changes for Clojure SVN 1094+, my contribs and ones they…
scgilardi authored
59 [ns]
60 (doseq [item (ns-vars ns)]
61 (println item)))
62
63 (defn print-docs
64 "Prints documentation for the public vars in a namespace"
65 [ns]
66 (doseq [item (ns-vars ns)]
67 (print-doc (ns-resolve ns item))))
68
69 ;; Convenience
70
71 (defmacro vars
72 "Returns a sorted seq of symbols naming public vars in
73 a namespace"
74 [nsname]
75 `(ns-vars (get-ns '~nsname)))
76
77 (defmacro dir
78 "Prints a sorted directory of public vars in a namespace"
df1b195 marking deprecations in ns-utils
Aaron Bedra and Stuart Halloway authored
79 {:deprecated "1.2"}
6f7a77e @scgilardi first cut at changes for Clojure SVN 1094+, my contribs and ones they…
scgilardi authored
80 [nsname]
81 `(print-dir (get-ns '~nsname)))
82
83 (defmacro docs
84 "Prints documentation for the public vars in a namespace"
85 [nsname]
86 `(print-docs (get-ns '~nsname)))
cf4790b added test-expect source, renamed namespaces for contrib
Aaron Bedra and Stuart Halloway authored
87
88 (defn immigrate
3a220e3 @scgilardi modify immigrate to operate on root bindings rather than current bind…
scgilardi authored
89 "Create a public var in this namespace for each public var in the
90 namespaces named by ns-names. The created vars have the same name, root
91 binding, and metadata as the original except that their :ns metadata
92 value is this namespace."
93 [& ns-names]
94 (doseq [ns ns-names]
95 (require ns)
96 (doseq [[sym var] (ns-publics ns)]
97 (let [sym (with-meta sym (assoc (meta var) :ns *ns*))]
98 (if (.hasRoot var)
99 (intern *ns* sym (.getRoot var))
100 (intern *ns* sym))))))
Something went wrong with that request. Please try again.