1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-21 07:05:46 +01:00

add initial (very rough) implementations of :map, :mapclear and :unmap

This commit is contained in:
Doug Kearns
2007-07-21 16:42:38 +00:00
parent 039544a697
commit 38fd04be35
2 changed files with 319 additions and 66 deletions

View File

@@ -187,6 +187,7 @@ function Commands() //{{{
if (ex_commands[i].hasName(name))
return ex_commands[i];
}
return null;
}
@@ -505,6 +506,73 @@ function Commands() //{{{
"The special version <code class=\"command\">:javascript!</code> will open the javascript console of Firefox."
}
));
addDefaultCommand(new Command(["map"],
// 0 args -> list all maps
// 1 arg -> list the maps starting with args
// 2 args -> map arg1 to arg*
function(args)
{
if (args.length == 0)
{
vimperator.mappings.list(vimperator.modes.NORMAL);
return;
}
var matches = args.match(/^([^ ]+)(?:\s+(.+))?$/);
var [lhs, rhs] = [matches[1], matches[2]];
if (rhs)
{
if (/^:/.test(rhs))
{
vimperator.mappings.add(
new Map(vimperator.modes.NORMAL, [lhs], function() { execute(rhs); }, { rhs: rhs })
);
}
else
{
var map = vimperator.mappings.get(vimperator.modes.NORMAL, rhs);
// create a new Map for {lhs} with the same action as
// {rhs}...until we have feedkeys().
// NOTE: Currently only really useful for static use ie. from
// the RC file
if (map)
vimperator.mappings.add(
new Map(vimperator.modes.NORMAL, [lhs], map.action, { rhs: rhs })
);
else
vimperator.echoerr("E475: Invalid argument: " + "{rhs} must be a existing singular mapping");
}
}
else
{
// FIXME: no filtering for now
vimperator.mappings.list(vimperator.modes.NORMAL, lhs);
}
},
{
usage: ["map {lhs} {rhs}", "map {lhs}", "map"],
short_help: "Map the key sequence {lhs} to {rhs}",
help: ""
}
));
addDefaultCommand(new Command(["mapc[lear]"],
function(args)
{
if (args.length > 0)
{
vimperator.echoerr("E474: Invalid argument");
return;
}
vimperator.mappings.removeAll(vimperator.modes.NORMAL);
},
{
short_help: "Remove all mappings",
help: ""
}
));
addDefaultCommand(new Command(["ma[rk]"],
function(args)
{
@@ -891,6 +959,28 @@ function Commands() //{{{
help: "TODO."
}
));
addDefaultCommand(new Command(["unm[ap]"],
function(args)
{
if (args.length == 0)
{
vimperator.echoerr("E474: Invalid argument");
return;
}
var lhs = args;
if (vimperator.mappings.hasMap(vimperator.modes.NORMAL, lhs))
vimperator.mappings.remove(vimperator.modes.NORMAL, lhs);
else
vimperator.echoerr("E31: No such mapping");
},
{
usage: ["unm[ap] {lhs}"],
short_help: "Remove the mapping of {lhs}",
help: ""
}
));
addDefaultCommand(new Command(["ve[rsion]"],
function(args, special)
{