X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fcontent%2Fautocommands.js;h=eaaa1c785e1613b2c04ab535fc1f34d5d7f2d19f;hb=3d837eb266a3a01d424192aa4ec1a167366178c5;hp=31c3ad90826bcae04fddd387b0c39182311fb596;hpb=9044153cb63835e39b9de8ec4ade237c03e3888a;p=dactyl.git diff --git a/common/content/autocommands.js b/common/content/autocommands.js index 31c3ad9..eaaa1c7 100644 --- a/common/content/autocommands.js +++ b/common/content/autocommands.js @@ -1,10 +1,10 @@ // Copyright (c) 2006-2008 by Martin Stubenschrott // Copyright (c) 2007-2011 by Doug Kearns -// Copyright (c) 2008-2011 by Kris Maglione +// Copyright (c) 2008-2012 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -/* use strict */ +"use strict"; /** @scope modules */ @@ -103,31 +103,28 @@ var AutoCommands = Module("autocommands", { return cmds; } - XML.prettyPrinting = XML.ignoreWhitespace = false; - commandline.commandOutput( - - - - - { - template.map(hives, function (hive) - - - + - + - template.map(cmds(hive), function ([event, items]) - + - template.map(items, function (item, i) - - - - - ) + - ) + - ) - } -
----- Auto Commands -----
{hive.name} - {hive.filter}
{i == 0 ? event : ""}{item.filter.toXML ? item.filter.toXML() : item.filter}{item.command}
); + let table = ( + ["table", {}, + ["tr", { highlight: "Title" }, + ["td", { colspan: "3" }, "----- Auto Commands -----"]], + hives.map(function (hive) [ + ["tr", {}, + ["td", { colspan: "3" }, + ["span", { highlight: "Title" }, hive.name], + " ", hive.filter.toJSONXML(modules)]], + ["tr", { style: "height: .5ex;" }], + iter(cmds(hive)).map(function ([event, items]) [ + ["tr", { style: "height: .5ex;" }], + items.map(function (item, i) + ["tr", {}, + ["td", { highlight: "Title", style: "padding-left: 1em; padding-right: 1em;" }, + i == 0 ? event : ""], + ["td", {}, item.filter.toJSONXML ? item.filter.toJSONXML(modules) : String(item.filter)], + ["td", {}, String(item.command)]]), + ["tr", { style: "height: .5ex;" }]]).toArray(), + ["tr", { style: "height: .5ex;" }] + ])]); + commandline.commandOutput(table); }, /** @@ -168,7 +165,7 @@ var AutoCommands = Module("autocommands", { } }, { }, { - contexts: function () { + contexts: function initContexts() { update(AutoCommands.prototype, { hives: contexts.Hives("autocmd", AutoCmdHive), user: contexts.hives.autocmd.user, @@ -176,7 +173,7 @@ var AutoCommands = Module("autocommands", { matchingHives: function matchingHives(uri, doc) contexts.matchingGroups(uri, doc).autocmd }); }, - commands: function () { + commands: function initCommands() { commands.add(["au[tocmd]"], "Execute commands automatically on events", function (args) { @@ -249,7 +246,7 @@ var AutoCommands = Module("autocommands", { return void dactyl.echomsg(_("autocmd.noMatching")); let [event, url] = args; - let defaultURL = url || buffer.uri.spec; + let uri = util.createURI(url) || buffer.uri; let validEvents = Object.keys(config.autocommands); // TODO: add command validators @@ -257,7 +254,7 @@ var AutoCommands = Module("autocommands", { _("autocmd.cantExecuteAll")); dactyl.assert(validEvents.indexOf(event) >= 0, _("autocmd.noGroup", args)); - dactyl.assert(autocommands.get(event).some(function (c) c.patterns.some(function (re) re.test(defaultURL) ^ !re.result)), + dactyl.assert(autocommands.get(event).some(function (c) c.filter(uri)), _("autocmd.noMatching")); if (this.name == "doautoall" && dactyl.has("tabs")) { @@ -266,13 +263,13 @@ var AutoCommands = Module("autocommands", { for (let i = 0; i < tabs.count; i++) { tabs.select(i); // if no url arg is specified use the current buffer's URL - autocommands.trigger(event, { url: url || buffer.uri.spec }); + autocommands.trigger(event, { url: uri.spec }); } tabs.select(current); } else - autocommands.trigger(event, { url: defaultURL }); + autocommands.trigger(event, { url: uri.spec }); }, { argCount: "*", // FIXME: kludged for proper error message should be "1". completer: function (context) completion.autocmdEvent(context), @@ -280,15 +277,15 @@ var AutoCommands = Module("autocommands", { }); }); }, - completion: function () { + completion: function initCompletion() { completion.autocmdEvent = function autocmdEvent(context) { context.completions = Iterator(config.autocommands); }; }, - javascript: function () { + javascript: function initJavascript() { JavaScript.setCompleter(AutoCmdHive.prototype.get, [function () Iterator(config.autocommands)]); }, - options: function () { + options: function initOptions() { options.add(["eventignore", "ei"], "List of autocommand event names which should be ignored", "stringlist", "", @@ -299,4 +296,4 @@ var AutoCommands = Module("autocommands", { } }); -// vim: set fdm=marker sw=4 ts=4 et: +// vim: set fdm=marker sw=4 sts=4 ts=8 et: