Mercurial > lasercutter
annotate 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 |
rev | line source |
---|---|
rlm@10 | 1 ;;; show_doc.clj -- part of the pretty printer for Clojure |
rlm@10 | 2 |
rlm@10 | 3 ;; by Tom Faulhaber |
rlm@10 | 4 ;; April 3, 2009 |
rlm@10 | 5 |
rlm@10 | 6 ; Copyright (c) Tom Faulhaber, Dec 2008. All rights reserved. |
rlm@10 | 7 ; The use and distribution terms for this software are covered by the |
rlm@10 | 8 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) |
rlm@10 | 9 ; which can be found in the file epl-v10.html at the root of this distribution. |
rlm@10 | 10 ; By using this software in any fashion, you are agreeing to be bound by |
rlm@10 | 11 ; the terms of this license. |
rlm@10 | 12 ; You must not remove this notice, or any other, from this software. |
rlm@10 | 13 |
rlm@10 | 14 ;; This example uses cl-format as part of a routine to display all the doc |
rlm@10 | 15 ;; strings and function arguments from one or more namespaces. |
rlm@10 | 16 |
rlm@10 | 17 (ns clojure.contrib.pprint.examples.show-doc |
rlm@10 | 18 (:use clojure.contrib.pprint)) |
rlm@10 | 19 |
rlm@10 | 20 (defn ns-list |
rlm@10 | 21 ([] (ns-list nil)) |
rlm@10 | 22 ([pattern] |
rlm@10 | 23 (filter |
rlm@10 | 24 (if pattern |
rlm@10 | 25 (comp (partial re-find pattern) name ns-name) |
rlm@10 | 26 (constantly true)) |
rlm@10 | 27 (sort-by ns-name (all-ns))))) |
rlm@10 | 28 |
rlm@10 | 29 (defn show-doc |
rlm@10 | 30 ([] (show-doc nil)) |
rlm@10 | 31 ([pattern] |
rlm@10 | 32 (cl-format |
rlm@10 | 33 true |
rlm@10 | 34 "~:{~A: ===============================================~ |
rlm@10 | 35 ~%~{~{~a: ~{~a~^, ~}~%~a~%~}~^~%~}~2%~}" |
rlm@10 | 36 (map |
rlm@10 | 37 #(vector (ns-name %) |
rlm@10 | 38 (map |
rlm@10 | 39 (fn [f] |
rlm@10 | 40 (let [f-meta (meta (find-var (symbol (str (ns-name %)) (str f))))] |
rlm@10 | 41 [f (:arglists f-meta) (:doc f-meta)])) |
rlm@10 | 42 (filter |
rlm@10 | 43 (fn [a] (instance? clojure.lang.IFn a)) |
rlm@10 | 44 (sort (map key (ns-publics %)))))) |
rlm@10 | 45 (ns-list pattern))))) |
rlm@10 | 46 |
rlm@10 | 47 (defn create-api-file [pattern out-file] |
rlm@10 | 48 (with-open [f (java.io.FileWriter. out-file)] |
rlm@10 | 49 (binding [*out* f] |
rlm@10 | 50 (show-doc pattern)))) |