API for cljs.repl - clojurescript


Full namespace name: cljs.repl

Overview





Protocols



IGetError

Protocol

    Known implementations: cljs.repl.browser.BrowserEnv, cljs.repl.rhino.RhinoEnv
    

-get-error

function
Usage: (-get-error repl-env name env build-options)
Given a symbol representing a var holding an error, an analysis
 environment, and the REPL/compiler options return the canonical error
 representation:

 {:value <string>
  :stacktrace <string>}

:value should be the host environment JavaScript error message string.
:stacktrace should be the host JavaScript environment stacktrace string.

      
      
      
    


IJavaScriptEnv

Protocol

    Known implementations: cljs.repl.browser.BrowserEnv, cljs.repl.nashorn.NashornEnv, cljs.repl.node.NodeEnv, cljs.repl.rhino.RhinoEnv
    

-evaluate

function
Usage: (-evaluate repl-env filename line js)
evaluate a javascript string

      
      
      
    

-load

function
Usage: (-load repl-env provides url)
load code at url into the environment

      
      
      
    

-setup

function
Usage: (-setup repl-env opts)
initialize the environment

      
      
      
    

-tear-down

function
Usage: (-tear-down repl-env)
dispose of the environment

      
      
      
    


IParseError

Protocol

    Known implementations: cljs.repl.nashorn.NashornEnv, cljs.repl.node.NodeEnv
    

-parse-error

function
Usage: (-parse-error repl-env error build-options)
Given the original JavaScript error return the error to actually
use.

      
      
      
    


IParseStacktrace

Protocol

    Known implementations: cljs.repl.browser.BrowserEnv, cljs.repl.nashorn.NashornEnv, cljs.repl.rhino.RhinoEnv
    

-parse-stacktrace

function
Usage: (-parse-stacktrace repl-env stacktrace error build-options)
Given the original JavaScript stacktrace string, the entire original error
value and current compiler build options, parse the stacktrace into the
canonical form:

[{:file <string>
  :function <string>
  :line <integer>
  :column <integer>}*]

:file must be a URL path (without protocol) relative to :output-dir. If
no source file can be supplied (such as REPL defs), :file may be a custom
identifier string surrounded by angle brackets, i.e. "<cljs repl>".

      
      
      
    


IPrintStacktrace

Protocol

    Known implementations: 
    

-print-stacktrace

function
Usage: (-print-stacktrace repl-env stacktrace error build-options)
Implementing REPL evaluation environments are given the opportunity to
print the mapped stacktrace themselves. This permits further processing.

      
      
      
    


IReplEnvOptions

Protocol

    Known implementations: cljs.repl.browser.BrowserEnv, cljs.repl.nashorn.NashornEnv, cljs.repl.node.NodeEnv, cljs.repl.rhino.RhinoEnv, Object
    

-repl-options

function
Usage: (-repl-options repl-env)
Return default REPL options for a REPL Env

      
      
      
    

Public Variables and Functions



analyze-source

function
Usage: (analyze-source src-dir)
       (analyze-source src-dir opts)
Given a source directory, analyzes all .cljs files. Used to populate
(:cljs.analyzer/namespaces compiler-env) so as to support code reflection.

    
    
    
  


apropos

macro
Usage: (apropos str-or-pattern)
Given a regular expression or stringable thing, return a seq of all
public definitions in all currently-loaded namespaces that match the
str-or-pattern.

    
    
    
  


dir

macro
Usage: (dir ns)
Prints a sorted directory of public vars in a namespace

    
    
    
  


doc

macro
Usage: (doc name)
Prints documentation for a var or special form given its name

    
    
    
  


evaluate-form

function
Usage: (evaluate-form repl-env env filename form)
       (evaluate-form repl-env env filename form wrap)
       (evaluate-form repl-env env filename form wrap opts)
Evaluate a ClojureScript form in the JavaScript environment. Returns a
string which is the ClojureScript return value. This string may or may
not be readable by the Clojure reader.

    
    
    
  


find-doc

macro
Usage: (find-doc re-string-or-pattern)
Prints documentation for any var whose documentation or name
contains a match for re-string-or-pattern

    
    
    
  


js-src->cljs-src

function
Usage: (js-src->cljs-src f)
Map a JavaScript output file back to the original ClojureScript source
file (.cljs or .cljc).

    
    
    
  


known-repl-opts

var

    
Set of all known REPL options.

    
    
    
  


load-namespace

function
Usage: (load-namespace repl-env ns)
       (load-namespace repl-env ns opts)
