From 067b8d2a6c4183c87f277d3dd98f50e01ca7ef00 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 19 Jan 2011 15:36:04 -0500 Subject: [PATCH] Cleanup horrible :map output. Update for map groups. --- common/content/commands.js | 6 +++- common/content/mappings.js | 58 +++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/common/content/commands.js b/common/content/commands.js index 749cdf36..0bd57a01 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -269,6 +269,7 @@ var Command = Class("Command", { { __iterator__: function () array.iterItems(this), command: this, + explicitOpts: Class.memoize(function () ({})), get literalArg() this.command.literal != null && this[this.command.literal] || "", // TODO: string: Class.memoize(function () { ... }), verify: function verify() { @@ -396,7 +397,8 @@ var ex = { let val = opt.type && opt.type.parse(v); dactyl.assert(val != null && (typeof val !== "number" || !isNaN(val)), "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)) res[i] = String(val); @@ -921,6 +923,8 @@ var Commands = Module("commands", { else Class.replaceProperty(args, opt.names[0], opt.type == CommandOption.NOARG || arg); + args.explicitOpts[opt.names[0]] = args[opt.names[0]]; + i += optname.length + count; if (i == str.length) break outer; diff --git a/common/content/mappings.js b/common/content/mappings.js index fce82cf7..e72b2651 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -276,6 +276,8 @@ var Mappings = Module("mappings", { 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) { map.definedAt = commands.getCaller(Components.stack.caller.caller); map.hive = hive; @@ -398,30 +400,40 @@ var Mappings = Module("mappings", { * @param {number[]} modes An array of modes to search. * @param {string} filter The filter string to match. */ - list: function (modes, filter) { + list: function (modes, filter, hives) { + hives = hives || mappings.userHives; + 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 - // :nmap respectively if the map is not exclusive. - 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) - maps = [map for (map in maps) if (map.names[0] == filter)]; + function maps(hive) { + let maps = hive.iterate(modes); + if (filter) + maps = [map for (map in maps) if (map.names[0] == filter)]; + return maps; + } let list = + + + + + { - template.map(maps, function (map) - template.map(map.names, function (name) - - - - - )) + template.map(hives, function (hive) let (i = 0) + + + template.map(maps(hive), function (map) + template.map(map.names, function (name) + + + + + + )) + + ) }
+ ModeCommandAction
{modeSign} {name}{map.noremap ? "*" : " "}{map.rhs || map.action.toSource()}
{!i++ ? hive.name : ""}{modeSign}{name}{map.rhs || map.action.toSource()}
; @@ -437,8 +449,10 @@ var Mappings = Module("mappings", { function addMapCommands(ch, mapmodes, modeDescription) { function map(args, noremap) { let mapmodes = array.uniq(args["-modes"].map(findMode)); + let hives = args.explicitOpts["-group"] ? [args["-group"]] : null; + if (!args.length) { - mappings.list(mapmodes); + mappings.list(mapmodes, null, hives); return; } @@ -447,7 +461,7 @@ var Mappings = Module("mappings", { args["-builtin"] = true; if (!rhs) // list the mapping - mappings.list(mapmodes, mappings.expandLeader(lhs)); + mappings.list(mapmodes, mappings.expandLeader(lhs), hives); else { mappings.addUserMap(mapmodes, [lhs], args["-description"], @@ -800,7 +814,7 @@ var Mappings = Module("mappings", { completion.mapGroup = function mapGroup(context, modes) { context.title = ["Map group"]; 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) { // FIXME: have we decided on a 'standard' way to handle this clash? --djk