1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-05 06:24:12 +01:00

Replace expression closures (methods).

Expression closures are to be axed. See https://bugzil.la/1083458.
This commit is contained in:
Doug Kearns
2015-07-23 01:55:32 +10:00
parent c035aa936b
commit 77d59cdfd1
45 changed files with 1595 additions and 1045 deletions

View File

@@ -112,7 +112,9 @@ var Map = Class("Map", {
* @param {string} name The name to query.
* @returns {boolean}
*/
hasName: function (name) this.keys.indexOf(name) >= 0,
hasName: function (name) {
return this.keys.indexOf(name) >= 0;
},
get keys() { return Ary.flatten(this.names.map(mappings.bound.expand)); },
@@ -232,7 +234,9 @@ var MapHive = Class("MapHive", Contexts.Hive, {
* @param {string} cmd The map name to match.
* @returns {Map|null}
*/
get: function (mode, cmd) this.getStack(mode).mappings[cmd],
get: function (mode, cmd) {
return this.getStack(mode).mappings[cmd];
},
/**
* Returns a count of maps with names starting with but not equal to
@@ -242,7 +246,9 @@ var MapHive = Class("MapHive", Contexts.Hive, {
* @param {string} prefix The map prefix string to match.
* @returns {number)
*/
getCandidates: function (mode, prefix) this.getStack(mode).candidates[prefix] || 0,
getCandidates: function (mode, prefix) {
return this.getStack(mode).candidates[prefix] || 0;
},
/**
* Returns whether there is a user-defined mapping *cmd* for the specified
@@ -252,7 +258,9 @@ var MapHive = Class("MapHive", Contexts.Hive, {
* @param {string} cmd The candidate key mapping.
* @returns {boolean}
*/
has: function (mode, cmd) this.getStack(mode).mappings[cmd] != null,
has: function (mode, cmd) {
return this.getStack(mode).mappings[cmd] != null;
},
/**
* Remove the mapping named *cmd* for *mode*.
@@ -291,7 +299,9 @@ var MapHive = Class("MapHive", Contexts.Hive, {
return self;
},
"@@iterator": function () Ary.iterValues(this),
"@@iterator": function () {
return Ary.iterValues(this);
},
get candidates() { return this.states.candidates; },
get mappings() { return this.states.mappings; },
@@ -401,7 +411,9 @@ var Mappings = Module("mappings", {
// NOTE: just normal mode for now
/** @property {Iterator(Map)} */
"@@iterator": function () this.iterate(modes.NORMAL),
"@@iterator": function () {
return this.iterate(modes.NORMAL);
},
getDefault: deprecated("mappings.builtin.get", function getDefault(mode, cmd) this.builtin.get(mode, cmd)),
getUserIterator: deprecated("mappings.user.iterator", function getUserIterator(modes) this.user.iterator(modes)),
@@ -455,8 +467,9 @@ var Mappings = Module("mappings", {
* @param {string} cmd The map name to match.
* @returns {Map}
*/
get: function get(mode, cmd) this.hives.map(h => h.get(mode, cmd))
.compact()[0] || null,
get: function get(mode, cmd) {
return this.hives.map(h => h.get(mode, cmd)).compact()[0] || null;
},
/**
* Returns a count of maps with names starting with but not equal to
@@ -466,9 +479,10 @@ var Mappings = Module("mappings", {
* @param {string} prefix The map prefix string to match.
* @returns {[Map]}
*/
getCandidates: function (mode, prefix)
this.hives.map(h => h.getCandidates(mode, prefix))
.reduce((a, b) => (a + b), 0),
getCandidates: function (mode, prefix) {
return this.hives.map(h => h.getCandidates(mode, prefix))
.reduce((a, b) => (a + b), 0);
},
/**
* Lists all user-defined mappings matching *filter* for the specified
@@ -763,7 +777,7 @@ var Mappings = Module("mappings", {
mode.displayName);
let args = {
getMode: function (args) findMode(args["-mode"]),
getMode: function (args) { return findMode(args["-mode"]); },
iterate: function* (args, mainOnly) {
let modes = [this.getMode(args)];
if (!mainOnly)
@@ -788,13 +802,15 @@ var Mappings = Module("mappings", {
};
},
format: {
description: function (map) [
description: function (map) {
return [
options.get("passkeys").has(map.name)
? ["span", { highlight: "URLExtra" },
"(", template.linkifyHelp(_("option.passkeys.passedBy")), ")"]
: [],
template.linkifyHelp(map.description + (map.rhs ? ": " + map.rhs : ""))
],
];
},
help: function (map) {
let char = Ary.compact(map.modes.map(m => m.char))[0];
return char === "n" ? map.name : char ? char + "_" + map.name : "";
@@ -831,15 +847,21 @@ var Mappings = Module("mappings", {
},
description: "List all " + mode.displayName + " mode mappings along with their short descriptions",
index: mode.char + "-map",
getMode: function (args) mode,
getMode: function (args) { return mode; },
options: []
});
});
},
completion: function initCompletion(dactyl, modules, window) {
completion.userMapping = function userMapping(context, modes_=[modes.NORMAL], hive=mappings.user) {
context.keys = { text: function (m) m.names[0],
description: function (m) m.description + ": " + m.action };
context.keys = {
text: function (m) {
return m.names[0];
},
description: function (m) {
return m.description + ": " + m.action;
}
};
context.completions = hive.iterate(modes_);
};
},
@@ -847,8 +869,10 @@ var Mappings = Module("mappings", {
JavaScript.setCompleter([Mappings.prototype.get, MapHive.prototype.get],
[
null,
function (context, obj, args) [[m.names, m.description]
for (m of this.iterate(args[0]))]
function (context, obj, args) {
return [[m.names, m.description]
for (m of this.iterate(args[0]))];
}
]);
},
mappings: function initMappings(dactyl, modules, window) {