diff --git a/content/buffer.js b/content/buffer.js index 428420ce..fb21e740 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -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) { - liberator.template.map(row, function (d) - {d}) + liberator.template.map2(row, function (i, d) + {d}) } ) } diff --git a/content/commands.js b/content/commands.js index 8af5e1d9..bb175044 100644 --- a/content/commands.js +++ b/content/commands.js @@ -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); diff --git a/content/events.js b/content/events.js index febbe17d..d203aae6 100644 --- a/content/events.js +++ b/content/events.js @@ -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); }, { diff --git a/content/io.js b/content/io.js index 6d6d4e1d..399d73f1 100644 --- a/content/io.js +++ b/content/io.js @@ -321,16 +321,7 @@ liberator.IO = function () //{{{ function () { XML.prettyPrinting = false; - var list = - - { - liberator.template.map2(scriptNames, function (i, name) - - - - ) - } -
{i+1}{name}
.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" }); diff --git a/content/liberator.js b/content/liberator.js index 851fdafd..faa31186 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -325,38 +325,19 @@ const liberator = (function () //{{{ } else { - // check for a heredoc - var matches = args.match(/(.*)<<\s*([^\s]+)$/); - if (matches && matches[2]) + try { - liberator.commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"), - function (code) - { - try - { - eval(matches[1] + "\n" + code); - } - catch (e) - { - liberator.echoerr(e.name + ": " + e.message); - } - }); + liberator.eval(args); } - else // single line javascript code + catch (e) { - try - { - liberator.eval(args); - } - catch (e) - { - liberator.echoerr(e.name + ": " + e.message); - } + 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]"],