mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-29 00:05:45 +01:00
@@ and some checks added to macro/recording...
This commit is contained in:
@@ -251,6 +251,7 @@ vimperator.Events = function () //{{{
|
||||
var macros = {};
|
||||
var isRecording = false;
|
||||
var currentMacro;
|
||||
var playReg = "";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////}}}
|
||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||
@@ -262,19 +263,53 @@ vimperator.Events = function () //{{{
|
||||
|
||||
startRecording: function (reg)
|
||||
{
|
||||
isRecording = true;
|
||||
vimperator.modes.add(vimperator.modes.RECORDING);
|
||||
currentMacro = reg;
|
||||
macros[currentMacro] = "";
|
||||
if (!/[a-zA-Z0-9]/.test(reg))
|
||||
{
|
||||
vimperator.echoerr("Register must be [a-zA-z0-9]");
|
||||
return false;
|
||||
}
|
||||
vimperator.modes.add(vimperator.modes.RECORDING); //TODO: does not work/show yet
|
||||
|
||||
if (/[A-Z]/.test(reg)) // uppercase (append)
|
||||
{
|
||||
currentMacro = reg.toLowerCase();
|
||||
if (!macros[currentMacro])
|
||||
macros[currentMacro] = ""; // initialise if it does not yet exist
|
||||
}
|
||||
else
|
||||
{
|
||||
currentMacro = reg;
|
||||
macros[currentMacro] = "";
|
||||
}
|
||||
|
||||
vimperator.echo("recording into register " + currentMacro + "...");
|
||||
isRecording = true;
|
||||
},
|
||||
|
||||
playMacro: function (reg)
|
||||
playRegister: function (reg)
|
||||
{
|
||||
if (macros[reg])
|
||||
vimperator.events.feedkeys(macros[reg], true); // true -> noremap
|
||||
if (!/[a-zA-Z0-9]/.test(reg))
|
||||
{
|
||||
vimperator.echoerr("Register must be [a-z0-9]");
|
||||
return false;
|
||||
}
|
||||
if (reg == "@") // use playReg if it's set
|
||||
{
|
||||
if (!playReg)
|
||||
{
|
||||
vimperator.echoerr("E748: No previously used Register");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
vimperator.echoerr("Register '" + reg + " not set");
|
||||
{
|
||||
playReg = reg.toLowerCase(); // XXX: sets last playerd reg, even if it does not yet exist
|
||||
}
|
||||
|
||||
if (macros[playReg])
|
||||
vimperator.events.feedkeys(macros[playReg], true); // true -> noremap
|
||||
else
|
||||
vimperator.echoerr("Register '" + playReg + " not set");
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
|
||||
@@ -1294,14 +1294,16 @@ vimperator.Mappings = function () //{{{
|
||||
function (arg) { vimperator.events.startRecording(arg); },
|
||||
{
|
||||
shortHelp: "record a macro into a register",
|
||||
help: "record a macro; [a-zA-Z0-9] are valid registers",
|
||||
help: "Record typed characters into register {0-9a-zA-Z} (uppercase to append)." +
|
||||
"type 'q' to stop recording.",
|
||||
|
||||
flags: vimperator.Mappings.flags.ARGUMENT
|
||||
}
|
||||
));
|
||||
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["@"],
|
||||
function (arg) { vimperator.events.playMacro(arg); },
|
||||
function (arg) { vimperator.events.playRegister(arg); },
|
||||
{
|
||||
shortHelp: "play a macro",
|
||||
shortHelp: "Execute the contents of register {0-9a-z}. @@ repeats the previous @{0-9a-z}",
|
||||
flags: vimperator.Mappings.flags.ARGUMENT
|
||||
}
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user