Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ SCI is used in [babashka](https://github.com/babashka/babashka),

## Unreleased

- `clojure.repl/doc` on `&`, `catch` and `finally` prints the docs of `fn` and `try`
- Speed up `binding` (about 4x on the JVM, 2x in native bb) and `try` without a catch (about 4x)
- Clojure 1.13 map destructuring as of clojure/clojure 98d735fa: `:excess` and `:missing` directives, `:defaults` removed. Adds the `selector` macro to `clojure.core`.
- Minimum Clojure version is `1.11.1`
Expand Down
21 changes: 11 additions & 10 deletions src/sci/impl/namespaces.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2158,16 +2158,17 @@
(defn doc
[_ _ sym]
;; emit ~'resolve etc unqualified, the cljd host would qualify them into this ns
`(let [special-doc# (try (~'resolve '~'clojure.repl/special-doc) (catch #?(:cljs :default :default ~'Exception) ~'_ nil))
special# (when special-doc# (special-doc# '~sym))]
(if special#
(~'clojure.repl/print-doc special#)
(if-let [var# (~'resolve '~sym)]
(when (~'var? var#)
(~'clojure.repl/print-doc (meta var#)))
(if-let [ns# (~'find-ns '~sym)]
(~'clojure.repl/print-doc (assoc (meta ns#)
:name (~'ns-name ns#))))))))
(let [sym (get '{& fn catch try finally try} sym sym)]
`(let [special-doc# (try (~'resolve '~'clojure.repl/special-doc) (catch #?(:cljs :default :default ~'Exception) ~'_ nil))
special# (when special-doc# (special-doc# '~sym))]
(if special#
(~'clojure.repl/print-doc special#)
(if-let [var# (~'resolve '~sym)]
(when (~'var? var#)
(~'clojure.repl/print-doc (meta var#)))
(if-let [ns# (~'find-ns '~sym)]
(~'clojure.repl/print-doc (assoc (meta ns#)
:name (~'ns-name ns#)))))))))

(defn find-doc
"Prints documentation for any var whose documentation or name
Expand Down
6 changes: 5 additions & 1 deletion test/sci/repl_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ clojure.core/inc
(is (= (str/trim
"-------------------------\nfoo\n foodoc\n")
(str/trim (sci/with-out-str (eval* "(ns foo \"foodoc\") (clojure.repl/doc foo)")))))
(is (empty? (sci/with-out-str (tu/eval* "(clojure.repl/doc x)" {:bindings {'x 1}}))))))
(is (empty? (sci/with-out-str (tu/eval* "(clojure.repl/doc x)" {:bindings {'x 1}}))))
(is (str/includes? (sci/with-out-str (eval* "(clojure.repl/doc &)")) "clojure.core/fn"))
(let [opts {:namespaces {'clojure.repl {'special-doc (fn [sym] (when (= 'try sym) {:name 'try :doc "trydoc" :special-form true}))}}}]
(is (str/includes? (sci/with-out-str (tu/eval* "(clojure.repl/doc catch)" opts)) "trydoc"))
(is (str/includes? (sci/with-out-str (tu/eval* "(clojure.repl/doc finally)" opts)) "trydoc")))))

(deftest repl-find-doc-test
(when-not tu/native?
Expand Down
Loading