Skip to content

Commit 63da50e

Browse files
author
dnolen
committed
add REPL special functions docmap
1 parent cb9cab1 commit 63da50e

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

src/clj/cljs/repl.clj

+72
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,75 @@ itself (not its value) is returned. The reader macro #'x expands to (var x)."}})
892892
:name name-symbol
893893
:special-form true))
894894

895+
(def repl-special-doc-map
896+
'{in-ns {:arglists ([name])
897+
:doc "Sets *cljs-ns* to the namespace named by the symbol, creating it if needed."}
898+
require {:arglists ([& args])
899+
:doc " Loads libs, skipping any that are already loaded. Each argument is
900+
either a libspec that identifies a lib or a flag that modifies how all the identified
901+
libs are loaded. Use :require in the ns macro in preference to calling this
902+
directly.
903+
904+
Libs
905+
906+
A 'lib' is a named set of resources in classpath whose contents define a
907+
library of ClojureScript code. Lib names are symbols and each lib is associated
908+
with a ClojureScript namespace. A lib's name also locates its root directory
909+
within classpath using Java's package name to classpath-relative path mapping.
910+
All resources in a lib should be contained in the directory structure under its
911+
root directory. All definitions a lib makes should be in its associated namespace.
912+
913+
'require loads a lib by loading its root resource. The root resource path
914+
is derived from the lib name in the following manner:
915+
Consider a lib named by the symbol 'x.y.z; it has the root directory
916+
<classpath>/x/y/, and its root resource is <classpath>/x/y/z.clj. The root
917+
resource should contain code to create the lib's namespace (usually by using
918+
the ns macro) and load any additional lib resources.
919+
920+
Libspecs
921+
922+
A libspec is a lib name or a vector containing a lib name followed by
923+
options expressed as sequential keywords and arguments.
924+
925+
Recognized options:
926+
:as takes a symbol as its argument and makes that symbol an alias to the
927+
lib's namespace in the current namespace.
928+
:refer takes a list of symbols to refer from the namespace..
929+
:refer-macros takes a list of macro symbols to refer from the namespace.
930+
:include-macros takes a list of macro symbols to refer from the namespace.
931+
932+
Flags
933+
934+
A flag is a keyword.
935+
Recognized flags: :reload, :reload-all, :verbose
936+
:reload forces loading of all the identified libs even if they are
937+
already loaded
938+
:reload-all implies :reload and also forces loading of all libs that the
939+
identified libs directly or indirectly load via require or use
940+
:verbose triggers printing information about each load, alias, and refer
941+
942+
Example:
943+
944+
The following would load the library clojure.string :as string.
945+
946+
(require '[clojure/string :as string])"}
947+
require-macros {:arglists ([& args])
948+
:doc "Similar to the require REPL special function but
949+
only for macros."}
950+
import {:arglists ([& import-symbols-or-lists])
951+
:doc "import-list => (closure-namespace constructor-name-symbols*)
952+
953+
For each name in constructor-name-symbols, adds a mapping from name to the
954+
constructor named by closure-namespace to the current namespace. Use :import in the ns
955+
macro in preference to calling this directly."}
956+
load-file {:arglist ([name])
957+
:doc "Sequentially read and evaluate the set of forms contained in the file."}})
958+
959+
(defn- repl-special-doc [name-symbol]
960+
(assoc (repl-special-doc-map name-symbol)
961+
:name name-symbol
962+
:repl-special-function true))
963+
895964
(defmacro doc
896965
"Prints documentation for a var or special form given its name"
897966
[name]
@@ -904,6 +973,9 @@ itself (not its value) is returned. The reader macro #'x expands to (var x)."}})
904973
(special-doc-map name)
905974
`(cljs.repl/print-doc (quote ~(special-doc name)))
906975

976+
(repl-special-doc-map name)
977+
`(cljs.repl/print-doc (quote ~(repl-special-doc name)))
978+
907979
(ana-api/find-ns name)
908980
`(cljs.repl/print-doc
909981
(quote ~(select-keys (ana-api/find-ns name) [:name :doc])))

src/cljs/cljs/repl.cljs

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
(cond
1616
(:forms m) (doseq [f (:forms m)]
1717
(println " " f))
18-
(:arglists m) (if (:macro m)
18+
(:arglists m) (if (or (:macro m)
19+
(:repl-special-function m))
1920
(prn (:arglists m))
2021
(prn (second (:arglists m)))))
2122
(if (:special-form m)
@@ -29,5 +30,7 @@
2930
(:name m)))))
3031
(do
3132
(when (:macro m)
32-
(println "Macro"))
33+
(println "Macro"))
34+
(when (:repl-special-function m)
35+
(println "REPL Special Function"))
3336
(println " " (:doc m)))))

0 commit comments

Comments
 (0)