Skip to content

Commit a1de7af

Browse files
committed
hacke
1 parent e89b007 commit a1de7af

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

src/sci/impl/namespaces.cljc

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,8 +1191,7 @@
11911191
'extend (copy-var sci.impl.protocols/extend clojure-core-ns {:name 'extend})
11921192
'extends? (copy-core-var sci.impl.protocols/extends?)
11931193
'extend-type (macrofy 'extend-type sci.impl.protocols/extend-type clojure-core-ns)
1194-
'extend-protocol (macrofy 'extend-protocol sci.impl.protocols/extend-protocol
1195-
clojure-core-ns true)
1194+
'extend-protocol (macrofy 'extend-protocol sci.impl.protocols/extend-protocol clojure-core-ns)
11961195
'-reified-methods (new-var '-reified-methods #(types/getMethods %))
11971196
'reify* (new-var 'reify* reify/reify* clojure-core-ns)
11981197
'reify (macrofy 'reify reify/reify clojure-core-ns)
@@ -1785,9 +1784,10 @@
17851784
(defn find-doc
17861785
"Prints documentation for any var whose documentation or name
17871786
contains a match for re-string-or-pattern"
1788-
[ctx re-string-or-pattern]
1787+
[re-string-or-pattern]
17891788
(let [re (re-pattern re-string-or-pattern)
17901789
ans (sci-all-ns)
1790+
ctx (store/get-ctx)
17911791
ms (concat (mapcat #(sort-by :name (map meta (vals (sci-ns-interns* ctx %))))
17921792
ans)
17931793
(map #(assoc (meta %)
@@ -1803,8 +1803,9 @@
18031803
"Given a regular expression or stringable thing, return a seq of all
18041804
public definitions in all currently-loaded namespaces that match the
18051805
str-or-pattern."
1806-
[ctx str-or-pattern]
1807-
(let [matches? (if (instance? #?(:clj java.util.regex.Pattern :cljs js/RegExp) str-or-pattern)
1806+
[str-or-pattern]
1807+
(let [ctx (store/get-ctx)
1808+
matches? (if (instance? #?(:clj java.util.regex.Pattern :cljs js/RegExp) str-or-pattern)
18081809
#(re-find str-or-pattern (str %))
18091810
#(clojure.string/includes? (str %) (str str-or-pattern)))]
18101811
(sort (mapcat (fn [ns]
@@ -1846,21 +1847,23 @@
18461847
convenient.
18471848
18481849
Example: (source-fn 'filter)"
1849-
[ctx x]
1850-
(when-let [v (sci-resolve* ctx x)]
1851-
(let [{:keys [#?(:clj :file) :line :ns]} (meta v)]
1852-
(when (and line ns)
1853-
(when-let [source (or #?(:clj (when file
1854-
(let [f (jio/file file)]
1855-
(when (.exists f) (slurp f)))))
1856-
(when-let [load-fn (:load-fn @(:env ctx))]
1857-
(:source (load-fn {:namespace (types/getName ns)}))))]
1858-
(let [lines (clojure.string/split source #"\n")
1859-
line (dec line)
1860-
start (clojure.string/join "\n" (drop line lines))
1861-
reader (read/source-logging-reader start)
1862-
res (parser/parse-next ctx reader {:source true})]
1863-
(:source (meta res))))))))
1850+
[x]
1851+
(let [ctx (store/get-ctx)]
1852+
(when-let [
1853+
v (sci-resolve* ctx x)]
1854+
(let [{:keys [#?(:clj :file) :line :ns]} (meta v)]
1855+
(when (and line ns)
1856+
(when-let [source (or #?(:clj (when file
1857+
(let [f (jio/file file)]
1858+
(when (.exists f) (slurp f)))))
1859+
(when-let [load-fn (:load-fn @(:env ctx))]
1860+
(:source (load-fn {:namespace (types/getName ns)}))))]
1861+
(let [lines (clojure.string/split source #"\n")
1862+
line (dec line)
1863+
start (clojure.string/join "\n" (drop line lines))
1864+
reader (read/source-logging-reader start)
1865+
res (parser/parse-next ctx reader {:source true})]
1866+
(:source (meta res)))))))))
18641867

18651868
(defn source
18661869
"Prints the source code for the given symbol, if it can find it.
@@ -1912,13 +1915,13 @@
19121915
"Prints a stack trace of the exception, to the depth requested. If none supplied, uses the root cause of the
19131916
most recent repl exception (*e), and a depth of 12."
19141917
{:added "1.3"}
1915-
([ctx] (pst ctx 12))
1916-
([ctx e-or-depth]
1918+
([] (pst 12))
1919+
([e-or-depth]
19171920
(if (instance? Throwable e-or-depth)
1918-
(pst ctx e-or-depth 12)
1919-
(when-let [e (get-in @(:env ctx) [:namespaces 'clojure.core '*e])]
1920-
(pst ctx (root-cause @e) e-or-depth))))
1921-
([ctx ^Throwable e depth]
1921+
(pst e-or-depth 12)
1922+
(when-let [e @*e]
1923+
(pst (root-cause @e) e-or-depth))))
1924+
([^Throwable e depth]
19221925
(sci.impl.vars/with-bindings {sci.impl.io/out @sci.impl.io/err}
19231926
(sci.impl.io/println (str (-> e class .getSimpleName) " "
19241927
(.getMessage e)
@@ -1932,9 +1935,9 @@
19321935
(sci.impl.io/println (str \tab (stack-element-str el))))
19331936
(when cause
19341937
(sci.impl.io/println "Caused by:")
1935-
(pst ctx cause (min depth
1936-
(+ 2 (- (count (.getStackTrace cause))
1937-
(count st)))))))))))
1938+
(pst cause (min depth
1939+
(+ 2 (- (count (.getStackTrace cause))
1940+
(count st)))))))))))
19381941

19391942
(def clojure-repl-namespace (sci.lang/->Namespace 'clojure.repl nil))
19401943

@@ -1944,11 +1947,11 @@
19441947
'dir (macrofy 'dir dir clojure-repl-namespace)
19451948
'print-doc (with-meta print-doc {:private true})
19461949
'doc (macrofy 'doc doc clojure-repl-namespace)
1947-
'find-doc (new-var 'find-doc find-doc clojure-repl-namespace true)
1948-
'apropos (new-var 'apropos apropos clojure-repl-namespace true)
1950+
'find-doc (new-var 'find-doc find-doc clojure-repl-namespace)
1951+
'apropos (new-var 'apropos apropos clojure-repl-namespace)
19491952
'source (macrofy 'source source clojure-repl-namespace)
1950-
'source-fn (new-var 'source-fn source-fn clojure-repl-namespace true)
1951-
#?@(:clj ['pst (new-var 'pst pst clojure-repl-namespace true)
1953+
'source-fn (new-var 'source-fn source-fn clojure-repl-namespace)
1954+
#?@(:clj ['pst (new-var 'pst pst clojure-repl-namespace)
19521955
'stack-element-str (new-var 'stack-element-str stack-element-str clojure-repl-namespace)
19531956
'demunge (new-var 'demunge demunge clojure-repl-namespace)])})
19541957

src/sci/impl/protocols.cljc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,8 @@
206206
[t]
207207
(str t))
208208

209-
(defn extend-protocol [form _ ctx protocol-name & impls]
210-
(let [[ctx protocol-name impls] (if (symbol? ctx)
211-
[nil ctx (cons protocol-name impls)]
212-
[ctx protocol-name impls])
213-
ctx (or ctx (store/get-ctx))
209+
(defn extend-protocol [form _ protocol-name & impls]
210+
(let [ctx (store/get-ctx)
214211
#?@(:cljs [print-writer? (= 'IPrintWithWriter protocol-name)])
215212
impls (utils/split-when #(not (seq? %)) impls)
216213
protocol-var

0 commit comments

Comments
 (0)