Load a namespace and all of its dependencies into the evaluation environment.
The environment is responsible for ensuring that each namespace is loaded once and
only once.

    
    
    
  


mapped-stacktrace

function
Usage: (mapped-stacktrace stacktrace)
       (mapped-stacktrace stacktrace opts)
Given a vector representing the canonicalized JavaScript stacktrace
return the ClojureScript stacktrace. The canonical stacktrace must be
in the form:

 [{:file <string>
   :function <string>
   :line <integer>
   :column <integer>}*]

:file must be a URL path (without protocol) relative to :output-dir or a
identifier delimited by angle brackets. The returned mapped stacktrace will
also contain :url entries to the original sources if it can be determined
from the classpath.

    
    
    
  


ns-info

function
Usage: (ns-info f)
Given a path to a js source file return the ns info for the corresponding
ClojureScript file if it exists.

    
    
    
  


print-mapped-stacktrace

function
Usage: (print-mapped-stacktrace stacktrace)
       (print-mapped-stacktrace stacktrace opts)
Given a vector representing the canonicalized JavaScript stacktrace
print the ClojureScript stacktrace. See mapped-stacktrace.

    
    
    
  


read-source-map

function
Usage: (read-source-map f)
Return the source map for the JavaScript source file.

    
    
    
  


repl

function
Usage: (repl repl-env & opts)
Generic, reusable, read-eval-print loop. By default, reads from *in* using
a c.t.r.reader-types/source-logging-push-back-reader,
writes to *out*, and prints exception summaries to *err*. If you use the
default :read hook, *in* must either be an instance of
c.t.r.reader-types/PushbackReader or duplicate its behavior of both supporting
unread and collapsing CR, LF, and CRLF into a single \newline. Options
are sequential keyword-value pairs. The first argument is the JavaScript
evaluation environment, the second argument is an extended version of the
standard ClojureScript compiler options. In addition to ClojureScript compiler
build options it also take a set of options similar to clojure.main/repl with
adjustments for ClojureScript evalution and compilation model:

Available clojure.main/repl style options and their defaults:

   - :init, function of no arguments, initialization hook called with
     bindings for set!-able vars in place.
     default: #()

   - :need-prompt, function of no arguments, called before each
     read-eval-print except the first, the user will be prompted if it
     returns true.
     default: #(if (c.t.r.readers-types/indexing-reader? *in*)
                 (== (c.t.r.reader-types/get-column-number *in*) 1)
                 (identity true))

   - :prompt, function of no arguments, prompts for more input.
     default: repl-prompt

   - :flush, function of no arguments, flushes output
     default: flush

   - :read, function of two arguments, reads from *in*:
       - returns its first argument to request a fresh prompt
         - depending on need-prompt, this may cause the repl to prompt
           before reading again
       - returns its second argument to request an exit from the repl
       - else returns the next object read from the input stream
     default: repl-read

   - :eval, function of one argument, returns the evaluation of its
     argument. The eval function must take repl-env, the JavaScript evaluation
     environment, env, the ClojureScript analysis environment, the form
     and opts, the standard ClojureScript REPL/compiler options.
     default: eval

   - :print, function of one argument, prints its argument to the output
     default: println

   - :caught, function of three arguments, a throwable, called when
     read, eval, or print throws an exception or error default. The second
     argument is the JavaScript evaluation environment this permits context
     sensitive handling if necessary. The third argument is opts, the standard
     ClojureScript REPL/compiler options. In the case of errors or exception
     in the JavaScript target, these will be thrown as
     clojure.lang.IExceptionInfo instances.
     default: repl-caught

   - :reader, the c.t.r reader to use.
     default: c.t.r.reader-types/source-logging-push-back-reader

   - :print-no-newline, print without a newline.
     default: print

   - :source-map-inline, whether inline source maps should be enabled. Most
     useful in browser context. Implies using a fresh reader for each form.
     default: true

    
    
    
  


repl-read

function
Usage: (repl-read request-prompt request-exit)
       (repl-read request-prompt request-exit opts)
Default :read hook for repl. Reads from *in* which must either be an
instance of LineNumberingPushbackReader or duplicate its behavior of both
supporting .unread and collapsing all of CR, LF, and CRLF into a single
\newline. repl-read:
  - skips whitespace, then
    - returns request-prompt on start of line, or
    - returns request-exit on end of stream, or
    - reads an object from the input stream, then
      - skips the next input character if it's end of line, then
      - returns the object.

    
    
    
  


skip-if-eol

