1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 12:52:28 +01:00

Make some stuff nicer. Add heredoc support to :sty

This commit is contained in:
Kris Maglione
2008-10-04 00:00:25 +00:00
parent 267535d9c7
commit 40ff96452e
5 changed files with 27 additions and 41 deletions

View File

@@ -664,10 +664,11 @@ liberator.Buffer = function () //{{{
"Add or list user styles", "Add or list user styles",
function (args, special) function (args, special)
{ {
let [, filter, css] = args.match(/([^\s]+)\s*(.*)/) || []; let [, filter, css] = args.match(/([^\s]+)\s*((?:.|\n)*)/) || [];
if (!css) if (!css)
{ {
let str = liberator.template.tabular(["", "Filter", "CSS"], let str = liberator.template.tabular(["", "Filter", "CSS"],
["padding: 0 1em 0 1ex; vertical-align: top", "padding: 0 1em 0 0; vertical-align: top"],
([i, style[0], style[1]] for ([i, style] in styles) ([i, style[0], style[1]] for ([i, style] in styles)
if (!filter || style[0] == filter))); if (!filter || style[0] == filter)));
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
@@ -686,6 +687,7 @@ liberator.Buffer = function () //{{{
[content.location.href, ""]] [content.location.href, ""]]
.concat([[s[0], ""] for ([i, s] in styles)]) .concat([[s[0], ""] for ([i, s] in styles)])
], ],
hereDoc: true,
}); });
liberator.commands.add(["dels[tyle]"], liberator.commands.add(["dels[tyle]"],
@@ -1988,7 +1990,7 @@ liberator.template = {
return table; return table;
}, },
tabular: function (headings, iter) tabular: function (headings, style, iter)
{ {
/* This might be mind-bogglingly slow. We'll see. */ /* This might be mind-bogglingly slow. We'll see. */
return this.generic( return this.generic(
@@ -2003,8 +2005,8 @@ liberator.template = {
this.map(iter, function (row) this.map(iter, function (row)
<tr> <tr>
{ {
liberator.template.map(row, function (d) liberator.template.map2(row, function (i, d)
<td>{d}</td>) <td style={style[i] || ""}>{d}</td>)
} }
</tr>) </tr>)
} }

View File

@@ -77,6 +77,7 @@ liberator.Command = function (specs, description, action, extraInfo) //{{{
this.completer = extraInfo.completer || null; this.completer = extraInfo.completer || null;
this.options = extraInfo.options || []; this.options = extraInfo.options || [];
this.argCount = extraInfo.argCount || ""; this.argCount = extraInfo.argCount || "";
this.hereDoc = extraInfo.hereDoc || false;
this.isUserCommand = extraInfo.isUserCommand || false; this.isUserCommand = extraInfo.isUserCommand || false;
this.replacementText = extraInfo.replacementText || null; this.replacementText = extraInfo.replacementText || null;
@@ -90,6 +91,7 @@ liberator.Command.prototype = {
special = !!special; special = !!special;
count = (count === undefined) ? -1 : count; count = (count === undefined) ? -1 : count;
modifiers = modifiers || {}; modifiers = modifiers || {};
let self = this;
// whenever the user specifies special options or fixed number of arguments // whenever the user specifies special options or fixed number of arguments
// we use our args parser instead of passing a string to the callback // we use our args parser instead of passing a string to the callback
@@ -99,6 +101,16 @@ liberator.Command.prototype = {
if (args == null) if (args == null)
return false; return false;
} }
else if (this.hereDoc)
{
let matches = args.match(/(.*)<<\s*([^\s]+)$/);
if (matches && matches[2])
{
liberator.commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"),
function (args) self.action.call(self, matches[1] + "\n" + args, special, count, modifiers));
return;
}
}
return this.action.call(this, args, special, count, modifiers); return this.action.call(this, args, special, count, modifiers);
}, },
@@ -697,7 +709,7 @@ liberator.Commands = function () //{{{
var cmdlist = getMatchingUserCommands(cmd); var cmdlist = getMatchingUserCommands(cmd);
if (cmdlist.length > 0) if (cmdlist.length > 0)
{ {
var str = liberator.template.tabular(["Name", "Args", "Definition"], var str = liberator.template.tabular(["Name", "Args", "Definition"], [],
([cmd.name, "*", cmd.replacementText || "function () { ... }"] ([cmd.name, "*", cmd.replacementText || "function () { ... }"]
for each (cmd in cmdlist))); for each (cmd in cmdlist)));
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);

View File

@@ -666,7 +666,7 @@ liberator.Events = function () //{{{
function (args) function (args)
{ {
XML.prettyPrinting = false; XML.prettyPrinting = false;
var str = liberator.template.tabular(["Macro", "Keys"], liberator.events.getMacros(args)); var str = liberator.template.tabular(["Macro", "Keys"], [], liberator.events.getMacros(args));
liberator.echo(str, liberator.commandline.FORCE_MULTILINE); liberator.echo(str, liberator.commandline.FORCE_MULTILINE);
}, },
{ {

View File

@@ -321,16 +321,7 @@ liberator.IO = function () //{{{
function () function ()
{ {
XML.prettyPrinting = false; XML.prettyPrinting = false;
var list = var list = liberator.template.tabular(["Idx", "Filename"], ["text-align: right"], Iterator(scriptNames));
<table>
{
liberator.template.map2(scriptNames, function (i, name)
<tr>
<td style="text-align: right">{i+1}</td>
<td>{name}</td>
</tr>)
}
</table>.toXMLString();
liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); liberator.commandline.echo(list, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}, },
{ argCount: "0" }); { argCount: "0" });

View File

@@ -325,38 +325,19 @@ const liberator = (function () //{{{
} }
else else
{ {
// check for a heredoc try
var matches = args.match(/(.*)<<\s*([^\s]+)$/);
if (matches && matches[2])
{ {
liberator.commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"), liberator.eval(args);
function (code)
{
try
{
eval(matches[1] + "\n" + code);
}
catch (e)
{
liberator.echoerr(e.name + ": " + e.message);
}
});
} }
else // single line javascript code catch (e)
{ {
try liberator.echoerr(e.name + ": " + e.message);
{
liberator.eval(args);
}
catch (e)
{
liberator.echoerr(e.name + ": " + e.message);
}
} }
} }
}, },
{ {
completer: function (filter) liberator.completion.javascript(filter) completer: function (filter) liberator.completion.javascript(filter),
hereDoc: true,
}); });
liberator.commands.add(["norm[al]"], liberator.commands.add(["norm[al]"],