eval.xml

expressionexprevaljavascript
Expression evaluation

Contents

  1. JavaScript evaluation
  2. Global Variables
  3. Conditionals

Much of the power of Pentadactyl lies in its scriptable expression evaluation. Pentadactyl understands two kinds of expressions: Ex commands, and JavaScript. Ex commands are simple, easy to type, and readily accessible from the 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 Pentadactyl and Firefox. Both expression evaluation methods support sophisticated expression completion, including option lists and descriptions thereof, along with parentheses matching and syntax error highlighting.

javascript-evaluation
JavaScript evaluation

:ec:echo
:ec[ho] {expr}

Echo a JavaScript expression. {expr} may be a simple quoted string, in which case it is shown in the 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
:echoe[rr] {expr}

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

:echom:echomsg
:echom[sg] {expr}

Echo the expression as an informational message. Just like :ec[ho] but also saves the message in the message history.

:exe:execute
:exe[cute] {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.

Note: Unlike Vim this only supports a single argument.

:js:javas:javascript
:javas[cript] {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 c_<Tab> 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 c_<Tab> press to commence.

REPL
:js! [context]
:js!:javas!:javascript!
:javas[cript]! [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
Global Variables

:let
:let {var-name} [+-.]= {expr1}
:let {var-name}
:let

Deprecated: 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
:unl[et][!] {name} …

Deprecated: 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
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
:en[dif]

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

:elseif:elsei:elif
:elsei[f] {expr}

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

:else:el
:el[se]

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