mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 21:28:00 +01:00
Cleanup horrible :map output. Update for map groups.
This commit is contained in:
@@ -269,6 +269,7 @@ var Command = Class("Command", {
|
|||||||
{
|
{
|
||||||
__iterator__: function () array.iterItems(this),
|
__iterator__: function () array.iterItems(this),
|
||||||
command: this,
|
command: this,
|
||||||
|
explicitOpts: Class.memoize(function () ({})),
|
||||||
get literalArg() this.command.literal != null && this[this.command.literal] || "",
|
get literalArg() this.command.literal != null && this[this.command.literal] || "",
|
||||||
// TODO: string: Class.memoize(function () { ... }),
|
// TODO: string: Class.memoize(function () { ... }),
|
||||||
verify: function verify() {
|
verify: function verify() {
|
||||||
@@ -396,7 +397,8 @@ var ex = {
|
|||||||
let val = opt.type && opt.type.parse(v);
|
let val = opt.type && opt.type.parse(v);
|
||||||
dactyl.assert(val != null && (typeof val !== "number" || !isNaN(val)),
|
dactyl.assert(val != null && (typeof val !== "number" || !isNaN(val)),
|
||||||
"No such option: " + k);
|
"No such option: " + k);
|
||||||
res[opt.names[0]] = val;
|
Class.replaceProperty(args, opt.names[0], val);
|
||||||
|
args.explicitOpts[opt.names[0]] = val;
|
||||||
}
|
}
|
||||||
for (let [i, val] in array.iterItems(args))
|
for (let [i, val] in array.iterItems(args))
|
||||||
res[i] = String(val);
|
res[i] = String(val);
|
||||||
@@ -921,6 +923,8 @@ var Commands = Module("commands", {
|
|||||||
else
|
else
|
||||||
Class.replaceProperty(args, opt.names[0], opt.type == CommandOption.NOARG || arg);
|
Class.replaceProperty(args, opt.names[0], opt.type == CommandOption.NOARG || arg);
|
||||||
|
|
||||||
|
args.explicitOpts[opt.names[0]] = args[opt.names[0]];
|
||||||
|
|
||||||
i += optname.length + count;
|
i += optname.length + count;
|
||||||
if (i == str.length)
|
if (i == str.length)
|
||||||
break outer;
|
break outer;
|
||||||
|
|||||||
@@ -276,6 +276,8 @@ var Mappings = Module("mappings", {
|
|||||||
|
|
||||||
hives: Class.memoize(function () array(this.allHives.filter(function (h) h.filter(buffer.uri)))),
|
hives: Class.memoize(function () array(this.allHives.filter(function (h) h.filter(buffer.uri)))),
|
||||||
|
|
||||||
|
get userHives() this.allHives.filter(function (h) h !== this.builtinHive, this),
|
||||||
|
|
||||||
_addMap: function (map, hive) {
|
_addMap: function (map, hive) {
|
||||||
map.definedAt = commands.getCaller(Components.stack.caller.caller);
|
map.definedAt = commands.getCaller(Components.stack.caller.caller);
|
||||||
map.hive = hive;
|
map.hive = hive;
|
||||||
@@ -398,30 +400,40 @@ var Mappings = Module("mappings", {
|
|||||||
* @param {number[]} modes An array of modes to search.
|
* @param {number[]} modes An array of modes to search.
|
||||||
* @param {string} filter The filter string to match.
|
* @param {string} filter The filter string to match.
|
||||||
*/
|
*/
|
||||||
list: function (modes, filter) {
|
list: function (modes, filter, hives) {
|
||||||
|
hives = hives || mappings.userHives;
|
||||||
|
|
||||||
let modeSign = "";
|
let modeSign = "";
|
||||||
|
modes.filter(function (m) m.char).forEach(function (m) { modeSign += m.char; });
|
||||||
|
modes.filter(function (m) !m.char).forEach(function (m) { modeSign += " " + m.name; });
|
||||||
|
modeSign = modeSign.replace(/^ /, "");
|
||||||
|
|
||||||
// TODO: Vim hides "nv" in a :map and "v" and "n" in :vmap and
|
function maps(hive) {
|
||||||
// :nmap respectively if the map is not exclusive.
|
let maps = hive.iterate(modes);
|
||||||
modes.forEach(function (mode) {
|
|
||||||
for (let m in modules.modes.mainModes)
|
|
||||||
if (mode == m.mask && modeSign.indexOf(m.char) == -1)
|
|
||||||
modeSign += m.char;
|
|
||||||
});
|
|
||||||
|
|
||||||
let maps = this.userHive.iterate(modes);
|
|
||||||
if (filter)
|
if (filter)
|
||||||
maps = [map for (map in maps) if (map.names[0] == filter)];
|
maps = [map for (map in maps) if (map.names[0] == filter)];
|
||||||
|
return maps;
|
||||||
|
}
|
||||||
|
|
||||||
let list = <table>
|
let list = <table>
|
||||||
|
<tr highlight="Title">
|
||||||
|
<td/>
|
||||||
|
<td style="padding-right: 1em;">Mode</td>
|
||||||
|
<td style="padding-right: 1em;">Command</td>
|
||||||
|
<td style="padding-right: 1em;">Action</td>
|
||||||
|
</tr>
|
||||||
{
|
{
|
||||||
template.map(maps, function (map)
|
template.map(hives, function (hive) let (i = 0)
|
||||||
|
<tr style="height: .5ex;"/> +
|
||||||
|
template.map(maps(hive), function (map)
|
||||||
template.map(map.names, function (name)
|
template.map(map.names, function (name)
|
||||||
<tr>
|
<tr>
|
||||||
<td>{modeSign} {name}</td>
|
<td highlight="Title" style="padding-right: 1em">{!i++ ? hive.name : ""}</td>
|
||||||
<td>{map.noremap ? "*" : " "}</td>
|
<td>{modeSign}</td>
|
||||||
|
<td>{name}</td>
|
||||||
<td>{map.rhs || map.action.toSource()}</td>
|
<td>{map.rhs || map.action.toSource()}</td>
|
||||||
</tr>))
|
</tr>)) +
|
||||||
|
<tr style="height: .5ex;"/>)
|
||||||
}
|
}
|
||||||
</table>;
|
</table>;
|
||||||
|
|
||||||
@@ -437,8 +449,10 @@ var Mappings = Module("mappings", {
|
|||||||
function addMapCommands(ch, mapmodes, modeDescription) {
|
function addMapCommands(ch, mapmodes, modeDescription) {
|
||||||
function map(args, noremap) {
|
function map(args, noremap) {
|
||||||
let mapmodes = array.uniq(args["-modes"].map(findMode));
|
let mapmodes = array.uniq(args["-modes"].map(findMode));
|
||||||
|
let hives = args.explicitOpts["-group"] ? [args["-group"]] : null;
|
||||||
|
|
||||||
if (!args.length) {
|
if (!args.length) {
|
||||||
mappings.list(mapmodes);
|
mappings.list(mapmodes, null, hives);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,7 +461,7 @@ var Mappings = Module("mappings", {
|
|||||||
args["-builtin"] = true;
|
args["-builtin"] = true;
|
||||||
|
|
||||||
if (!rhs) // list the mapping
|
if (!rhs) // list the mapping
|
||||||
mappings.list(mapmodes, mappings.expandLeader(lhs));
|
mappings.list(mapmodes, mappings.expandLeader(lhs), hives);
|
||||||
else {
|
else {
|
||||||
mappings.addUserMap(mapmodes, [lhs],
|
mappings.addUserMap(mapmodes, [lhs],
|
||||||
args["-description"],
|
args["-description"],
|
||||||
@@ -800,7 +814,7 @@ var Mappings = Module("mappings", {
|
|||||||
completion.mapGroup = function mapGroup(context, modes) {
|
completion.mapGroup = function mapGroup(context, modes) {
|
||||||
context.title = ["Map group"];
|
context.title = ["Map group"];
|
||||||
context.keys = { text: "name", description: function (h) h.description || h.filter };
|
context.keys = { text: "name", description: function (h) h.description || h.filter };
|
||||||
context.completions = mappings.allHives.filter(function (h) h.name != "builtin");
|
context.completions = mappings.userHives;
|
||||||
};
|
};
|
||||||
completion.userMapping = function userMapping(context, modes) {
|
completion.userMapping = function userMapping(context, modes) {
|
||||||
// FIXME: have we decided on a 'standard' way to handle this clash? --djk
|
// FIXME: have we decided on a 'standard' way to handle this clash? --djk
|
||||||
|
|||||||
Reference in New Issue
Block a user