mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 21:47:59 +01:00
add initial (very rough) implementation of :noremap
This commit is contained in:
@@ -556,7 +556,7 @@ function Commands() //{{{
|
||||
{
|
||||
usage: ["map {lhs} {rhs}", "map {lhs}", "map"],
|
||||
short_help: "Map the key sequence {lhs} to {rhs}",
|
||||
help: ""
|
||||
help: "The {rhs} is remapped, allowing for nested and recursive mappings."
|
||||
}
|
||||
));
|
||||
addDefaultCommand(new Command(["mapc[lear]"],
|
||||
@@ -616,6 +616,60 @@ function Commands() //{{{
|
||||
help: "Not implemented yet."
|
||||
}
|
||||
));
|
||||
// TODO: remove duplication in :map
|
||||
addDefaultCommand(new Command(["noremap"],
|
||||
// 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
|
||||
{
|
||||
// NOTE: we currently only allow one normal mode command in {rhs}
|
||||
var map = vimperator.mappings.getDefaultMap(vimperator.modes.NORMAL, rhs);
|
||||
|
||||
// create a new Map for {lhs} with the same action as
|
||||
// {rhs}...until we have feedkeys().
|
||||
// NOTE: Currently only really intended for static use (e.g.
|
||||
// from the RC file) since {rhs} is evaluated when the map
|
||||
// is created not at runtime
|
||||
if (map)
|
||||
vimperator.mappings.add(
|
||||
new Map(vimperator.modes.NORMAL, [lhs], map.action, { flags: map.flags, 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: ["noremap {lhs} {rhs}", "noremap {lhs}", "noremap"],
|
||||
short_help: "Map the key sequence {lhs} to {rhs}",
|
||||
help: "No remapping of the {rhs} is performed."
|
||||
}
|
||||
));
|
||||
addDefaultCommand(new Command(["o[pen]", "e[dit]"],
|
||||
function(args, special)
|
||||
{
|
||||
|
||||
@@ -238,6 +238,12 @@ function Mappings() //{{{
|
||||
return map;
|
||||
}
|
||||
|
||||
// TODO: move default maps to their own v.normal namespace
|
||||
this.getDefaultMap = function(mode, cmd)
|
||||
{
|
||||
return getMap(mode, cmd, main);
|
||||
}
|
||||
|
||||
// returns an array of mappings with names which start with "cmd"
|
||||
this.getCandidates = function(mode, cmd)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user