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

More groups work, including -args flag and proper serialization.

--HG--
branch : groups
This commit is contained in:
Kris Maglione
2011-02-06 14:07:18 -05:00
parent 78e8c3c20e
commit 4211f6ee07
4 changed files with 57 additions and 17 deletions

View File

@@ -146,7 +146,11 @@ var AutoCommands = Module("autocommands", {
let uri = args.url ? util.newURI(args.url) : buffer.uri; let uri = args.url ? util.newURI(args.url) : buffer.uri;
event = event.toLowerCase(); event = event.toLowerCase();
for (let hive in this.hives.iterValues()) for (let hive in this.hives.iterValues()) {
let args = update({},
hive.group.argsExtra(arguments[1]),
arguments[1]);
for (let autoCmd in values(hive._store)) for (let autoCmd in values(hive._store))
if (autoCmd.eventName === event && autoCmd.filter(uri)) { if (autoCmd.eventName === event && autoCmd.filter(uri)) {
if (!lastPattern || lastPattern !== String(autoCmd.filter)) if (!lastPattern || lastPattern !== String(autoCmd.filter))
@@ -157,6 +161,7 @@ var AutoCommands = Module("autocommands", {
dactyl.trapErrors(autoCmd.command, autoCmd, args); dactyl.trapErrors(autoCmd.command, autoCmd, args);
} }
}
} }
}, { }, {
}, { }, {

View File

@@ -154,9 +154,12 @@ var Command = Class("Command", {
throw FailedAssertion("E477: No ! allowed"); throw FailedAssertion("E477: No ! allowed");
return !dactyl.trapErrors(function exec(command) { return !dactyl.trapErrors(function exec(command) {
// update({}, command.hive.group.argsExtra(args), args);
if (this.always) if (this.always)
this.always(args, modifiers); this.always(args, modifiers);
if (!contexts.context || !contexts.context.noExecute)
if (!context || !context.noExecute)
this.action(args, modifiers); this.action(args, modifiers);
}, this); }, this);
}, },
@@ -569,12 +572,13 @@ var Commands = Module("commands", {
string = string(tokens || {}); string = string(tokens || {});
let lines = string.split(/\r\n|[\r\n]/); let lines = string.split(/\r\n|[\r\n]/);
let startLine = context.line;
for (var i = 0; i < lines.length && !context.finished; i++) { for (var i = 0; i < lines.length && !context.finished; i++) {
// Deal with editors from Silly OSs. // Deal with editors from Silly OSs.
let line = lines[i].replace(/\r$/, ""); let line = lines[i].replace(/\r$/, "");
context.line = context.line + i; context.line = startLine + i;
// Process escaped new lines // Process escaped new lines
while (i < lines.length && /^\s*\\/.test(lines[i + 1])) while (i < lines.length && /^\s*\\/.test(lines[i + 1]))

View File

@@ -9,7 +9,7 @@ var Group = Class("Group", {
const self = this; const self = this;
this.name = name; this.name = name;
this.description = description; this.description = description;
this.filter = filter || function (uri) true; this.filter = filter || Group.defaultFilter;
this.persist = persist || false; this.persist = persist || false;
this.subGroups = []; this.subGroups = [];
}, },
@@ -20,6 +20,8 @@ var Group = Class("Group", {
subGroup.cleanup(); subGroup.cleanup();
}, },
argsExtra: function argsExtra() ({}),
get toStringParams() [this.name], get toStringParams() [this.name],
get builtin() contexts.builtinGroups.indexOf(this) >= 0, get builtin() contexts.builtinGroups.indexOf(this) >= 0,
@@ -52,6 +54,8 @@ var Group = Class("Group", {
groupsProto: {}, groupsProto: {},
defaultFilter: Class.memoize(function () this.compileFilter(["*"])),
subGroupMap: {}, subGroupMap: {},
SubGroup: Class("SubGroup", Class.Property, { SubGroup: Class("SubGroup", Class.Property, {
@@ -91,7 +95,7 @@ var Contexts = Module("contexts", {
this.groupMap = {}; this.groupMap = {};
this.subGroupProto = {}; this.subGroupProto = {};
this.system = this.addGroup("builtin", "Builtin items"); this.builtin = this.addGroup("builtin", "Builtin items");
this.user = this.addGroup("user", "User-defined items", null, true); this.user = this.addGroup("user", "User-defined items", null, true);
this.builtinGroups = [this.system, this.user]; this.builtinGroups = [this.system, this.user];
}, },
@@ -295,7 +299,7 @@ var Contexts = Module("contexts", {
let filter = Group.compileFilter(args["-locations"]); let filter = Group.compileFilter(args["-locations"]);
if (!group) if (!group)
group = contexts.addGroup(name, args["-description"], filter, !args["-nopersist"]); group = contexts.addGroup(name, args["-description"], filter, !args["-nopersist"]);
else { else if (!group.builtin) {
if (args.has("-locations")) if (args.has("-locations"))
group.filter = filter; group.filter = filter;
if (args.has("-description")) if (args.has("-description"))
@@ -304,6 +308,12 @@ var Contexts = Module("contexts", {
group.persist = !args["-nopersist"] group.persist = !args["-nopersist"]
} }
if (!group.builtin && args.has("-args")) {
group.argsExtra = contexts.bindMacro({ literalArg: "return " + args["-args"] },
"-javascript", util.identity);
group.args = args["-args"];
}
if (args.context) if (args.context)
args.context.group = group; args.context.group = group;
}, },
@@ -316,6 +326,11 @@ var Contexts = Module("contexts", {
}, },
keepQuotes: true, keepQuotes: true,
options: [ options: [
{
names: ["-args", "-a"],
description: "JavaScript Object which augments the arguments passed to commands, mappings, and autocommands",
type: CommandOption.STRING
},
{ {
names: ["-description", "-desc", "-d"], names: ["-description", "-desc", "-d"],
description: "A description of this group", description: "A description of this group",
@@ -332,7 +347,26 @@ var Contexts = Module("contexts", {
names: ["-nopersist", "-n"], names: ["-nopersist", "-n"],
description: "Do not save this group to an auto-generated RC file" description: "Do not save this group to an auto-generated RC file"
} }
] ],
serialGroup: 20,
serialize: function () [
{
command: this.name,
bang: true,
options: iter([v, typeof group[k] == "boolean" ? null : group[k]]
// FIXME: this map is expressed multiple times
for ([k, v] in Iterator({
args: "-args",
description: "-description",
filter: "-locations"
}))
if (group[k])).toObject(),
arguments: [group.name],
ignoreDefaults: true
}
for (group in values(contexts.activeGroups()))
if (!group.builtin && group.persist)
].concat([{ command: this.name, arguments: ["user"] }])
}); });
commands.add(["delg[roup]"], commands.add(["delg[roup]"],

View File

@@ -107,8 +107,9 @@ var Map = Class("Map", {
.map(function ([i, prop]) [prop, this[i]], arguments) .map(function ([i, prop]) [prop, this[i]], arguments)
.toObject(); .toObject();
if (!args.context) args = update({ context: contexts.context },
args.context = contexts.context; this.hive.group.argsExtra(args),
args);
let self = this; let self = this;
function repeat() self.action(args) function repeat() self.action(args)
@@ -531,20 +532,16 @@ var Mappings = Module("mappings", {
serialize: function () { serialize: function () {
return this.name != "map" ? [] : return this.name != "map" ? [] :
array(mappings.userHives) array(mappings.userHives)
.filter(function (h) !h.noPersist) .filter(function (h) h.group.persist)
.map(function (hive) [ .map(function (hive) [
{
command: "mapgroup",
bang: true,
arguments: [hive.name, String(hive.filter)].slice(0, hive.name == "user" ? 1 : 2)
}
].concat([
{ {
command: "map", command: "map",
options: array([ options: array([
hive !== mappings.user && ["-group", hive.group.name],
["-modes", uniqueModes(map.modes)], ["-modes", uniqueModes(map.modes)],
["-description", map.description], ["-description", map.description],
map.silent && ["-silent"]]) map.silent && ["-silent"]])
.filter(util.identity) .filter(util.identity)
.toObject(), .toObject(),
arguments: [map.names[0]], arguments: [map.names[0]],
@@ -553,7 +550,7 @@ var Mappings = Module("mappings", {
} }
for (map in userMappings(hive)) for (map in userMappings(hive))
if (map.persist) if (map.persist)
])) ])
.flatten().array; .flatten().array;
} }
}; };