Expression evaluation

Much of the power of &dactyl.appName; lies in its scriptable expression evaluation. &dactyl.appName; understands two kinds of expressions: Ex commands, and JavaScript. Ex commands are simple, easy to type, and readily accessible from the &tag.command-line;. They form a core part of the user interface. JavaScript, on the other hand, is much less straightforward, but allows for any number of complex actions to be executed, with full access to all of the internals of &dactyl.appName; and &dactyl.host;. Both expression evaluation methods support sophisticated expression completion, including option lists and descriptions thereof, along with parentheses matching and syntax error highlighting.

JavaScript evaluation

:ec :echo :echo expr

Echo a JavaScript expression. expr may be a simple quoted string, in which case it is shown in the &tag.status-line;, or any arbitrary JavaScript expression. If the expression results in anything other than a string, it is pretty-printed in a multi-line frame just above the command line. The output depends on the type of object. Functions display their source, DOM nodes display the pretty-printed XML of the top-level node, XML literals are rendered as page content, and all other objects display their string representation and all of their enumerable properties.

See also :javascript.

:echoe :echoerr :echoerr expr

Echo the expression as an error message. Just like :echo but echoes the result highlighted as with the ErrorMsg group and saves it to the message history.

:echom :echomsg :echomsg expr

Echo the expression as an informational message. Just like :echo but also saves the message in the message history.

:exe :execute :execute expr

Execute the Ex command string that results from the evaluation of the JavaScript expression expr. For example,

:execute open + content.location.host

opens the homepage of the currently opened site.

Unlike Vim this only supports a single argument.
:js :javas :javascript :javascript cmd :javascript <<endpattern cmd ... endpattern

Evaluates the given cmd as JavaScript. Behaves exactly as :echo, except that the result is not printed. Any exception raised by the evaluation will, however, be displayed as an error message and appended to :messages.

:javascript alert(Hello world) will open a dialog window with the message Hello world.

Moreover, multi-line scripts can be executed with shell-like here document syntax. For example, the following,

:javascript <<EOF for each (var tab in tabs.visibleTabs) tab.linkedBrowser.reload(); EOF

will reload all visible tabs.

Moreover, sophisticated, context-sensitive completion is available for JavaScript code, which extends to property names, object keys, and programmable completion for string function arguments. The completion code is designed to be both as safe and as powerful as possible. Expressions in a given command-line session will only be evaluated once, and, with auto-completion turned on, any completion which requires a function to be executed requires an explicit press to commence.

REPL :js! context :js! :javas! :javascript! :javascript! context

Starts the JavaScript Read Eval Print Loop, where JavaScript statements are entered and evaluated, their results printed, and the input modified and entered again. Within the REPL, the results of a given evaluation are available as variables named for the given prompt.

If context is given, then statements are executed in that global context.

js1> ({ foo: bar })[object Object]:: foo: "bar"js2> js1.foobar

Global Variables

:let :let var-name [+-.]= expr1 :let var-name :let All scripts which make use of :let should be updated to use the simpler and more powerful options system instead.

Sets or lists a variable. Sets the variable var-name to the value of the expression expr1. If no expression is given, the value of the variable is displayed. Without arguments, displays a list of all variables. This functionality has few useful applications and so is deprecated.

:unl :unlet :unlet! name … All scripts which make use of :unlet should be updated to use the simpler and more powerful options system instead.

Deletes the named variables. When ! is given, no error message is output for non-existing variables.

Conditionals

:if :if expr

Execute commands until the next :elseif, :else, or :endif only if the JavaScript expression expr evaluates to a true value.

:endif :en :fi :endif

Ends a string of :if/:elseif/:else conditionals.

:elseif :elsei :elif :elseif expr

Execute commands until the next :elseif, :else, or :endif only if the JavaScript expression expr evaluates to a true value.

:else :el :else

Execute commands until the next :endif only if the previous conditionals were not executed.