Mercurial > lasercutter
diff src/clojure/contrib/test_contrib/pprint/examples/show_doc.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clojure/contrib/test_contrib/pprint/examples/show_doc.clj Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,50 @@ 1.4 +;;; show_doc.clj -- part of the pretty printer for Clojure 1.5 + 1.6 +;; by Tom Faulhaber 1.7 +;; April 3, 2009 1.8 + 1.9 +; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved. 1.10 +; The use and distribution terms for this software are covered by the 1.11 +; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 1.12 +; which can be found in the file epl-v10.html at the root of this distribution. 1.13 +; By using this software in any fashion, you are agreeing to be bound by 1.14 +; the terms of this license. 1.15 +; You must not remove this notice, or any other, from this software. 1.16 + 1.17 +;; This example uses cl-format as part of a routine to display all the doc 1.18 +;; strings and function arguments from one or more namespaces. 1.19 + 1.20 +(ns clojure.contrib.pprint.examples.show-doc 1.21 + (:use clojure.contrib.pprint)) 1.22 + 1.23 +(defn ns-list 1.24 + ([] (ns-list nil)) 1.25 + ([pattern] 1.26 + (filter 1.27 + (if pattern 1.28 + (comp (partial re-find pattern) name ns-name) 1.29 + (constantly true)) 1.30 + (sort-by ns-name (all-ns))))) 1.31 + 1.32 +(defn show-doc 1.33 + ([] (show-doc nil)) 1.34 + ([pattern] 1.35 + (cl-format 1.36 + true 1.37 + "~:{~A: ===============================================~ 1.38 + ~%~{~{~a: ~{~a~^, ~}~%~a~%~}~^~%~}~2%~}" 1.39 + (map 1.40 + #(vector (ns-name %) 1.41 + (map 1.42 + (fn [f] 1.43 + (let [f-meta (meta (find-var (symbol (str (ns-name %)) (str f))))] 1.44 + [f (:arglists f-meta) (:doc f-meta)])) 1.45 + (filter 1.46 + (fn [a] (instance? clojure.lang.IFn a)) 1.47 + (sort (map key (ns-publics %)))))) 1.48 + (ns-list pattern))))) 1.49 + 1.50 +(defn create-api-file [pattern out-file] 1.51 + (with-open [f (java.io.FileWriter. out-file)] 1.52 + (binding [*out* f] 1.53 + (show-doc pattern))))