function
Usage: (skip-if-eol s)
If the next character on stream s is a newline, skips it, otherwise
leaves the stream untouched. Returns :line-start, :stream-end, or :body
to indicate the relative location of the next character on s. The stream
must either be an instance of LineNumberingPushbackReader or duplicate
its behavior of both supporting .unread and collapsing all of CR, LF, and
CRLF to a single \newline.

    
    
    
  


skip-whitespace

function
Usage: (skip-whitespace s)
Skips whitespace characters on stream s. Returns :line-start, :stream-end,
or :body to indicate the relative location of the next character on s.
Interprets comma as whitespace and semicolon as comment to end of line.
Does not interpret #! as comment to end of line because only one
character of lookahead is available. The stream must either be an
instance of LineNumberingPushbackReader or duplicate its behavior of both
supporting .unread and collapsing all of CR, LF, and CRLF to a single
\newline.

    
    
    
  


source

macro
Usage: (source n)
Prints the source code for the given symbol, if it can find it.
This requires that the symbol resolve to a Var defined in a
namespace for which the .cljs is in the classpath.

Example: (source filter)

    
    
    
  


source-fn

function
Usage: (source-fn env x)
Returns a string of the source code for the given symbol, if it can
find it.  This requires that the symbol resolve to a Var defined in
a namespace for which the .clj is in the classpath.  Returns nil if
it can't find the source.  For most REPL usage, 'source' is more
convenient.

