Skip to content

Commit 21caa3e

Browse files
committed
Added doc string to ns macro, patch from mb
1 parent 92a2a04 commit 21caa3e

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/clj/clojure/core.clj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,13 @@
27622762
(println type)
27632763
(println (str " Please see http://clojure.org/special_forms#" anchor)))
27642764

2765+
(defn print-namespace-doc
2766+
"Print the documentation string of a Namespace."
2767+
[nspace]
2768+
(println "-------------------------")
2769+
(println (str (ns-name nspace)))
2770+
(println " " (:doc ^nspace)))
2771+
27652772
(defmacro doc
27662773
"Prints documentation for a var or special form given its name"
27672774
[name]
@@ -2771,7 +2778,10 @@
27712778
(syntax-symbol-anchor `~name)
27722779
`(print-special-doc '~name "Syntax Symbol" (syntax-symbol-anchor '~name))
27732780
:else
2774-
`(print-doc (var ~name))))
2781+
(let [nspace (find-ns name)]
2782+
(if nspace
2783+
`(print-namespace-doc ~nspace)
2784+
`(print-doc (var ~name))))))
27752785

27762786
(defn tree-seq
27772787
"returns a lazy sequence of the nodes in a tree, via a depth-first walk.
@@ -3319,6 +3329,12 @@
33193329
(fn [[kname & args]]
33203330
`(~(symbol "clojure.core" (clojure.core/name kname))
33213331
~@(map #(list 'quote %) args)))
3332+
docstring (when (string? (first references)) (first references))
3333+
references (if docstring (rest references) references)
3334+
name (if docstring
3335+
(with-meta name (assoc (meta name)
3336+
:doc docstring))
3337+
name)
33223338
gen-class-clause (first (filter #(= :gen-class (first %)) references))
33233339
gen-class-call
33243340
(when gen-class-clause
@@ -3789,7 +3805,7 @@
37893805
~(emit gpred gexpr clauses))))
37903806

37913807
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; helper files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3792-
3808+
(alter-meta! (find-ns 'clojure.core) assoc :doc "Fundamental library of the Clojure language")
37933809
(load "core_proxy")
37943810
(load "core_print")
37953811
(load "genclass")

src/jvm/clojure/lang/Namespace.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public String toString(){
2727
}
2828

2929
Namespace(Symbol name){
30+
super(name.meta());
3031
this.name = name;
3132
mappings.set(RT.DEFAULT_IMPORTS);
3233
aliases.set(RT.map());
@@ -174,4 +175,4 @@ public void removeAlias(Symbol alias) throws Exception{
174175
map = getAliases();
175176
}
176177
}
177-
}
178+
}

0 commit comments

Comments
 (0)