1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-04 09:25:46 +01:00

Use a Struct for autocommands.

This is marginally clearer and will be helpful for autocommand groups
etc.
This commit is contained in:
Doug Kearns
2008-12-31 15:56:00 +11:00
parent 5f846990bc
commit 1e25799ef1

View File

@@ -37,12 +37,12 @@ function AutoCommands() //{{{
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
const AutoCommand = new Struct("event", "pattern", "command");
var store = []; var store = [];
function matchAutoCmd(autoCmd, event, regex) function matchAutoCmd(autoCmd, event, regex)
{ {
return (!event || autoCmd.event == event) && return (!event || autoCmd.event == event) && (!regex || autoCmd.pattern.source == regex);
(!regex || autoCmd.pattern.source == regex);
} }
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
@@ -71,6 +71,7 @@ function AutoCommands() //{{{
{ {
let [event, regex, cmd] = args; let [event, regex, cmd] = args;
let events = null; let events = null;
if (event) if (event)
{ {
// NOTE: event can only be a comma separated list for |:au {event} {pat} {cmd}| // NOTE: event can only be a comma separated list for |:au {event} {pat} {cmd}|
@@ -95,6 +96,7 @@ function AutoCommands() //{{{
{ {
if (event == "*") if (event == "*")
event = null; event = null;
if (args.bang) if (args.bang)
{ {
// TODO: "*" only appears to work in Vim when there is a {group} specified // TODO: "*" only appears to work in Vim when there is a {group} specified
@@ -187,8 +189,9 @@ function AutoCommands() //{{{
events = events.split(","); events = events.split(",");
liberator.log("DEPRECATED: the events list arg to autocommands.add() should be an array of event names"); liberator.log("DEPRECATED: the events list arg to autocommands.add() should be an array of event names");
} }
events.forEach(function (event) events.forEach(function (event) {
store.push({ event: event, pattern: RegExp(regex), command: cmd })); store.push(new AutoCommand(event, RegExp(regex), cmd));
});
}, },
get: function (event, regex) get: function (event, regex)