Example: (source-fn 'filter)

    
    
    
  

cljs.repl.browser





Types



BrowserEnv

record

    Fields: []
Protocols: cljs.repl/IGetError, cljs.repl/IJavaScriptEnv, cljs.repl/IParseStacktrace, cljs.repl/IReplEnvOptions
Interfaces: clojure.lang.IHashEq, clojure.lang.IKeywordLookup, clojure.lang.ILookup, clojure.lang.IObj, clojure.lang.IPersistentMap, java.io.Serializable, java.util.Map

Public Variables and Functions



->BrowserEnv

function
Usage: (->BrowserEnv)
Positional factory function for class cljs.repl.browser.BrowserEnv.

    
    
    
  


browser-eval

function
Usage: (browser-eval form)
Given a string of JavaScript, evaluate it in the browser and return a map representing the
result of the evaluation. The map will contain the keys :type and :value. :type can be
:success, :exception, or :error. :success means that the JavaScript was evaluated without
exception and :value will contain the return value of the evaluation. :exception means that
there was an exception in the browser while evaluating the JavaScript and :value will
contain the error message. :error means that some other error has occured.

    
    
    
  


constrain-order

function
Usage: (constrain-order order f)
Elements to be printed in the REPL will arrive out of order. Ensure
that they are printed in the correct order.

    
    
    
  


load-javascript

function
Usage: (load-javascript repl-env provides url)
Accepts a REPL environment, a list of namespaces, and a URL for a
JavaScript file which contains the implementation for the list of
namespaces. Will load the JavaScript file into the REPL environment
if any of the namespaces have not already been loaded from the
ClojureScript REPL.

    
    
    
  


map->BrowserEnv

function
Usage: (map->BrowserEnv m#)
Factory function for class cljs.repl.browser.BrowserEnv, taking a map of keywords to field values.

    
    
    
  


repl-env

function
Usage: (repl-env & {:as opts})
Create a browser-connected REPL environment.

Options:

port:           The port on which the REPL server will run. Defaults to 9000.
working-dir:    The directory where the compiled REPL client JavaScript will
                be stored. Defaults to ".repl" with a ClojureScript version
                suffix, eg. ".repl-0.0-2138".
serve-static:   Should the REPL server attempt to serve static content?
                Defaults to true.
static-dir:     List of directories to search for static content. Defaults to
                ["." "out/"].
optimizations:  The level of optimization to use when compiling the client
                end of the REPL. Defaults to :simple.
src:            The source directory containing user-defined cljs files. Used to
                support reflection. Defaults to "src/".

    
    
    
  


send-for-eval

function
Usage: (send-for-eval form return-value-fn)
       (send-for-eval conn form return-value-fn)
Given a form and a return value function, send the form to the
browser for evaluation. The return value function will be called
when the return value is received.

    
    
    
  

cljs.repl.nashorn





Types



NashornEnv

record

    Fields: [engine debug]
Protocols: cljs.repl/IJavaScriptEnv, cljs.repl/IParseError, cljs.repl/IParseStacktrace, cljs.repl/IReplEnvOptions
Interfaces: clojure.lang.IHashEq, clojure.lang.IKeywordLookup, clojure.lang.ILookup, clojure.lang.IObj, clojure.lang.IPersistentMap, java.io.Serializable, java.util.Map

Public Variables and Functions



->NashornEnv

function
Usage: (->NashornEnv engine debug)
Positional factory function for class cljs.repl.nashorn.NashornEnv.

    
    
    
  


eval-resource

function
Usage: (eval-resource engine path debug)
Evaluate a file on the classpath in the engine.

    
    
    
  


map->NashornEnv

function
Usage: (map->NashornEnv m#)
Factory function for class cljs.repl.nashorn.NashornEnv, taking a map of keywords to field values.

    
    
    
  


repl-env

function
Usage: (repl-env & {:as opts})
Create a Nashorn repl-env for use with the repl/repl* method in Clojurescript.

    
    
    
  

cljs.repl.node





Types



NodeEnv

record

    Fields: [host port socket proc]
Protocols: cljs.repl/IJavaScriptEnv, cljs.repl/IParseError, cljs.repl/IReplEnvOptions
Interfaces: clojure.lang.IHashEq, clojure.lang.IKeywordLookup, clojure.lang.ILookup, clojure.lang.IObj, clojure.lang.IPersistentMap, java.io.Serializable, java.util.Map

Public Variables and Functions



->NodeEnv

function
Usage: (->NodeEnv host port socket proc)
Positional factory function for class cljs.repl.node.NodeEnv.

    
    
    
  


load-javascript

function
Usage: (load-javascript repl-env provides url)
Load a Closure JavaScript file into the Node REPL process.

    
    
    
  


map->NodeEnv

function
Usage: (map->NodeEnv m#)
Factory function for class cljs.repl.node.NodeEnv, taking a map of keywords to field values.

    
    
    
  


node-eval

function
Usage: (node-eval repl-env js)
Evaluate a JavaScript string in the Node REPL process.

    
    
    
  


repl-env

function
Usage: (repl-env & {:as options})
Construct a Node.js evalution environment. Can supply :host and :port.

    
    
    
  

cljs.repl.reflect





Public Variables and Functions



parse-param

function
Usage: (parse-param path)
Parses the query parameter of a path of the form "/reflect?var=foo"
into the vector ["var" "foo"].

    
    
    
  

cljs.repl.rhino





Types



RhinoEnv

record

    Fields: []
Protocols: cljs.repl/IGetError, cljs.repl/IJavaScriptEnv, cljs.repl/IParseStacktrace, cljs.repl/IReplEnvOptions
Interfaces: clojure.lang.IHashEq, clojure.lang.IKeywordLookup, clojure.lang.ILookup, clojure.lang.IObj, clojure.lang.IPersistentMap, java.io.Serializable, java.util.Map

Public Variables and Functions



->RhinoEnv

function
Usage: (->RhinoEnv)
Positional factory function for class cljs.repl.rhino.RhinoEnv.

    
    
    
  


load-file

function
Usage: (load-file repl-env opts src)
Load a JavaScript. This is needed to load JavaScript files before the Rhino
environment is bootstrapped. After bootstrapping load-javascript will be
used.

    
    
    
  


map->RhinoEnv

function
Usage: (map->RhinoEnv m#)
Factory function for class cljs.repl.rhino.RhinoEnv, taking a map of keywords to field values.

    
    
    
  


repl-env

function
Usage: (repl-env & {:as opts})
Returns a fresh JS environment, suitable for passing to repl.
Hang on to return for use across repl calls.

    
    
    
  

cljs.repl.server





Public Variables and Functions



connection

function
Usage: (connection)
Promise to return a connection when one is available. If a
connection is not available, store the promise in server/state.

    
    
    
  


dispatch-on

function
Usage: (dispatch-on method pred handler)
       (dispatch-on method {:as m})
Registers a handler to be dispatched based on a request method and a
predicate.

pred should be a function that accepts an options map, a connection,
and a request map and returns a boolean value based on whether or not
that request should be dispatched to the related handler.

    
    
    
  


parse-headers

function
Usage: (parse-headers header-lines)
Parse the headers of an HTTP POST request.

    
    
    
  


send-and-close

function
Usage: (send-and-close conn status form)
       (send-and-close conn status form content-type)
       (send-and-close conn status form content-type encoding)
Use the passed connection to send a form to the browser. Send a
proper HTTP response.

    
    
    
  


set-connection

function
Usage: (set-connection conn)
Given a new available connection, either use it to deliver the
connection which was promised or store the connection for later
use.

    
    
    
  


start

function
Usage: (start opts)
Start the server on the specified port.

    
    
    
  
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.