Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
add find-doc REPL function
Browse files Browse the repository at this point in the history
fixes #141
  • Loading branch information
anmonteiro committed Apr 24, 2017
1 parent 6172778 commit 81caf3f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [master](https://github.com/anmonteiro/lumo/compare/1.4.1...HEAD) (unreleased)

### New features

- Add `find-doc` REPL function ([#141](https://github.com/anmonteiro/lumo/issues/141)).

## [1.4.1](https://github.com/anmonteiro/lumo/compare/1.4.0...1.4.1) (2017-04-20)

### Changes
Expand Down
21 changes: 21 additions & 0 deletions src/cljs/snapshot/lumo/repl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,27 @@
:arglists (seq sigs)}]))
(into {})))))))))

(defn- namespace-doc [nspace]
(select-keys (get-in @st [::ana/namespaces nspace]) [:name :doc]))

(defn find-doc
"Prints documentation for any var whose documentation or name
contains a match for re-string-or-pattern"
[re-string-or-pattern]
(let [re (re-pattern re-string-or-pattern)
ms (concat (mapcat #(sort-by :name
(map (fn [[k v]]
(assoc (:meta v) :name (symbol % k)))
(get-in @st [::ana/namespaces % :defs])))
(all-ns))
(map namespace-doc (all-ns))
(map special-doc (keys special-doc-map)))]
(doseq [m ms
:when (and (:doc m)
(or (re-find re (:doc m))
(re-find re (str (:name m)))))]
(doc* (:name m)))))

;; --------------------
;; Code evaluation

Expand Down
2 changes: 2 additions & 0 deletions src/js/__tests__/__snapshots__/cli-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Array [
ClojureScript clojurescript-version
Node.js X.X.X
Docs: (doc function-name-here)
(find-doc \\"part-of-name-here\\")
Exit: Control+D or :cljs/quit or exit
",
Expand All @@ -34,6 +35,7 @@ Array [
ClojureScript clojurescript-version
Node.js X.X.X
Docs: (doc function-name-here)
(find-doc \\"part-of-name-here\\")
Exit: Control+D or :cljs/quit or exit
",
Expand Down
1 change: 1 addition & 0 deletions src/js/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function createBanner(): string {
ClojureScript ${lumo.load('clojurescript-version')}
Node.js ${process.version}
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Exit: Control+D or :cljs/quit or exit
`;
Expand Down
2 changes: 1 addition & 1 deletion src/js/cljs.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export default function startClojureScriptEngine(opts: CLIOptsType): void {
setPrintFns(new DiscardingSender());

execute(
"(require '[lumo.repl :refer-macros [doc dir]])",
"(require '[lumo.repl :refer [find-doc] :refer-macros [dir doc]])",
'text',
true,
false,
Expand Down

0 comments on commit 81caf3f

Please sign in to comment.