diff options
author | Chouser <chouser@n01se.net> | 2009-11-08 19:18:55 -0500 |
---|---|---|
committer | Chouser <chouser@n01se.net> | 2009-11-08 19:18:55 -0500 |
commit | f165e286ac9856781419d4659a0cde088eb79ee1 (patch) | |
tree | 532dde517a06a9e7d5c65d581f73ea95a11abe9b /src/clojure/contrib/repl_utils.clj | |
parent | cc4e2ec2bf558f059330ebc97a031d7806a1e364 (diff) |
repl-utils: (source foo) threw NPE when metadata didn't include :file. Fixed.
Diffstat (limited to 'src/clojure/contrib/repl_utils.clj')
-rw-r--r-- | src/clojure/contrib/repl_utils.clj | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/clojure/contrib/repl_utils.clj b/src/clojure/contrib/repl_utils.clj index af694898..2864179b 100644 --- a/src/clojure/contrib/repl_utils.clj +++ b/src/clojure/contrib/repl_utils.clj @@ -104,16 +104,17 @@ Example: (get-source 'filter)" [x] (when-let [v (resolve x)] - (when-let [strm (.getResourceAsStream (RT/baseLoader) (:file ^v))] - (with-open [rdr (LineNumberReader. (InputStreamReader. strm))] - (dotimes [_ (dec (:line ^v))] (.readLine rdr)) - (let [text (StringBuilder.) - pbr (proxy [PushbackReader] [rdr] - (read [] (let [i (proxy-super read)] - (.append text (char i)) - i)))] - (read (PushbackReader. pbr)) - (str text)))))) + (when-let [filepath (:file (meta v))] + (when-let [strm (.getResourceAsStream (RT/baseLoader) filepath)] + (with-open [rdr (LineNumberReader. (InputStreamReader. strm))] + (dotimes [_ (dec (:line ^v))] (.readLine rdr)) + (let [text (StringBuilder.) + pbr (proxy [PushbackReader] [rdr] + (read [] (let [i (proxy-super read)] + (.append text (char i)) + i)))] + (read (PushbackReader. pbr)) + (str text))))))) (defmacro source "Prints the source code for the given symbol, if it can find it. |