aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristophe Grand <christophe@cgrand.net>2009-03-03 14:49:15 +0000
committerChristophe Grand <christophe@cgrand.net>2009-03-03 14:49:15 +0000
commit1f66365c555956a50f235e858b93365ece6cd4b6 (patch)
tree52447e7cce3270c97b7a497a12ff7c1b98ca5518 /src
parent6f6415ce4f2f20581331f7f13e2e87ad131fce13 (diff)
Merged javadoc into repl-utils
Diffstat (limited to 'src')
-rw-r--r--src/clojure/contrib/javadoc.clj88
-rw-r--r--src/clojure/contrib/repl_utils.clj5
-rw-r--r--src/clojure/contrib/repl_utils/javadoc.clj83
3 files changed, 89 insertions, 87 deletions
diff --git a/src/clojure/contrib/javadoc.clj b/src/clojure/contrib/javadoc.clj
index 78b566f4..8a0c32e4 100644
--- a/src/clojure/contrib/javadoc.clj
+++ b/src/clojure/contrib/javadoc.clj
@@ -1,87 +1,3 @@
-; Copyright (c) Christophe Grand, November 2008. All rights reserved.
+(ns clojure.contrib.javadoc)
-; The use and distribution terms for this software are covered by the
-; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
-; which can be found in the file epl-v10.html at the root of this
-; distribution.
-; By using this software in any fashion, you are agreeing to be bound by
-; the terms of this license.
-; You must not remove this notice, or any other, from this software.
-
-; thanks to Stuart Sierra
-
-; a repl helper to quickly open javadocs.
-
-(ns clojure.contrib.javadoc
- (:use clojure.contrib.javadoc.browse)
- (:import (java.io File)))
-
-(def *feeling-lucky-url* "http://www.google.com/search?btnI=I%27m%20Feeling%20Lucky&q=allinurl:")
-(def *feeling-lucky* true)
-
-(def
- #^{:doc "Ref to a list of local paths for Javadoc-generated HTML
- files."}
- *local-javadocs* (ref (list)))
-
-(def *core-java-api*
- (if (= "1.5" (System/getProperty "java.specification.version"))
- "http://java.sun.com/j2se/1.5.0/docs/api/"
- "http://java.sun.com/javase/6/docs/api/"))
-
-(def
- #^{:doc "Ref to a map from package name prefixes to URLs for remote
- Javadocs."}
- *remote-javadocs*
- (ref (sorted-map
- "java." *core-java-api*
- "javax." *core-java-api*
- "org.ietf.jgss." *core-java-api*
- "org.omg." *core-java-api*
- "org.w3c.dom." *core-java-api*
- "org.xml.sax." *core-java-api*
- "org.apache.commons.codec." "http://commons.apache.org/codec/api-release/"
- "org.apache.commons.io." "http://commons.apache.org/io/api-release/"
- "org.apache.commons.lang." "http://commons.apache.org/lang/api-release/")))
-
-(defn add-local-javadoc
- "Adds to the list of local Javadoc paths."
- [path]
- (dosync (commute *local-javadocs* conj path)))
-
-(defn add-remote-javadoc
- "Adds to the list of remote Javadoc URLs. package-prefix is the
- beginning of the package name that has docs at this URL."
- [package-prefix url]
- (dosync (commute *remote-javadocs* assoc package-prefix url)))
-
-(defn find-javadoc-url
- "Searches for a URL for the given class name. Tries
- *local-javadocs* first, then *remote-javadocs*. Returns a string."
- {:tag String}
- [#^String classname]
- (let [file-path (.replace classname \. File/separatorChar)
- url-path (.replace classname \. \/)]
- (if-let [file #^File (first
- (filter #(.exists #^File %)
- (map #(File. (str %) (str file-path ".html"))
- @*local-javadocs*)))]
- (-> file .toURI str)
- ;; If no local file, try remote URLs:
- (or (some (fn [[prefix url]]
- (when (.startsWith classname prefix)
- (str url url-path ".html")))
- @*remote-javadocs*)
- ;; if *feeling-lucky* try a web search
- (when *feeling-lucky* (str *feeling-lucky-url* url-path ".html"))))))
-
-(defn javadoc
- "Opens a browser window displaying the javadoc for the argument.
- Tries *local-javadocs* first, then *remote-javadocs*."
- [class-or-object]
- (let [#^Class c (if (instance? Class class-or-object)
- class-or-object
- (class class-or-object))]
- (if-let [url (find-javadoc-url (.getName c))]
- (browse-url url)
- (println "Could not find Javadoc for" c))))
+(throw (Exception. "clojure.contrib.javadoc/javadoc can now be found in clojure.contrib.repl-utils."))
diff --git a/src/clojure/contrib/repl_utils.clj b/src/clojure/contrib/repl_utils.clj
index 5ba37373..671cb39d 100644
--- a/src/clojure/contrib/repl_utils.clj
+++ b/src/clojure/contrib/repl_utils.clj
@@ -9,10 +9,11 @@
; Utilities meant to be used interactively at the REPL
(ns clojure.contrib.repl-utils
- (:import (java.io LineNumberReader InputStreamReader PushbackReader)
+ (:import (java.io File LineNumberReader InputStreamReader PushbackReader)
(java.lang.reflect Modifier Method Constructor)
(clojure.lang RT))
(:use [clojure.contrib.seq-utils :only (indexed)]
+ [clojure.contrib.javadoc.browse :only (browse-url)]
[clojure.contrib.str-utils :only (str-join re-sub re-partition)]))
(defn- sortable [t]
@@ -119,3 +120,5 @@
Example: (source filter)"
[n]
`(println (or (get-source '~n) (str "Source not found"))))
+
+(load "repl_utils/javadoc") \ No newline at end of file
diff --git a/src/clojure/contrib/repl_utils/javadoc.clj b/src/clojure/contrib/repl_utils/javadoc.clj
new file mode 100644
index 00000000..32551340
--- /dev/null
+++ b/src/clojure/contrib/repl_utils/javadoc.clj
@@ -0,0 +1,83 @@
+; Copyright (c) Christophe Grand, November 2008. All rights reserved.
+
+; The use and distribution terms for this software are covered by the
+; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+; which can be found in the file epl-v10.html at the root of this
+; distribution.
+; By using this software in any fashion, you are agreeing to be bound by
+; the terms of this license.
+; You must not remove this notice, or any other, from this software.
+
+; thanks to Stuart Sierra
+
+; a repl helper to quickly open javadocs.
+
+(def *feeling-lucky-url* "http://www.google.com/search?btnI=I%27m%20Feeling%20Lucky&q=allinurl:")
+(def *feeling-lucky* true)
+
+(def
+ #^{:doc "Ref to a list of local paths for Javadoc-generated HTML
+ files."}
+ *local-javadocs* (ref (list)))
+
+(def *core-java-api*
+ (if (= "1.5" (System/getProperty "java.specification.version"))
+ "http://java.sun.com/j2se/1.5.0/docs/api/"
+ "http://java.sun.com/javase/6/docs/api/"))
+
+(def
+ #^{:doc "Ref to a map from package name prefixes to URLs for remote
+ Javadocs."}
+ *remote-javadocs*
+ (ref (sorted-map
+ "java." *core-java-api*
+ "javax." *core-java-api*
+ "org.ietf.jgss." *core-java-api*
+ "org.omg." *core-java-api*
+ "org.w3c.dom." *core-java-api*
+ "org.xml.sax." *core-java-api*
+ "org.apache.commons.codec." "http://commons.apache.org/codec/api-release/"
+ "org.apache.commons.io." "http://commons.apache.org/io/api-release/"
+ "org.apache.commons.lang." "http://commons.apache.org/lang/api-release/")))
+
+(defn add-local-javadoc
+ "Adds to the list of local Javadoc paths."
+ [path]
+ (dosync (commute *local-javadocs* conj path)))
+
+(defn add-remote-javadoc
+ "Adds to the list of remote Javadoc URLs. package-prefix is the
+ beginning of the package name that has docs at this URL."
+ [package-prefix url]
+ (dosync (commute *remote-javadocs* assoc package-prefix url)))
+
+(defn find-javadoc-url
+ "Searches for a URL for the given class name. Tries
+ *local-javadocs* first, then *remote-javadocs*. Returns a string."
+ {:tag String}
+ [#^String classname]
+ (let [file-path (.replace classname \. File/separatorChar)
+ url-path (.replace classname \. \/)]
+ (if-let [file #^File (first
+ (filter #(.exists #^File %)
+ (map #(File. (str %) (str file-path ".html"))
+ @*local-javadocs*)))]
+ (-> file .toURI str)
+ ;; If no local file, try remote URLs:
+ (or (some (fn [[prefix url]]
+ (when (.startsWith classname prefix)
+ (str url url-path ".html")))
+ @*remote-javadocs*)
+ ;; if *feeling-lucky* try a web search
+ (when *feeling-lucky* (str *feeling-lucky-url* url-path ".html"))))))
+
+(defn javadoc
+ "Opens a browser window displaying the javadoc for the argument.
+ Tries *local-javadocs* first, then *remote-javadocs*."
+ [class-or-object]
+ (let [#^Class c (if (instance? Class class-or-object)
+ class-or-object
+ (class class-or-object))]
+ (if-let [url (find-javadoc-url (.getName c))]
+ (browse-url url)
+ (println "Could not find Javadoc for" c))))