Skip to content

Instantly share code, notes, and snippets.

@r-moeritz
Created June 16, 2011 21:29
Show Gist options
  • Save r-moeritz/1030328 to your computer and use it in GitHub Desktop.
Save r-moeritz/1030328 to your computer and use it in GitHub Desktop.
cljdoc - a repl helper to quickly browse Clojure docs
;; Copyright (c) Ralph Moritz. 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.
(ns
^{:author "Ralph Moritz"
:doc "A repl helper to quickly browse Clojure docs"}
cljdoc.core
(:use [clojure.java.browse :only (browse-url)]))
(def *url* #"https?\://clojure.org/[\w#]+")
(defmacro cljdoc
"Scans output of clojure.core/doc for a URL and opens
a browser window to display documentation from clojure.org,
where available."
[string]
`(let [text# (with-out-str (doc ~(symbol string)))
url# (re-find *url* text#)]
(if (nil? url#)
(println "Could not find documentation for" ~string)
(browse-url url#))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment