completer: function (context) modules.completion.group(context)
});
+
+ memoize(modules, "userContext", function () contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules, true]));
+ memoize(modules, "_userContext", function () contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules.userContext]));
},
cleanup: function () {
util.trapErrors("destroy", hive);
for (let [name, plugin] in iter(this.modules.plugins.contexts))
- if (plugin && "onUnload" in plugin)
+ if (plugin && "onUnload" in plugin && callable(plugin.onUnload))
util.trapErrors("onUnload", plugin);
},
{ _hive: { value: name } })));
memoize(contexts.groupsProto, name,
- function () [group[name] for (group in values(this.groups)) if (set.has(group, name))]);
+ function () [group[name] for (group in values(this.groups)) if (Set.has(group, name))]);
},
get toStringParams() [this.name, this.Hive]
0);
let contextPath = file.path;
- let self = set.has(plugins, contextPath) && plugins.contexts[contextPath];
+ let self = Set.has(plugins, contextPath) && plugins.contexts[contextPath];
if (self) {
- if (set.has(self, "onUnload"))
+ if (Set.has(self, "onUnload"))
self.onUnload();
}
else {
let name = isPlugin ? file.getRelativeDescriptor(isPlugin).replace(File.PATH_SEP, "-")
: file.leafName;
- self = update(newContext.apply(null, args || [userContext]), {
+ self = args && !isArray(args) ? args : newContext.apply(null, args || [userContext]);
+ update(self, {
NAME: Const(name.replace(/\.[^.]*$/, "").replace(/-([a-z])/g, function (m, n1) n1.toUpperCase())),
PATH: Const(file.path),
contexts.removeGroup(this.GROUP);
})
});
- Class.replaceProperty(plugins, file.path, self);
+
+ if (group !== this.user)
+ Class.replaceProperty(plugins, file.path, self);
// This belongs elsewhere
- if (isPlugin && args)
+ if (isPlugin)
Object.defineProperty(plugins, self.NAME, {
configurable: true,
enumerable: true,
group = this.addGroup(commands.nameRegexp
.iterate(name.replace(/\.[^.]*$/, ""))
.join("-").replace(/--+/g, "-"),
- "Script group for " + file.path,
+ _("context.scriptGroup", file.path),
null, false);
Class.replaceProperty(self, "GROUP", group);
})),
matchingGroups: function (uri) Object.create(this.groupsProto, {
- groups: { value: this.activeGroups(uri) },
+ groups: { value: this.activeGroups(uri) }
}),
activeGroups: function (uri, doc) {
initializedGroups: function (hive)
let (need = hive ? [hive] : Object.keys(this.hives))
- this.groupList.filter(function (group) need.some(set.has(group))),
+ this.groupList.filter(function (group) need.some(Set.has(group))),
addGroup: function addGroup(name, description, filter, persist, replace) {
let group = this.getGroup(name);
if (description)
group.description = description;
if (filter)
- group.filter = filter
+ group.filter = filter;
group.persist = persist;
}
getGroup: function getGroup(name, hive) {
if (name === "default")
var group = this.context && this.context.context && this.context.context.GROUP;
- else if (set.has(this.groupMap, name))
+ else if (Set.has(this.groupMap, name))
group = this.groupMap[name];
if (group && hive)
return group;
},
+ getDocs: function getDocs(context) {
+ try {
+ if (isinstance(context, ["Sandbox"])) {
+ let info = "INFO" in context && Cu.evalInSandbox("this.INFO instanceof XML && INFO.toXMLString()", context);
+ return info && XML(info);
+ }
+ if (typeof context.INFO == "xml")
+ return context.INFO;
+ }
+ catch (e) {}
+ return null;
+ },
+
bindMacro: function (args, default_, params) {
const { dactyl, events, modules } = this.modules;
+ function Proxy(obj, key) Class.Property({
+ configurable: true,
+ enumerable: true,
+ get: function Proxy_get() process(obj[key]),
+ set: function Proxy_set(val) obj[key] = val
+ })
+
let process = util.identity;
if (callable(params))
var makeParams = function makeParams(self, args)
- iter.toObject([k, process(v)]
- for ([k, v] in iter(params.apply(self, args))));
+ let (obj = params.apply(self, args))
+ iter.toObject([k, Proxy(obj, k)] for (k in properties(obj)));
else if (params)
makeParams = function makeParams(self, args)
iter.toObject([name, process(args[i])]
let rhs = args.literalArg;
let type = ["-builtin", "-ex", "-javascript", "-keys"].reduce(function (a, b) args[b] ? b : a, default_);
+
switch (type) {
case "-builtin":
let noremap = true;
var action = function action() {
events.feedkeys(action.macro(makeParams(this, arguments)),
noremap, silent);
- }
+ };
action.macro = util.compileMacro(rhs, true);
break;
+
case "-ex":
action = function action() modules.commands
.execute(action.macro, makeParams(this, arguments),
action.macro = util.compileMacro(rhs, true);
action.context = this.context && update({}, this.context);
break;
+
case "-javascript":
if (callable(params))
action = dactyl.userEval("(function action() { with (action.makeParams(this, arguments)) {" + args.literalArg + "} })");
action.makeParams = makeParams;
break;
}
+
action.toString = function toString() (type === default_ ? "" : type + " ") + rhs;
args = null;
return action;
if (args.has("-locations"))
group.filter = filter;
if (args.has("-description"))
- group.description = args["-description"]
+ group.description = args["-description"];
if (args.has("-nopersist"))
- group.persist = !args["-nopersist"]
+ group.persist = !args["-nopersist"];
}
if (!group.builtin && args.has("-args")) {
util.assert(!group.builtin ||
!["-description", "-locations", "-nopersist"]
- .some(set.has(args.explicitOpts)),
+ .some(Set.has(args.explicitOpts)),
_("group.cantModifyBuiltin"));
},
{
commands.add(["delg[roup]"],
"Delete a group",
function (args) {
- util.assert(contexts.getGroup(args[0]), _("group.noSuch", args[0]));
- contexts.removeGroup(args[0]);
+ util.assert(args.bang ^ !!args[0], _("error.argumentOrBang"));
+
+ if (args.bang)
+ contexts.groupList = contexts.groupList.filter(function (g) g.builtin);
+ else {
+ util.assert(contexts.getGroup(args[0]), _("group.noSuch", args[0]));
+ contexts.removeGroup(args[0]);
+ }
},
{
- argCount: "1",
+ argCount: "?",
+ bang: true,
completer: function (context, args) {
- modules.completion.group(context);
+ if (args.bang)
+ return;
context.filters.push(function ({ item }) !item.builtin);
+ modules.completion.group(context);
}
});