|
1191 | 1191 | 'extend (copy-var sci.impl.protocols/extend clojure-core-ns {:name 'extend}) |
1192 | 1192 | 'extends? (copy-core-var sci.impl.protocols/extends?) |
1193 | 1193 | '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) |
1196 | 1195 | '-reified-methods (new-var '-reified-methods #(types/getMethods %)) |
1197 | 1196 | 'reify* (new-var 'reify* reify/reify* clojure-core-ns) |
1198 | 1197 | 'reify (macrofy 'reify reify/reify clojure-core-ns) |
|
1785 | 1784 | (defn find-doc |
1786 | 1785 | "Prints documentation for any var whose documentation or name |
1787 | 1786 | contains a match for re-string-or-pattern" |
1788 | | - [ctx re-string-or-pattern] |
| 1787 | + [re-string-or-pattern] |
1789 | 1788 | (let [re (re-pattern re-string-or-pattern) |
1790 | 1789 | ans (sci-all-ns) |
| 1790 | + ctx (store/get-ctx) |
1791 | 1791 | ms (concat (mapcat #(sort-by :name (map meta (vals (sci-ns-interns* ctx %)))) |
1792 | 1792 | ans) |
1793 | 1793 | (map #(assoc (meta %) |
|
1803 | 1803 | "Given a regular expression or stringable thing, return a seq of all |
1804 | 1804 | public definitions in all currently-loaded namespaces that match the |
1805 | 1805 | 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) |
1808 | 1809 | #(re-find str-or-pattern (str %)) |
1809 | 1810 | #(clojure.string/includes? (str %) (str str-or-pattern)))] |
1810 | 1811 | (sort (mapcat (fn [ns] |
|
1846 | 1847 | convenient. |
1847 | 1848 |
|
1848 | 1849 | 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))))))))) |
1864 | 1867 |
|
1865 | 1868 | (defn source |
1866 | 1869 | "Prints the source code for the given symbol, if it can find it. |
|
1912 | 1915 | "Prints a stack trace of the exception, to the depth requested. If none supplied, uses the root cause of the |
1913 | 1916 | most recent repl exception (*e), and a depth of 12." |
1914 | 1917 | {:added "1.3"} |
1915 | | - ([ctx] (pst ctx 12)) |
1916 | | - ([ctx e-or-depth] |
| 1918 | + ([] (pst 12)) |
| 1919 | + ([e-or-depth] |
1917 | 1920 | (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] |
1922 | 1925 | (sci.impl.vars/with-bindings {sci.impl.io/out @sci.impl.io/err} |
1923 | 1926 | (sci.impl.io/println (str (-> e class .getSimpleName) " " |
1924 | 1927 | (.getMessage e) |
|
1932 | 1935 | (sci.impl.io/println (str \tab (stack-element-str el)))) |
1933 | 1936 | (when cause |
1934 | 1937 | (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))))))))))) |
1938 | 1941 |
|
1939 | 1942 | (def clojure-repl-namespace (sci.lang/->Namespace 'clojure.repl nil)) |
1940 | 1943 |
|
|
1944 | 1947 | 'dir (macrofy 'dir dir clojure-repl-namespace) |
1945 | 1948 | 'print-doc (with-meta print-doc {:private true}) |
1946 | 1949 | '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) |
1949 | 1952 | '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) |
1952 | 1955 | 'stack-element-str (new-var 'stack-element-str stack-element-str clojure-repl-namespace) |
1953 | 1956 | 'demunge (new-var 'demunge demunge clojure-repl-namespace)])}) |
1954 | 1957 |
|
|
0 commit comments