1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-05 09:05:48 +01:00

@@ and some checks added to macro/recording...

This commit is contained in:
Marco Candrian
2007-12-16 05:01:26 +00:00
parent cbaca2dc3e
commit 6d9d3ace05
2 changed files with 48 additions and 11 deletions

View File

@@ -251,6 +251,7 @@ vimperator.Events = function () //{{{
var macros = {}; var macros = {};
var isRecording = false; var isRecording = false;
var currentMacro; var currentMacro;
var playReg = "";
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION ////////////////////////////////////////// ////////////////////// PUBLIC SECTION //////////////////////////////////////////
@@ -262,19 +263,53 @@ vimperator.Events = function () //{{{
startRecording: function (reg) startRecording: function (reg)
{ {
isRecording = true; if (!/[a-zA-Z0-9]/.test(reg))
vimperator.modes.add(vimperator.modes.RECORDING); {
currentMacro = reg; vimperator.echoerr("Register must be [a-zA-z0-9]");
macros[currentMacro] = ""; 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 + "..."); vimperator.echo("recording into register " + currentMacro + "...");
isRecording = true;
}, },
playMacro: function (reg) playRegister: function (reg)
{ {
if (macros[reg]) if (!/[a-zA-Z0-9]/.test(reg))
vimperator.events.feedkeys(macros[reg], true); // true -> noremap {
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 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 () destroy: function ()

View File

@@ -1294,14 +1294,16 @@ vimperator.Mappings = function () //{{{
function (arg) { vimperator.events.startRecording(arg); }, function (arg) { vimperator.events.startRecording(arg); },
{ {
shortHelp: "record a macro into a register", 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 flags: vimperator.Mappings.flags.ARGUMENT
} }
)); ));
addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["@"], 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 flags: vimperator.Mappings.flags.ARGUMENT
} }
)); ));