Permalink
Browse files

Basic support for doc, find_doc, and source in IRB

  • Loading branch information...
1 parent cba6374 commit 1755459fe33438cb859a49fee5b95151f95124b2 @daveray committed Oct 15, 2011
Showing with 34 additions and 0 deletions.
  1. +34 −0 lib/familiar.rb
View
34 lib/familiar.rb
@@ -238,6 +238,40 @@ def self.future(&code)
Java::clojure.lang.Agent.soloExecutor.submit(Callable.new(code))
end
+ #############################################################################
+ # REPL
+ if $0 != __FILE__
+ Familiar.with do
+ self.require symbol("clojure.repl")
+ end
+
+ def self.find_doc(s)
+ self["clojure.repl", :find_doc].invoke(s)
+ end
+
+ # Print docs for he given string, symbol, etc.
+ #
+ # Examples:
+ #
+ # > Familiar.doc :reduce
+ # ... prints docs for clojure.core/reduce ...
+ #
+ # > Familiar.doc "clojure.repl/source"
+ # ... prints docs for clojure.repl/source ...
+ def self.doc(s)
+ self.with do
+ Familiar.eval read_string("(clojure.repl/doc #{s})")
+ end
+ end
+
+ # Same as Familiar.doc, but prints the *source code* for the given
+ # input.
+ def self.source(s)
+ self.with do
+ Familiar.eval read_string("(clojure.repl/source #{s})")
+ end
+ end
+ end
end

0 comments on commit 1755459

Please sign in to comment.