// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2012 Kris Maglione <maglione.k at Gmail>
+// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
name: Class.Memoize(function () this.names[0]),
/** @property {[string]} All of this mapping's names (key sequences). */
- names: Class.Memoize(function () this._keys.map(function (k) DOM.Event.canonicalKeys(k))),
+ names: Class.Memoize(function () this._keys.map(k => DOM.Event.canonicalKeys(k))),
- get toStringParams() [this.modes.map(function (m) m.name), this.names.map(String.quote)],
+ get toStringParams() [this.modes.map(m => m.name),
+ this.names.map(String.quote)],
get identifier() [this.modes[0].name, this.hive.prefix + this.names[0]].join("."),
execute: function (args) {
if (!isObject(args)) // Backwards compatibility :(
args = iter(["motion", "count", "arg", "command"])
- .map(function ([i, prop]) [prop, this[i]], arguments)
+ .map(([i, prop]) => [prop, this[i]], arguments)
.toObject();
args = this.hive.makeArgs(this.hive.group.lastDocument,
*/
iterate: function (modes) {
let stacks = Array.concat(modes).map(this.closure.getStack);
- return values(stacks.shift().sort(function (m1, m2) String.localeCompare(m1.name, m2.name))
- .filter(function (map) map.rhs &&
- stacks.every(function (stack) stack.some(function (m) m.rhs && m.rhs === map.rhs && m.name === map.name))));
+ return values(stacks.shift().sort((m1, m2) => String.localeCompare(m1.name, m2.name))
+ .filter((map) => map.rhs &&
+ stacks.every(stack => stack.some(m => m.rhs && m.rhs === map.rhs && m.name === map.name))));
},
/**
* @param {Object} extra An optional extra configuration hash.
* @optional
*/
- add: function (modes, keys, description, action, extra) {
- extra = extra || {};
-
+ add: function (modes, keys, description, action, extra = {}) {
modes = Array.concat(modes);
if (!modes.every(util.identity))
throw TypeError(/*L*/"Invalid modes: " + modes);
map.names.splice(j, 1);
if (map.names.length == 0) // FIX ME.
for (let [mode, stack] in Iterator(this.stacks))
- this.stacks[mode] = MapHive.Stack(stack.filter(function (m) m != map));
+ this.stacks[mode] = MapHive.Stack(stack.filter(m => m != map));
return;
}
}
get allHives() contexts.allGroups.mappings,
- get userHives() this.allHives.filter(function (h) h !== this.builtin, this),
+ get userHives() this.allHives.filter(h => h !== this.builtin),
expandLeader: deprecated("your brain", function expandLeader(keyString) keyString),
prefixes: Class.Memoize(function () {
- let list = Array.map("CASM", function (s) s + "-");
+ let list = Array.map("CASM", s => s + "-");
- return iter(util.range(0, 1 << list.length)).map(function (mask)
- list.filter(function (p, i) mask & (1 << i)).join("")).toArray().concat("*-");
+ return iter(util.range(0, 1 << list.length)).map(mask =>
+ list.filter((p, i) => mask & (1 << i)).join(""))
+ .toArray()
+ .concat("*-");
}),
expand: function expand(keys) {
if (/^<\*-/.test(key))
return ["<", this.prefixes, key.slice(3)];
return key;
- }, this).flatten().array).map(function (k) DOM.Event.canonicalKeys(k));
+ }, this).flatten().array).map(k => DOM.Event.canonicalKeys(k));
if (keys != arguments[0])
return [arguments[0]].concat(keys);
* @param {string} cmd The map name to match.
* @returns {Map}
*/
- get: function get(mode, cmd) this.hives.map(function (h) h.get(mode, cmd)).compact()[0] || null,
+ get: function get(mode, cmd) this.hives.map(h => h.get(mode, cmd))
+ .compact()[0] || null,
/**
* Returns a count of maps with names starting with but not equal to
* @returns {[Map]}
*/
getCandidates: function (mode, prefix)
- this.hives.map(function (h) h.getCandidates(mode, prefix))
- .reduce(function (a, b) a + b, 0),
+ this.hives.map(h => h.getCandidates(mode, prefix))
+ .reduce((a, b) => (a + b), 0),
/**
* Lists all user-defined mappings matching *filter* for the specified
* @param {[MapHive]} hives The map hives to list. @optional
*/
list: function (modes, filter, hives) {
- let modeSign = modes.map(function (m) m.char || "").join("")
- + modes.map(function (m) !m.char ? " " + m.name : "").join("");
+ let modeSign = modes.map(m => m.char || "").join("")
+ + modes.map(m => !m.char ? " " + m.name : "").join("");
modeSign = modeSign.replace(/^ /, "");
- hives = (hives || mappings.userHives).map(function (h) [h, maps(h)])
- .filter(function ([h, m]) m.length);
+ hives = (hives || mappings.userHives).map(h => [h, maps(h)])
+ .filter(([h, m]) => m.length);
function maps(hive) {
let maps = iter.toArray(hive.iterate(modes));
if (filter)
- maps = maps.filter(function (m) m.names[0] === filter);
+ maps = maps.filter(m => m.names[0] === filter);
return maps;
}
["td", { style: "padding-right: 1em;" }, _("title.Command")],
["td", { style: "padding-right: 1em;" }, _("title.Action")]],
["col", { style: "min-width: 6em; padding-right: 1em;" }],
- hives.map(function ([hive, maps]) let (i = 0) [
+ hives.map(([hive, maps]) => let (i = 0) [
["tr", { style: "height: .5ex;" }],
- maps.map(function (map)
- map.names.map(function (name)
+ maps.map(map =>
+ map.names.map(name =>
["tr", {},
["td", { highlight: "Title" }, !i++ ? hive.name : ""],
["td", {}, modeSign],
if (args[1] && !/^<nop>$/i.test(args[1])
&& !args["-count"] && !args["-ex"] && !args["-javascript"]
- && mapmodes.every(function (m) m.count))
+ && mapmodes.every(m => m.count))
args[1] = "<count>" + args[1];
let [lhs, rhs] = args;
args["-group"].add(mapmodes, [lhs],
args["-description"],
- contexts.bindMacro(args, "-keys", function (params) params),
+ contexts.bindMacro(args, "-keys", params => params),
{
arg: args["-arg"],
count: args["-count"] || !(args["-ex"] || args["-javascript"]),
serialize: function () {
return this.name != "map" ? [] :
array(mappings.userHives)
- .filter(function (h) h.persist)
- .map(function (hive) [
+ .filter(h => h.persist)
+ .map(hive => [
{
command: "map",
options: {
}
function uniqueModes(modes) {
let chars = [k for ([k, v] in Iterator(modules.modes.modeChars))
- if (v.every(function (mode) modes.indexOf(mode) >= 0))];
- return array.uniq(modes.filter(function (m) chars.indexOf(m.char) < 0)
- .map(function (m) m.name.toLowerCase())
+ if (v.every(mode => modes.indexOf(mode) >= 0))];
+ return array.uniq(modes.filter(m => chars.indexOf(m.char) < 0)
+ .map(m => m.name.toLowerCase())
.concat(chars));
}
: [],
template.linkifyHelp(map.description + (map.rhs ? ": " + map.rhs : ""))
],
- help: function (map) let (char = array.compact(map.modes.map(function (m) m.char))[0])
+ help: function (map) let (char = array.compact(map.modes.map(m => m.char))[0])
char === "n" ? map.name : char ? char + "_" + map.name : "",
headings: ["Command", "Mode", "Group", "Description"]
}
});
},
completion: function initCompletion(dactyl, modules, window) {
- completion.userMapping = function userMapping(context, modes_, hive) {
- hive = hive || mappings.user;
- modes_ = modes_ || [modes.NORMAL];
- context.keys = { text: function (m) m.names[0], description: function (m) m.description + ": " + m.action };
+ 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.completions = hive.iterate(modes_);
};
},
JavaScript.setCompleter([Mappings.prototype.get, MapHive.prototype.get],
[
null,
- function (context, obj, args) [[m.names, m.description] for (m in this.iterate(args[0]))]
+ function (context, obj, args) [[m.names, m.description]
+ for (m in this.iterate(args[0]))]
]);
},
mappings: function initMappings(dactyl, modules, window) {