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

View File

@@ -77,6 +77,7 @@ liberator.Command = function (specs, description, action, extraInfo) //{{{
this.completer = extraInfo.completer || null;
this.options = extraInfo.options || [];
this.argCount = extraInfo.argCount || "";
this.hereDoc = extraInfo.hereDoc || false;
this.isUserCommand = extraInfo.isUserCommand || false;
this.replacementText = extraInfo.replacementText || null;
@@ -90,6 +91,7 @@ liberator.Command.prototype = {
special = !!special;
count = (count === undefined) ? -1 : count;
modifiers = modifiers || {};
let self = this;
// whenever the user specifies special options or fixed number of arguments
// we use our args parser instead of passing a string to the callback
@@ -99,6 +101,16 @@ liberator.Command.prototype = {
if (args == null)
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);
},
@@ -697,7 +709,7 @@ liberator.Commands = function () //{{{
var cmdlist = getMatchingUserCommands(cmd);
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 () { ... }"]
for each (cmd in cmdlist)));
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);

View File

@@ -666,7 +666,7 @@ liberator.Events = function () //{{{
function (args)
{
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);
},
{

View File

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

View File

@@ -324,25 +324,6 @@ const liberator = (function () //{{{
liberator.NEW_TAB : liberator.CURRENT_TAB);
}
else
{
// check for a heredoc
var matches = args.match(/(.*)<<\s*([^\s]+)$/);
if (matches && matches[2])
{
liberator.commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"),
function (code)
{
try
{
eval(matches[1] + "\n" + code);
}
catch (e)
{
liberator.echoerr(e.name + ": " + e.message);
}
});
}
else // single line javascript code
{
try
{
@@ -353,10 +334,10 @@ const liberator = (function () //{{{
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]"],