aboutsummaryrefslogtreecommitdiff
path: root/src/main/clojure
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2010-04-12 17:17:29 -0400
committerStuart Halloway <stu@thinkrelevance.com>2010-04-12 17:17:29 -0400
commit4f9a78d13217a8de4c29221d74aca0a67cec8c1a (patch)
treedf1a52315a9f0cde9323654d576aa840df4c80c9 /src/main/clojure
parentbbe248f90e6ec33d5e85d2267fa1caf8c7cb99a7 (diff)
added apropos (per Michel Salim, plus re support)
Diffstat (limited to 'src/main/clojure')
-rw-r--r--src/main/clojure/clojure/contrib/repl_utils.clj18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/main/clojure/clojure/contrib/repl_utils.clj b/src/main/clojure/clojure/contrib/repl_utils.clj
index 309e1bac..ebe8e699 100644
--- a/src/main/clojure/clojure/contrib/repl_utils.clj
+++ b/src/main/clojure/clojure/contrib/repl_utils.clj
@@ -9,15 +9,15 @@
; Utilities meant to be used interactively at the REPL
(ns
- #^{:author "Chris Houser, Christophe Grand, Stephen Gilardi",
+ #^{:author "Chris Houser, Christophe Grand, Stephen Gilardi, Michel Salim",
:doc "Utilities meant to be used interactively at the REPL"}
clojure.contrib.repl-utils
(:import (java.io File LineNumberReader InputStreamReader PushbackReader)
(java.lang.reflect Modifier Method Constructor)
(clojure.lang RT Compiler Compiler$C))
+ (:require [clojure.contrib.string :as s])
(:use [clojure.contrib.seq :only (indexed)]
- [clojure.contrib.javadoc.browse :only (browse-url)]
- [clojure.contrib.string :as s :only ()]))
+ [clojure.contrib.javadoc.browse :only (browse-url)]))
;; ----------------------------------------------------------------------
;; Examine Java classes
@@ -125,6 +125,18 @@
[n]
`(println (or (get-source '~n) (str "Source not found"))))
+(defn apropos
+ "Given a regular expression or stringable thing, return a seq of
+all definitions in all currently-loaded namespaces that match the
+str-or-pattern."
+ [str-or-pattern]
+ (let [matches? (if (instance? java.util.regex.Pattern str-or-pattern)
+ #(re-find str-or-pattern (str %))
+ #(s/substring? (str str-or-pattern) (str %)))]
+ (mapcat (fn [ns]
+ (filter matches? (keys (ns-publics ns))))
+ (all-ns))))
+
;; ----------------------------------------------------------------------
;; Handle Ctrl-C keystrokes