mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 08:27:59 +01:00
Add :if/:elseif/:else/:endif contiditionals. Also add comment help tag.
--HG-- extra : rebase_source : 6b6e15157d2fae436aa812df2db94a36a5e7ce79
This commit is contained in:
@@ -1165,7 +1165,7 @@ const CommandLine = Module("commandline", {
|
|||||||
dactyl.registerObserver("echoLine", observe, true);
|
dactyl.registerObserver("echoLine", observe, true);
|
||||||
dactyl.registerObserver("echoMultiline", observe, true);
|
dactyl.registerObserver("echoMultiline", observe, true);
|
||||||
function observe(str, highlight, dom) {
|
function observe(str, highlight, dom) {
|
||||||
buffer.push(dom ? util.domToString(dom) : str)
|
buffer.push(dom && !isString(str) ? util.domToString(dom) : str)
|
||||||
}
|
}
|
||||||
dactyl.trapErrors.apply(dactyl, [fn, self].concat(Array.slice(arguments, 2)));
|
dactyl.trapErrors.apply(dactyl, [fn, self].concat(Array.slice(arguments, 2)));
|
||||||
return buffer.join("\n");
|
return buffer.join("\n");
|
||||||
|
|||||||
@@ -145,8 +145,12 @@ const Command = Class("Command", {
|
|||||||
if (args.bang && !this.bang)
|
if (args.bang && !this.bang)
|
||||||
throw FailedAssertion("E477: No ! allowed");
|
throw FailedAssertion("E477: No ! allowed");
|
||||||
|
|
||||||
|
|
||||||
dactyl.trapErrors(function exec(command) {
|
dactyl.trapErrors(function exec(command) {
|
||||||
this.action(args, modifiers);
|
if (this.always)
|
||||||
|
this.always(args, modifiers);
|
||||||
|
if (!io.sourcing || !io.sourcing.noExecute)
|
||||||
|
this.action(args, modifiers);
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1245,6 +1249,62 @@ const Commands = Module("commands", {
|
|||||||
completer: function (context) completion.userCommand(context)
|
completer: function (context) completion.userCommand(context)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function checkStack(cmd) {
|
||||||
|
util.assert(io.sourcing && io.sourcing.stack &&
|
||||||
|
io.sourcing.stack[cmd] && io.sourcing.stack[cmd].length,
|
||||||
|
"Invalid use of conditional");
|
||||||
|
}
|
||||||
|
function pop(cmd) {
|
||||||
|
checkStack(cmd);
|
||||||
|
return io.sourcing.stack[cmd].pop();
|
||||||
|
}
|
||||||
|
function push(cmd, value) {
|
||||||
|
util.assert(io.sourcing, "Invalid use of conditional");
|
||||||
|
if (arguments.length < 2)
|
||||||
|
value = io.sourcing.noExecute;
|
||||||
|
io.sourcing.stack = io.sourcing.stack || {};
|
||||||
|
io.sourcing.stack[cmd] = (io.sourcing.stack[cmd] || []).concat([value])
|
||||||
|
}
|
||||||
|
|
||||||
|
commands.add(["if"],
|
||||||
|
"Execute commands until the next :elseif, :else, or :endif only if the argument returns true",
|
||||||
|
function (args) { io.sourcing.noExecute = !dactyl.userEval(args[0]); },
|
||||||
|
{
|
||||||
|
always: function (args) { push("if") },
|
||||||
|
argCount: "1",
|
||||||
|
literal: 0
|
||||||
|
});
|
||||||
|
commands.add(["elsei[f]", "elif"],
|
||||||
|
"Execute commands until the next :elseif, :else, or :endif only if the argument returns true",
|
||||||
|
function (args) {},
|
||||||
|
{
|
||||||
|
always: function (args) {
|
||||||
|
checkStack("if");
|
||||||
|
io.sourcing.noExecute = io.sourcing.stack.if.slice(-1)[0] ||
|
||||||
|
!io.sourcing.noExecute || !dactyl.userEval(args[0]);
|
||||||
|
},
|
||||||
|
argCount: "1",
|
||||||
|
literal: 0
|
||||||
|
});
|
||||||
|
commands.add(["el[se]"],
|
||||||
|
"Execute commands until the next :endif only if the previous conditionals were not executed",
|
||||||
|
function (args) {},
|
||||||
|
{
|
||||||
|
always: function (args) {
|
||||||
|
checkStack("if");
|
||||||
|
io.sourcing.noExecute = io.sourcing.stack.if.slice(-1)[0] ||
|
||||||
|
!io.sourcing.noExecute;
|
||||||
|
},
|
||||||
|
argCount: "0"
|
||||||
|
});
|
||||||
|
commands.add(["en[dif]", "fi"],
|
||||||
|
"Ends a string of :if/:elseif/:else conditionals",
|
||||||
|
function (args) {},
|
||||||
|
{
|
||||||
|
always: function (args) { io.sourcing.noExecute = pop("if") },
|
||||||
|
argCount: "0"
|
||||||
|
});
|
||||||
|
|
||||||
commands.add(["y[ank]"],
|
commands.add(["y[ank]"],
|
||||||
"Yanks the output of the given command to the clipboard",
|
"Yanks the output of the given command to the clipboard",
|
||||||
function (args) {
|
function (args) {
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
along with paren matching and syntax error highlighting.
|
along with paren matching and syntax error highlighting.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<h2 tag="javascript-evaluation">JavaScript evaluation</h2>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<tags>:ec :echo</tags>
|
<tags>:ec :echo</tags>
|
||||||
<spec>:ec<oa>ho</oa> <a>expr</a></spec>
|
<spec>:ec<oa>ho</oa> <a>expr</a></spec>
|
||||||
@@ -134,6 +136,8 @@
|
|||||||
</description>
|
</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
<h2 tag="global-variables">Global Variables</h2>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
<tags>:let</tags>
|
<tags>:let</tags>
|
||||||
<spec>:let <a>var-name</a> [+-.]= <a>expr1</a></spec>
|
<spec>:let <a>var-name</a> [+-.]= <a>expr1</a></spec>
|
||||||
@@ -166,6 +170,55 @@
|
|||||||
</description>
|
</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
<h2 tag="conditionals">Conditionals</h2>
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<tags>:if</tags>
|
||||||
|
<spec>:if <a>expr</a></spec>
|
||||||
|
<description>
|
||||||
|
<p>
|
||||||
|
Execute commands until the next <ex>:elseif</ex>, <ex>:else</ex>,
|
||||||
|
or <ex>:endif</ex> only if the JavaScript expression <a>expr</a>
|
||||||
|
evaluates to a true value.
|
||||||
|
</p>
|
||||||
|
</description>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<tags>:endif :en :fi</tags>
|
||||||
|
<spec>:en<oa>dif</oa></spec>
|
||||||
|
<description>
|
||||||
|
<p>
|
||||||
|
Ends a string of <ex>:if</ex>/<ex>:elseif</ex>/<ex>:else</ex>
|
||||||
|
conditionals.
|
||||||
|
</p>
|
||||||
|
</description>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<tags>:elseif :elsei :elif</tags>
|
||||||
|
<spec>:elsei<oa>f</oa> <a>expr</a></spec>
|
||||||
|
<description>
|
||||||
|
<p>
|
||||||
|
Execute commands until the next <ex>:elseif</ex>, <ex>:else</ex>,
|
||||||
|
or <ex>:endif</ex> only if the JavaScript expression <a>expr</a>
|
||||||
|
evaluates to a true value.
|
||||||
|
</p>
|
||||||
|
</description>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<tags>:else :el</tags>
|
||||||
|
<spec>:el<oa>se</oa></spec>
|
||||||
|
<description>
|
||||||
|
<p>
|
||||||
|
Execute commands until the next <ex>:endif</ex> only if the
|
||||||
|
previous conditionals were not executed.
|
||||||
|
</p>
|
||||||
|
</description>
|
||||||
|
</item>
|
||||||
|
|
||||||
</document>
|
</document>
|
||||||
|
|
||||||
<!-- vim:se sts=4 sw=4 et: -->
|
<!-- vim:se sts=4 sw=4 et: -->
|
||||||
|
|||||||
@@ -242,7 +242,10 @@ This file contains a list of all available commands, mappings and options.
|
|||||||
<dt><ex>:echo</ex></dt> <dd>Echo the expression</dd>
|
<dt><ex>:echo</ex></dt> <dd>Echo the expression</dd>
|
||||||
<dt><ex>:echoerr</ex></dt> <dd>Echo the expression as an error message</dd>
|
<dt><ex>:echoerr</ex></dt> <dd>Echo the expression as an error message</dd>
|
||||||
<dt><ex>:echomsg</ex></dt> <dd>Echo the expression as an informational message</dd>
|
<dt><ex>:echomsg</ex></dt> <dd>Echo the expression as an informational message</dd>
|
||||||
|
<dt><ex>:else</ex></dt> <dd>Execute commands until the next <ex>:endif</ex> only if the previous conditionals were not executed</dd>
|
||||||
|
<dt><ex>:elseif</ex></dt> <dd>Execute commands until the next :elseif, <ex>:else</ex>, or :endif only if the argument returns true</dd>
|
||||||
<dt><ex>:emenu</ex></dt> <dd>Execute the specified menu item from the command line</dd>
|
<dt><ex>:emenu</ex></dt> <dd>Execute the specified menu item from the command line</dd>
|
||||||
|
<dt><ex>:endif</ex></dt> <dd>Ends a string of <ex>:if</ex>/<ex>:elseif</ex>/<ex>:else</ex> conditionals</dd>
|
||||||
<dt><ex>:execute</ex></dt> <dd>Execute the argument as an Ex command</dd>
|
<dt><ex>:execute</ex></dt> <dd>Execute the argument as an Ex command</dd>
|
||||||
<dt><ex>:extadd</ex></dt> <dd>Install an extension</dd>
|
<dt><ex>:extadd</ex></dt> <dd>Install an extension</dd>
|
||||||
<dt><ex>:extdelete</ex></dt> <dd>Uninstall an extension</dd>
|
<dt><ex>:extdelete</ex></dt> <dd>Uninstall an extension</dd>
|
||||||
@@ -262,6 +265,7 @@ This file contains a list of all available commands, mappings and options.
|
|||||||
<dt><ex>:history</ex></dt> <dd>Show recently visited URLs</dd>
|
<dt><ex>:history</ex></dt> <dd>Show recently visited URLs</dd>
|
||||||
<dt><ex>:iabbrev</ex></dt> <dd>Abbreviate a key sequence in Insert mode</dd>
|
<dt><ex>:iabbrev</ex></dt> <dd>Abbreviate a key sequence in Insert mode</dd>
|
||||||
<dt><ex>:iabclear</ex></dt> <dd>Remove all abbreviations in Insert mode</dd>
|
<dt><ex>:iabclear</ex></dt> <dd>Remove all abbreviations in Insert mode</dd>
|
||||||
|
<dt><ex>:if</ex></dt> <dd>Execute commands until the next <ex>:elseif</ex>, <ex>:else</ex>, or <ex>:endif</ex> only if the argument returns true</dd>
|
||||||
<dt><ex>:imap</ex></dt> <dd>Map a key sequence in Insert mode</dd>
|
<dt><ex>:imap</ex></dt> <dd>Map a key sequence in Insert mode</dd>
|
||||||
<dt><ex>:imapclear</ex></dt> <dd>Remove all mappings in Insert mode</dd>
|
<dt><ex>:imapclear</ex></dt> <dd>Remove all mappings in Insert mode</dd>
|
||||||
<dt><ex>:inoremap</ex></dt> <dd>Map a key sequence without remapping keys in Insert mode</dd>
|
<dt><ex>:inoremap</ex></dt> <dd>Map a key sequence without remapping keys in Insert mode</dd>
|
||||||
|
|||||||
@@ -169,6 +169,8 @@
|
|||||||
on a single line, you can use
|
on a single line, you can use
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<p>See also <t>ex-scripts</t> below.</p>
|
||||||
|
|
||||||
<code><ex>:js</ex> <<<em>EOF</em>
|
<code><ex>:js</ex> <<<em>EOF</em>
|
||||||
<hl key="Object">var</hl> hello = <hl key="Key">function</hl> () {
|
<hl key="Object">var</hl> hello = <hl key="Key">function</hl> () {
|
||||||
alert(<str>Hello world</str>);
|
alert(<str>Hello world</str>);
|
||||||
@@ -228,6 +230,54 @@
|
|||||||
</description>
|
</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
<h3 tag="ex-scripts">Ex Command Scripts</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Ex command scripts are similar to both entering commands on the
|
||||||
|
<link topic="command-line">command line</link> and to Vim
|
||||||
|
scripts, but with some notable differences.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p tag="multiline-commands">
|
||||||
|
Commands in Ex command scripts can span multiple lines by
|
||||||
|
prefixing the second and further lines with a <em>\</em>
|
||||||
|
character. For instance, the following all define commands whose
|
||||||
|
definitions span multiple lines.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<code><ex>:command!</ex> <em>foo</em>
|
||||||
|
\ <em>-description</em> <str>A command that frobs bars</str>
|
||||||
|
\ <ex>:javascript</ex> frob(content.bar)</code>
|
||||||
|
|
||||||
|
<code><ex>:style</ex> <em>-name</em> <str>foo</str>
|
||||||
|
\ <str delim="'">foobar.com</str>
|
||||||
|
\ p:first-line { <em>font-variant:</em> <str delim="">small-caps</str>; }
|
||||||
|
\ div#side-bar > :first-child { <em>display</em>: <str delim="">none</str>; }</code>
|
||||||
|
|
||||||
|
<code><ex>:command</ex> <em>do-some-stuff</em>
|
||||||
|
\ <em>-description</em> <str>A command does some stuff in JavaScript</str>
|
||||||
|
\ <ex>:javascript</ex> <<<em>EOF</em>
|
||||||
|
\ window.do(<str>some</str>);
|
||||||
|
\ window.do(<str>stuff</str>);
|
||||||
|
\<em>EOF</em></code>
|
||||||
|
|
||||||
|
<code><ex>:command</ex> <em>do-some-stuff</em>
|
||||||
|
\ <em>-description</em> <str>A command does some stuff in JavaScript</str>
|
||||||
|
\ <ex>:javascript</ex>
|
||||||
|
\\ window.do(<str>some</str>);
|
||||||
|
\\ window.do(<str>stuff</str>);</code>
|
||||||
|
|
||||||
|
<p tag="comments">
|
||||||
|
Lines may be commented out by prefixing them with a <em>"</em>
|
||||||
|
character.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<code> <html:span style="color: #444"> " This is a comment</html:span>
|
||||||
|
foo bar <html:span style="color: #444">" This is a comment</html:span>
|
||||||
|
<str> This is not a comment</str>
|
||||||
|
foo bar <str> This is not a cumment</str>
|
||||||
|
</code>
|
||||||
|
|
||||||
<h2 tag="profile profiling">Profiling</h2>
|
<h2 tag="profile profiling">Profiling</h2>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
|
|||||||
@@ -78,6 +78,7 @@
|
|||||||
* Added "passwords" and "venkman" dialogs to :dialog.
|
* Added "passwords" and "venkman" dialogs to :dialog.
|
||||||
* Added :extupdate command.
|
* Added :extupdate command.
|
||||||
* Replaced 'focuscontent' with 'strictfocus'.
|
* Replaced 'focuscontent' with 'strictfocus'.
|
||||||
|
* Add :if/:elseif/:else/:endif conditionals.
|
||||||
* Changed 'urlseparator' default value to '|'.
|
* Changed 'urlseparator' default value to '|'.
|
||||||
* Added 'wildanchor' option.
|
* Added 'wildanchor' option.
|
||||||
* Added -javascript option to :abbrev and :map.
|
* Added -javascript option to :abbrev and :map.
|
||||||
|
|||||||
Reference in New Issue
Block a user