1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 02:57:59 +01:00

Cleanup horrible :map output. Update for map groups.

This commit is contained in:
Kris Maglione
2011-01-19 15:36:04 -05:00
parent 807c7a4aba
commit 067b8d2a6c
2 changed files with 41 additions and 23 deletions

View File

@@ -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;

View File

@@ -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) { if (filter)
for (let m in modules.modes.mainModes) maps = [map for (map in maps) if (map.names[0] == filter)];
if (mode == m.mask && modeSign.indexOf(m.char) == -1) return maps;
modeSign += m.char; }
});
let maps = this.userHive.iterate(modes);
if (filter)
maps = [map for (map in maps) if (map.names[0] == filter)];
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)
template.map(map.names, function (name) <tr style="height: .5ex;"/> +
<tr> template.map(maps(hive), function (map)
<td>{modeSign} {name}</td> template.map(map.names, function (name)
<td>{map.noremap ? "*" : " "}</td> <tr>
<td>{map.rhs || map.action.toSource()}</td> <td highlight="Title" style="padding-right: 1em">{!i++ ? hive.name : ""}</td>
</tr>)) <td>{modeSign}</td>
<td>{name}</td>
<td>{map.rhs || map.action.toSource()}</td>
</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