summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-09-19 15:36:48 +0000
committerRich Hickey <richhickey@gmail.com>2008-09-19 15:36:48 +0000
commit25d8907f1ad42056ea57ec78141a2b7d34e0c897 (patch)
tree266ef5a9fb6510b99580f158bfbca6f4a58544f7 /src
parentb5351ce1c2eb466376dae750658c67a6b6df7213 (diff)
doc support for special vars, patch from Stephen C. Gilardi
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/boot.clj32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj
index 283f0b04..4645abf3 100644
--- a/src/clj/clojure/boot.clj
+++ b/src/clj/clojure/boot.clj
@@ -2409,10 +2409,36 @@
(re-find (re-matcher re (str (:name ^v))))))]
(print-doc v)))))
+(defn special-form-anchor
+ "Returns the anchor tag on http://clojure.org/special_forms for the
+ special form x, or nil"
+ [x]
+ (#{'. 'def 'do 'fn 'if 'let 'loop 'monitor-enter 'monitor-exit 'new
+ 'quote 'recur 'set! 'throw 'try 'var} x))
+
+(defn syntax-symbol-anchor
+ "Returns the anchor tag on http://clojure.org/special_forms for the
+ special form that uses syntax symbol x, or nil"
+ [x]
+ ({'& 'fn 'catch 'try 'finally 'try} x))
+
+(defn print-special-doc
+ [name type anchor]
+ (println "-------------------------")
+ (println name)
+ (println type)
+ (println (str " Please see http://clojure.org/special_forms#" anchor)))
+
(defmacro doc
- "Prints documentation for the var named by varname"
- [varname]
- `(print-doc (var ~varname)))
+ "Prints documentation for a var or special form given its name"
+ [name]
+ (cond
+ (special-form-anchor `~name)
+ `(print-special-doc '~name "Special Form" (special-form-anchor '~name))
+ (syntax-symbol-anchor `~name)
+ `(print-special-doc '~name "Syntax Symbol" (syntax-symbol-anchor '~name))
+ :else
+ `(print-doc (var ~name))))
(defn tree-seq
"returns a lazy sequence of the nodes in a tree, via a depth-first walk.