mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 16:47:58 +01:00
More groups work, including -args flag and proper serialization.
--HG-- branch : groups
This commit is contained in:
@@ -146,7 +146,11 @@ var AutoCommands = Module("autocommands", {
|
||||
let uri = args.url ? util.newURI(args.url) : buffer.uri;
|
||||
|
||||
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))
|
||||
if (autoCmd.eventName === event && autoCmd.filter(uri)) {
|
||||
if (!lastPattern || lastPattern !== String(autoCmd.filter))
|
||||
@@ -157,6 +161,7 @@ var AutoCommands = Module("autocommands", {
|
||||
|
||||
dactyl.trapErrors(autoCmd.command, autoCmd, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
}, {
|
||||
|
||||
@@ -154,9 +154,12 @@ var Command = Class("Command", {
|
||||
throw FailedAssertion("E477: No ! allowed");
|
||||
|
||||
return !dactyl.trapErrors(function exec(command) {
|
||||
// update({}, command.hive.group.argsExtra(args), args);
|
||||
|
||||
if (this.always)
|
||||
this.always(args, modifiers);
|
||||
if (!contexts.context || !contexts.context.noExecute)
|
||||
|
||||
if (!context || !context.noExecute)
|
||||
this.action(args, modifiers);
|
||||
}, this);
|
||||
},
|
||||
@@ -569,12 +572,13 @@ var Commands = Module("commands", {
|
||||
string = string(tokens || {});
|
||||
|
||||
let lines = string.split(/\r\n|[\r\n]/);
|
||||
let startLine = context.line;
|
||||
|
||||
for (var i = 0; i < lines.length && !context.finished; i++) {
|
||||
// Deal with editors from Silly OSs.
|
||||
let line = lines[i].replace(/\r$/, "");
|
||||
|
||||
context.line = context.line + i;
|
||||
context.line = startLine + i;
|
||||
|
||||
// Process escaped new lines
|
||||
while (i < lines.length && /^\s*\\/.test(lines[i + 1]))
|
||||
|
||||
@@ -9,7 +9,7 @@ var Group = Class("Group", {
|
||||
const self = this;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.filter = filter || function (uri) true;
|
||||
this.filter = filter || Group.defaultFilter;
|
||||
this.persist = persist || false;
|
||||
this.subGroups = [];
|
||||
},
|
||||
@@ -20,6 +20,8 @@ var Group = Class("Group", {
|
||||
subGroup.cleanup();
|
||||
},
|
||||
|
||||
argsExtra: function argsExtra() ({}),
|
||||
|
||||
get toStringParams() [this.name],
|
||||
|
||||
get builtin() contexts.builtinGroups.indexOf(this) >= 0,
|
||||
@@ -52,6 +54,8 @@ var Group = Class("Group", {
|
||||
|
||||
groupsProto: {},
|
||||
|
||||
defaultFilter: Class.memoize(function () this.compileFilter(["*"])),
|
||||
|
||||
subGroupMap: {},
|
||||
|
||||
SubGroup: Class("SubGroup", Class.Property, {
|
||||
@@ -91,7 +95,7 @@ var Contexts = Module("contexts", {
|
||||
this.groupMap = {};
|
||||
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.builtinGroups = [this.system, this.user];
|
||||
},
|
||||
@@ -295,7 +299,7 @@ var Contexts = Module("contexts", {
|
||||
let filter = Group.compileFilter(args["-locations"]);
|
||||
if (!group)
|
||||
group = contexts.addGroup(name, args["-description"], filter, !args["-nopersist"]);
|
||||
else {
|
||||
else if (!group.builtin) {
|
||||
if (args.has("-locations"))
|
||||
group.filter = filter;
|
||||
if (args.has("-description"))
|
||||
@@ -304,6 +308,12 @@ var Contexts = Module("contexts", {
|
||||
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)
|
||||
args.context.group = group;
|
||||
},
|
||||
@@ -316,6 +326,11 @@ var Contexts = Module("contexts", {
|
||||
},
|
||||
keepQuotes: true,
|
||||
options: [
|
||||
{
|
||||
names: ["-args", "-a"],
|
||||
description: "JavaScript Object which augments the arguments passed to commands, mappings, and autocommands",
|
||||
type: CommandOption.STRING
|
||||
},
|
||||
{
|
||||
names: ["-description", "-desc", "-d"],
|
||||
description: "A description of this group",
|
||||
@@ -332,7 +347,26 @@ var Contexts = Module("contexts", {
|
||||
names: ["-nopersist", "-n"],
|
||||
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]"],
|
||||
|
||||
@@ -107,8 +107,9 @@ var Map = Class("Map", {
|
||||
.map(function ([i, prop]) [prop, this[i]], arguments)
|
||||
.toObject();
|
||||
|
||||
if (!args.context)
|
||||
args.context = contexts.context;
|
||||
args = update({ context: contexts.context },
|
||||
this.hive.group.argsExtra(args),
|
||||
args);
|
||||
|
||||
let self = this;
|
||||
function repeat() self.action(args)
|
||||
@@ -531,20 +532,16 @@ var Mappings = Module("mappings", {
|
||||
serialize: function () {
|
||||
return this.name != "map" ? [] :
|
||||
array(mappings.userHives)
|
||||
.filter(function (h) !h.noPersist)
|
||||
.filter(function (h) h.group.persist)
|
||||
.map(function (hive) [
|
||||
{
|
||||
command: "mapgroup",
|
||||
bang: true,
|
||||
arguments: [hive.name, String(hive.filter)].slice(0, hive.name == "user" ? 1 : 2)
|
||||
}
|
||||
].concat([
|
||||
{
|
||||
command: "map",
|
||||
options: array([
|
||||
hive !== mappings.user && ["-group", hive.group.name],
|
||||
["-modes", uniqueModes(map.modes)],
|
||||
["-description", map.description],
|
||||
map.silent && ["-silent"]])
|
||||
|
||||
.filter(util.identity)
|
||||
.toObject(),
|
||||
arguments: [map.names[0]],
|
||||
@@ -553,7 +550,7 @@ var Mappings = Module("mappings", {
|
||||
}
|
||||
for (map in userMappings(hive))
|
||||
if (map.persist)
|
||||
]))
|
||||
])
|
||||
.flatten().array;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user