mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 06:17:58 +01:00
moved more commands. the end of all the moving is near!
This commit is contained in:
@@ -596,98 +596,6 @@ vimperator.Commands = function () //{{{
|
|||||||
|
|
||||||
// move to vim.js:
|
// move to vim.js:
|
||||||
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["let"],
|
|
||||||
function (args)
|
|
||||||
{
|
|
||||||
if (!args)
|
|
||||||
{
|
|
||||||
var str = "";
|
|
||||||
for (var i in vimperator.globalVariables)
|
|
||||||
{
|
|
||||||
var value = vimperator.globalVariables[i];
|
|
||||||
if (typeof value == "number")
|
|
||||||
var prefix = "#";
|
|
||||||
else if (typeof value == "function")
|
|
||||||
var prefix = "*";
|
|
||||||
else
|
|
||||||
var prefix = "";
|
|
||||||
|
|
||||||
str += "<tr><td style=\"width: 200px;\">" + i + "</td><td>" + prefix + value + "</td>\n";
|
|
||||||
}
|
|
||||||
if (str)
|
|
||||||
vimperator.echo("<table>" + str + "</table>", vimperator.commandline.FORCE_MULTILINE);
|
|
||||||
else
|
|
||||||
vimperator.echo("No variables found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var matches;
|
|
||||||
// 1 - type, 2 - name, 3 - +-., 4 - expr
|
|
||||||
if (matches = args.match(/([$@&])?([\w:]+)\s*([+-.])?=\s*(.+)/))
|
|
||||||
{
|
|
||||||
if (!matches[1])
|
|
||||||
{
|
|
||||||
var reference = vimperator.variableReference(matches[2]);
|
|
||||||
if (!reference[0] && matches[3])
|
|
||||||
{
|
|
||||||
vimperator.echoerr("E121: Undefined variable: " + matches[2]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var expr = vimperator.eval(matches[4]);
|
|
||||||
if (typeof expr === undefined)
|
|
||||||
{
|
|
||||||
vimperator.echoerr("E15: Invalid expression: " + matches[4]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!reference[0])
|
|
||||||
{
|
|
||||||
if (reference[2] == "g")
|
|
||||||
reference[0] = vimperator.globalVariables;
|
|
||||||
else
|
|
||||||
return; // for now
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matches[3])
|
|
||||||
{
|
|
||||||
if (matches[3] == "+")
|
|
||||||
reference[0][reference[1]] += expr;
|
|
||||||
else if (matches[3] == "-")
|
|
||||||
reference[0][reference[1]] -= expr;
|
|
||||||
else if (matches[3] == ".")
|
|
||||||
reference[0][reference[1]] += expr.toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
reference[0][reference[1]] = expr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 1 - name
|
|
||||||
else if (matches = args.match(/^\s*([\w:]+)\s*$/))
|
|
||||||
{
|
|
||||||
var reference = vimperator.variableReference(matches[1]);
|
|
||||||
if (!reference[0])
|
|
||||||
{
|
|
||||||
vimperator.echoerr("E121: Undefined variable: " + matches[1]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var value = reference[0][reference[1]];
|
|
||||||
if (typeof value == "number")
|
|
||||||
var prefix = "#";
|
|
||||||
else if (typeof value == "function")
|
|
||||||
var prefix = "*";
|
|
||||||
else
|
|
||||||
var prefix = "";
|
|
||||||
vimperator.echo(reference[1] + "\t\t" + prefix + value);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
shortHelp: "Sets or lists a variable"
|
|
||||||
}
|
|
||||||
));
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["q[uit]"],
|
commandManager.addUserCommand(new vimperator.Command(["q[uit]"],
|
||||||
function () { vimperator.tabs.remove(getBrowser().mCurrentTab, 1, false, 1); },
|
function () { vimperator.tabs.remove(getBrowser().mCurrentTab, 1, false, 1); },
|
||||||
{ shortHelp: "Quit current tab" }
|
{ shortHelp: "Quit current tab" }
|
||||||
@@ -697,158 +605,7 @@ vimperator.Commands = function () //{{{
|
|||||||
function () { vimperator.quit(false); },
|
function () { vimperator.quit(false); },
|
||||||
{ shortHelp: "Quit Vimperator", }
|
{ shortHelp: "Quit Vimperator", }
|
||||||
));
|
));
|
||||||
commandManager.addUserCommand(new vimperator.Command(["res[tart]"],
|
|
||||||
function () { vimperator.restart(); },
|
|
||||||
{ shortHelp: "Force the browser to restart" }
|
|
||||||
));
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["time"],
|
|
||||||
function (args, special, count)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (count > 1)
|
|
||||||
{
|
|
||||||
var i = count;
|
|
||||||
var beforeTime = Date.now();
|
|
||||||
|
|
||||||
if (args && args[0] == ":")
|
|
||||||
{
|
|
||||||
while (i--)
|
|
||||||
vimperator.execute(args);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (i--)
|
|
||||||
eval("with(vimperator){" + args + "}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (special)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var afterTime = Date.now();
|
|
||||||
|
|
||||||
if ((afterTime - beforeTime) / count >= 100)
|
|
||||||
{
|
|
||||||
var each = ((afterTime - beforeTime) / 1000.0 / count);
|
|
||||||
var eachUnits = "sec";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var each = ((afterTime - beforeTime) / count);
|
|
||||||
var eachUnits = "msec";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (afterTime - beforeTime >= 100)
|
|
||||||
{
|
|
||||||
var total = ((afterTime - beforeTime) / 1000.0);
|
|
||||||
var totalUnits = "sec";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var total = (afterTime - beforeTime);
|
|
||||||
var totalUnits = "msec";
|
|
||||||
}
|
|
||||||
|
|
||||||
var str = ":" + vimperator.util.escapeHTML(vimperator.commandline.getCommand()) + "<br/>" +
|
|
||||||
"<table>" +
|
|
||||||
"<tr align=\"left\" class=\"hl-Title\"><th colspan=\"3\">Code execution summary</th></tr>" +
|
|
||||||
"<tr><td> Executed:</td><td align=\"right\"><span style=\"color: green\">" + count + "</span></td><td>times</td></tr>" +
|
|
||||||
"<tr><td> Average time:</td><td align=\"right\"><span style=\"color: green\">" + each.toFixed(2) + "</span></td><td>" + eachUnits + "</td></tr>" +
|
|
||||||
"<tr><td> Total time:</td><td align=\"right\"><span style=\"color: red\">" + total.toFixed(2) + "</span></td><td>" + totalUnits + "</td></tr>" +
|
|
||||||
"</table>";
|
|
||||||
|
|
||||||
vimperator.commandline.echo(str, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var beforeTime = Date.now();
|
|
||||||
if (args && args[0] == ":")
|
|
||||||
vimperator.execute(args);
|
|
||||||
else
|
|
||||||
eval("with(vimperator){" + args + "}");
|
|
||||||
|
|
||||||
if (special)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var afterTime = Date.now();
|
|
||||||
|
|
||||||
if (afterTime - beforeTime >= 100)
|
|
||||||
vimperator.echo("Total time: " + ((afterTime - beforeTime) / 1000.0).toFixed(2) + " sec");
|
|
||||||
else
|
|
||||||
vimperator.echo("Total time: " + (afterTime - beforeTime) + " msec");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e)
|
|
||||||
{
|
|
||||||
vimperator.echoerr(e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
shortHelp: "Profile a piece of code or a command"
|
|
||||||
}
|
|
||||||
));
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["unl[et]"],
|
|
||||||
function (args, special)
|
|
||||||
{
|
|
||||||
if (!args)
|
|
||||||
{
|
|
||||||
vimperator.echoerr("E471: Argument required");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var names = args.split(/ /);
|
|
||||||
if (typeof names == "string") names = [names];
|
|
||||||
var length = names.length;
|
|
||||||
for (var i = 0, name = names[i]; i < length; name = names[++i])
|
|
||||||
{
|
|
||||||
var reference = vimperator.variableReference(name);
|
|
||||||
if (!reference[0])
|
|
||||||
{
|
|
||||||
if (!special)
|
|
||||||
vimperator.echoerr("E108: No such variable: " + name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete reference[0][reference[1]];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
shortHelp: "Deletes a variable."
|
|
||||||
}
|
|
||||||
));
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["ve[rsion]"],
|
|
||||||
function (args, special)
|
|
||||||
{
|
|
||||||
if (special)
|
|
||||||
vimperator.open("about:");
|
|
||||||
else
|
|
||||||
vimperator.echo(":" + vimperator.util.escapeHTML(vimperator.commandline.getCommand()) +
|
|
||||||
"\nVimperator " + vimperator.version + " running on:\n" + navigator.userAgent);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
shortHelp: "Show version information"
|
|
||||||
}
|
|
||||||
));
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["viu[sage]"],
|
|
||||||
function (args, special, count, modifiers)
|
|
||||||
{
|
|
||||||
var usage = "<table>";
|
|
||||||
for (let mapping in vimperator.mappings)
|
|
||||||
{
|
|
||||||
usage += "<tr><td style='color: magenta; padding-right: 20px'> " +
|
|
||||||
vimperator.util.escapeHTML(mapping.names[0]) + "</td><td>" +
|
|
||||||
vimperator.util.escapeHTML(mapping.shortHelp || "") + "</td></tr>";
|
|
||||||
}
|
|
||||||
usage += "</table>";
|
|
||||||
|
|
||||||
vimperator.echo(usage, vimperator.commandline.FORCE_MULTILINE);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
shortHelp: "Show help for normal mode commands"
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
// move to io.js:
|
|
||||||
|
|
||||||
// TODO: move where? (commands.js would be fine, but timing issue)
|
// TODO: move where? (commands.js would be fine, but timing issue)
|
||||||
commandManager.addUserCommand(new vimperator.Command(["com[mand]"],
|
commandManager.addUserCommand(new vimperator.Command(["com[mand]"],
|
||||||
@@ -1000,98 +757,6 @@ vimperator.Commands = function () //{{{
|
|||||||
{ shortHelp: "Remove all abbreviations for Insert mode" }
|
{ shortHelp: "Remove all abbreviations for Insert mode" }
|
||||||
));
|
));
|
||||||
|
|
||||||
// move to v.AutoCommands:
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["au[tocmd]"],
|
|
||||||
function (args, special)
|
|
||||||
{
|
|
||||||
if (!args)
|
|
||||||
{
|
|
||||||
if (special) // :au!
|
|
||||||
vimperator.autocommands.remove(null, null);
|
|
||||||
else // :au
|
|
||||||
vimperator.autocommands.list(null, null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// (?: ) means don't store; (....)? <-> exclamation marks makes the group optional
|
|
||||||
var [all, asterix, auEvent, regex, cmds] = args.match(/^(\*)?(?:\s+)?(\S+)(?:\s+)?(\S+)?(?:\s+)?(.+)?$/);
|
|
||||||
|
|
||||||
if (cmds)
|
|
||||||
{
|
|
||||||
vimperator.autocommands.add(auEvent, regex, cmds);
|
|
||||||
}
|
|
||||||
else if (regex) // e.g. no cmds provided
|
|
||||||
{
|
|
||||||
if (special)
|
|
||||||
vimperator.autocommands.remove(auEvent, regex);
|
|
||||||
else
|
|
||||||
vimperator.autocommands.list(auEvent, regex);
|
|
||||||
}
|
|
||||||
else if (auEvent)
|
|
||||||
{
|
|
||||||
if (asterix)
|
|
||||||
if (special)
|
|
||||||
vimperator.autocommands.remove(null, auEvent); // ':au! * auEvent'
|
|
||||||
else
|
|
||||||
vimperator.autocommands.list(null, auEvent);
|
|
||||||
else
|
|
||||||
if (special)
|
|
||||||
vimperator.autocommands.remove(auEvent, null);
|
|
||||||
else
|
|
||||||
vimperator.autocommands.list(auEvent, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
shortHelp: "Execute commands automatically on events",
|
|
||||||
completer: function (filter) { return vimperator.completion.autocommands(filter); }
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
// move to events.js:
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["macros"],
|
|
||||||
function (arg)
|
|
||||||
{
|
|
||||||
var str = "<table>";
|
|
||||||
var macroRef = vimperator.events.getMacros(arg);
|
|
||||||
for (var item in macroRef)
|
|
||||||
str += "<tr><td> " + item + " </td><td>" +
|
|
||||||
vimperator.util.escapeHTML(macroRef[item]) + "</td></tr>";
|
|
||||||
|
|
||||||
str += "</table>";
|
|
||||||
|
|
||||||
vimperator.echo(str, vimperator.commandline.FORCE_MULTILINE);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
shortHelp: "List macros matching a regex"
|
|
||||||
}
|
|
||||||
));
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["delmac[ros]"],
|
|
||||||
function (arg)
|
|
||||||
{
|
|
||||||
if (!arg)
|
|
||||||
vimperator.echoerr("E474: Invalid argument");
|
|
||||||
else
|
|
||||||
vimperator.events.deleteMacros(arg);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
shortHelp: "Delete macros matching a regex"
|
|
||||||
}
|
|
||||||
));
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["pl[ay]"],
|
|
||||||
function (arg)
|
|
||||||
{
|
|
||||||
if (!arg)
|
|
||||||
vimperator.echoerr("E474: Invalid argument");
|
|
||||||
else
|
|
||||||
vimperator.events.playMacro(arg);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
shortHelp: "Play a macro",
|
|
||||||
completer: function (filter) { return vimperator.completion.macros(filter); }
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
// TODO: add helper method: addMappingCommand
|
// TODO: add helper method: addMappingCommand
|
||||||
// 0 args -> list all maps
|
// 0 args -> list all maps
|
||||||
// 1 arg -> list the maps starting with args
|
// 1 arg -> list the maps starting with args
|
||||||
@@ -1268,40 +933,12 @@ vimperator.Commands = function () //{{{
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
// move to find.js:
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["noh[lsearch]"],
|
|
||||||
function (args) { vimperator.search.clear(); },
|
|
||||||
{ shortHelp: "Remove the search highlighting" }
|
|
||||||
));
|
|
||||||
|
|
||||||
// move to either events.js or vim.js?
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["norm[al]"],
|
|
||||||
function (args, special)
|
|
||||||
{
|
|
||||||
if (!args)
|
|
||||||
{
|
|
||||||
vimperator.echoerr("E471: Argument required");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
vimperator.events.feedkeys(args, special);
|
|
||||||
},
|
|
||||||
{
|
|
||||||
shortHelp: "Execute Normal mode commands"
|
|
||||||
}
|
|
||||||
));
|
|
||||||
// TODO: remove/change preview window
|
// TODO: remove/change preview window
|
||||||
commandManager.addUserCommand(new vimperator.Command(["pc[lose]"],
|
commandManager.addUserCommand(new vimperator.Command(["pc[lose]"],
|
||||||
function () { vimperator.previewwindow.hide(); },
|
function () { vimperator.previewwindow.hide(); },
|
||||||
{ shortHelp: "Close preview window on bottom of screen" }
|
{ shortHelp: "Close preview window on bottom of screen" }
|
||||||
));
|
));
|
||||||
|
|
||||||
// move to tabs.js
|
|
||||||
commandManager.addUserCommand(new vimperator.Command(["reloada[ll]"],
|
|
||||||
function (args, special) { vimperator.tabs.reloadAll(special); },
|
|
||||||
{ shortHelp: "Reload all pages" }
|
|
||||||
));
|
|
||||||
|
|
||||||
// TODO: check for v.has("windows")
|
// TODO: check for v.has("windows")
|
||||||
commandManager.addUserCommand(new vimperator.Command(["winc[lose]", "wc[lose]"],
|
commandManager.addUserCommand(new vimperator.Command(["winc[lose]", "wc[lose]"],
|
||||||
function (args) { window.close(); },
|
function (args) { window.close(); },
|
||||||
|
|||||||
@@ -42,6 +42,56 @@ vimperator.AutoCommands = function() //{{{
|
|||||||
throw StopIteration;
|
throw StopIteration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
|
////////////////////// COMMANDS ////////////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
|
vimperator.commands.add(["au[tocmd]"],
|
||||||
|
"Execute commands automatically on events",
|
||||||
|
function (args, special)
|
||||||
|
{
|
||||||
|
if (!args)
|
||||||
|
{
|
||||||
|
if (special) // :au!
|
||||||
|
vimperator.autocommands.remove(null, null);
|
||||||
|
else // :au
|
||||||
|
vimperator.autocommands.list(null, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// (?: ) means don't store; (....)? <-> exclamation marks makes the group optional
|
||||||
|
var [all, asterix, auEvent, regex, cmds] = args.match(/^(\*)?(?:\s+)?(\S+)(?:\s+)?(\S+)?(?:\s+)?(.+)?$/);
|
||||||
|
|
||||||
|
if (cmds)
|
||||||
|
{
|
||||||
|
vimperator.autocommands.add(auEvent, regex, cmds);
|
||||||
|
}
|
||||||
|
else if (regex) // e.g. no cmds provided
|
||||||
|
{
|
||||||
|
if (special)
|
||||||
|
vimperator.autocommands.remove(auEvent, regex);
|
||||||
|
else
|
||||||
|
vimperator.autocommands.list(auEvent, regex);
|
||||||
|
}
|
||||||
|
else if (auEvent)
|
||||||
|
{
|
||||||
|
if (asterix)
|
||||||
|
if (special)
|
||||||
|
vimperator.autocommands.remove(null, auEvent); // ':au! * auEvent'
|
||||||
|
else
|
||||||
|
vimperator.autocommands.list(null, auEvent);
|
||||||
|
else
|
||||||
|
if (special)
|
||||||
|
vimperator.autocommands.remove(auEvent, null);
|
||||||
|
else
|
||||||
|
vimperator.autocommands.list(auEvent, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
completer: function (filter) { return vimperator.completion.autocommands(filter); }
|
||||||
|
});
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////}}}
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
@@ -514,6 +564,48 @@ vimperator.Events = function () //{{{
|
|||||||
},
|
},
|
||||||
{ flags: vimperator.Mappings.flags.ARGUMENT | vimperator.Mappings.flags.COUNT });
|
{ flags: vimperator.Mappings.flags.ARGUMENT | vimperator.Mappings.flags.COUNT });
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
|
////////////////////// COMMANDS ////////////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
|
vimperator.commands.add(["delmac[ros]"],
|
||||||
|
"Delete macros",
|
||||||
|
function (arg)
|
||||||
|
{
|
||||||
|
if (!arg)
|
||||||
|
vimperator.echoerr("E474: Invalid argument");
|
||||||
|
else
|
||||||
|
vimperator.events.deleteMacros(arg);
|
||||||
|
});
|
||||||
|
|
||||||
|
vimperator.commands.add(["macros"],
|
||||||
|
"List all macros",
|
||||||
|
function (arg)
|
||||||
|
{
|
||||||
|
var str = "<table>";
|
||||||
|
var macroRef = vimperator.events.getMacros(arg);
|
||||||
|
for (var item in macroRef)
|
||||||
|
str += "<tr><td> " + item + " </td><td>" +
|
||||||
|
vimperator.util.escapeHTML(macroRef[item]) + "</td></tr>";
|
||||||
|
|
||||||
|
str += "</table>";
|
||||||
|
|
||||||
|
vimperator.echo(str, vimperator.commandline.FORCE_MULTILINE);
|
||||||
|
});
|
||||||
|
|
||||||
|
vimperator.commands.add(["pl[ay]"],
|
||||||
|
"Replay a recorded macro",
|
||||||
|
function (arg)
|
||||||
|
{
|
||||||
|
if (!arg)
|
||||||
|
vimperator.echoerr("E474: Invalid argument");
|
||||||
|
else
|
||||||
|
vimperator.events.playMacro(arg);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
completer: function (filter) { return vimperator.completion.macros(filter); }
|
||||||
|
});
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////}}}
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ vimperator.Search = function () //{{{
|
|||||||
/////////////////////////////////////////////////////////////////////////////}}}
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
////////////////////// MAPPINGS ////////////////////////////////////////////////
|
////////////////////// MAPPINGS ////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
var modes = vimperator.config.browserModes || [vimperator.modes.NORMAL];
|
var modes = vimperator.config.browserModes || [vimperator.modes.NORMAL];
|
||||||
|
|
||||||
vimperator.mappings.add(modes,
|
vimperator.mappings.add(modes,
|
||||||
@@ -178,6 +179,14 @@ vimperator.Search = function () //{{{
|
|||||||
vimperator.search.findAgain();
|
vimperator.search.findAgain();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
|
////////////////////// COMMANDS ////////////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
|
vimperator.commands.add(["noh[lsearch]"],
|
||||||
|
"Remove the search highlighting",
|
||||||
|
function (args) { vimperator.search.clear(); });
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////}}}
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|||||||
@@ -200,6 +200,96 @@ vimperator.Options = function () //{{{
|
|||||||
////////////////////// COMMANDS ////////////////////////////////////////////////
|
////////////////////// COMMANDS ////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
|
vimperator.commands.add(["let"],
|
||||||
|
"Set or list a variable",
|
||||||
|
function (args)
|
||||||
|
{
|
||||||
|
if (!args)
|
||||||
|
{
|
||||||
|
var str = "";
|
||||||
|
for (var i in vimperator.globalVariables)
|
||||||
|
{
|
||||||
|
var value = vimperator.globalVariables[i];
|
||||||
|
if (typeof value == "number")
|
||||||
|
var prefix = "#";
|
||||||
|
else if (typeof value == "function")
|
||||||
|
var prefix = "*";
|
||||||
|
else
|
||||||
|
var prefix = "";
|
||||||
|
|
||||||
|
str += "<tr><td style=\"width: 200px;\">" + i + "</td><td>" + prefix + value + "</td>\n";
|
||||||
|
}
|
||||||
|
if (str)
|
||||||
|
vimperator.echo("<table>" + str + "</table>", vimperator.commandline.FORCE_MULTILINE);
|
||||||
|
else
|
||||||
|
vimperator.echo("No variables found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var matches;
|
||||||
|
// 1 - type, 2 - name, 3 - +-., 4 - expr
|
||||||
|
if (matches = args.match(/([$@&])?([\w:]+)\s*([+-.])?=\s*(.+)/))
|
||||||
|
{
|
||||||
|
if (!matches[1])
|
||||||
|
{
|
||||||
|
var reference = vimperator.variableReference(matches[2]);
|
||||||
|
if (!reference[0] && matches[3])
|
||||||
|
{
|
||||||
|
vimperator.echoerr("E121: Undefined variable: " + matches[2]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var expr = vimperator.eval(matches[4]);
|
||||||
|
if (typeof expr === undefined)
|
||||||
|
{
|
||||||
|
vimperator.echoerr("E15: Invalid expression: " + matches[4]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!reference[0])
|
||||||
|
{
|
||||||
|
if (reference[2] == "g")
|
||||||
|
reference[0] = vimperator.globalVariables;
|
||||||
|
else
|
||||||
|
return; // for now
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matches[3])
|
||||||
|
{
|
||||||
|
if (matches[3] == "+")
|
||||||
|
reference[0][reference[1]] += expr;
|
||||||
|
else if (matches[3] == "-")
|
||||||
|
reference[0][reference[1]] -= expr;
|
||||||
|
else if (matches[3] == ".")
|
||||||
|
reference[0][reference[1]] += expr.toString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
reference[0][reference[1]] = expr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 1 - name
|
||||||
|
else if (matches = args.match(/^\s*([\w:]+)\s*$/))
|
||||||
|
{
|
||||||
|
var reference = vimperator.variableReference(matches[1]);
|
||||||
|
if (!reference[0])
|
||||||
|
{
|
||||||
|
vimperator.echoerr("E121: Undefined variable: " + matches[1]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var value = reference[0][reference[1]];
|
||||||
|
if (typeof value == "number")
|
||||||
|
var prefix = "#";
|
||||||
|
else if (typeof value == "function")
|
||||||
|
var prefix = "*";
|
||||||
|
else
|
||||||
|
var prefix = "";
|
||||||
|
vimperator.echo(reference[1] + "\t\t" + prefix + value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
vimperator.commands.add(["pref[erences]", "prefs"],
|
vimperator.commands.add(["pref[erences]", "prefs"],
|
||||||
"Show " + vimperator.config.appName + " Preferences",
|
"Show " + vimperator.config.appName + " Preferences",
|
||||||
function (args, special, count, modifiers)
|
function (args, special, count, modifiers)
|
||||||
@@ -476,6 +566,33 @@ vimperator.Options = function () //{{{
|
|||||||
completer: function (filter, special) { return vimperator.completion.option(filter, special); }
|
completer: function (filter, special) { return vimperator.completion.option(filter, special); }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vimperator.commands.add(["unl[et]"],
|
||||||
|
"Delete a variable",
|
||||||
|
function (args, special)
|
||||||
|
{
|
||||||
|
if (!args)
|
||||||
|
{
|
||||||
|
vimperator.echoerr("E471: Argument required");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var names = args.split(/ /);
|
||||||
|
if (typeof names == "string") names = [names];
|
||||||
|
var length = names.length;
|
||||||
|
for (var i = 0, name = names[i]; i < length; name = names[++i])
|
||||||
|
{
|
||||||
|
var reference = vimperator.variableReference(name);
|
||||||
|
if (!reference[0])
|
||||||
|
{
|
||||||
|
if (!special)
|
||||||
|
vimperator.echoerr("E108: No such variable: " + name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete reference[0][reference[1]];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////}}}
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|||||||
@@ -238,6 +238,10 @@ vimperator.Tabs = function () //{{{
|
|||||||
vimperator.buffer.list(special);
|
vimperator.buffer.list(special);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vimperator.commands.add(["reloada[ll]"],
|
||||||
|
"Reload all tab pages",
|
||||||
|
function (args, special) { vimperator.tabs.reloadAll(special); });
|
||||||
|
|
||||||
vimperator.commands.add(["tab"],
|
vimperator.commands.add(["tab"],
|
||||||
"Execute a command and tell it to output in a new tab",
|
"Execute a command and tell it to output in a new tab",
|
||||||
function (args) { vimperator.execute(args, { inTab: true }); },
|
function (args) { vimperator.execute(args, { inTab: true }); },
|
||||||
|
|||||||
129
content/vim.js
129
content/vim.js
@@ -254,6 +254,135 @@ const vimperator = (function () //{{{
|
|||||||
{
|
{
|
||||||
completer: function (filter) { return vimperator.completion.javascript(filter); }
|
completer: function (filter) { return vimperator.completion.javascript(filter); }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vimperator.commands.add(["norm[al]"],
|
||||||
|
"Execute Normal mode commands",
|
||||||
|
function (args, special)
|
||||||
|
{
|
||||||
|
if (!args)
|
||||||
|
{
|
||||||
|
vimperator.echoerr("E471: Argument required");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vimperator.events.feedkeys(args, special);
|
||||||
|
});
|
||||||
|
|
||||||
|
vimperator.commands.add(["res[tart]"],
|
||||||
|
"Force " + vimperator.config.appName + " to restart",
|
||||||
|
function () { vimperator.restart(); });
|
||||||
|
|
||||||
|
vimperator.commands.add(["time"],
|
||||||
|
"Profile a piece of code or run a command multiple times",
|
||||||
|
function (args, special, count)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (count > 1)
|
||||||
|
{
|
||||||
|
var i = count;
|
||||||
|
var beforeTime = Date.now();
|
||||||
|
|
||||||
|
if (args && args[0] == ":")
|
||||||
|
{
|
||||||
|
while (i--)
|
||||||
|
vimperator.execute(args);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (i--)
|
||||||
|
eval("with(vimperator){" + args + "}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (special)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var afterTime = Date.now();
|
||||||
|
|
||||||
|
if ((afterTime - beforeTime) / count >= 100)
|
||||||
|
{
|
||||||
|
var each = ((afterTime - beforeTime) / 1000.0 / count);
|
||||||
|
var eachUnits = "sec";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var each = ((afterTime - beforeTime) / count);
|
||||||
|
var eachUnits = "msec";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (afterTime - beforeTime >= 100)
|
||||||
|
{
|
||||||
|
var total = ((afterTime - beforeTime) / 1000.0);
|
||||||
|
var totalUnits = "sec";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var total = (afterTime - beforeTime);
|
||||||
|
var totalUnits = "msec";
|
||||||
|
}
|
||||||
|
|
||||||
|
var str = ":" + vimperator.util.escapeHTML(vimperator.commandline.getCommand()) + "<br/>" +
|
||||||
|
"<table>" +
|
||||||
|
"<tr align=\"left\" class=\"hl-Title\"><th colspan=\"3\">Code execution summary</th></tr>" +
|
||||||
|
"<tr><td> Executed:</td><td align=\"right\"><span style=\"color: green\">" + count + "</span></td><td>times</td></tr>" +
|
||||||
|
"<tr><td> Average time:</td><td align=\"right\"><span style=\"color: green\">" + each.toFixed(2) + "</span></td><td>" + eachUnits + "</td></tr>" +
|
||||||
|
"<tr><td> Total time:</td><td align=\"right\"><span style=\"color: red\">" + total.toFixed(2) + "</span></td><td>" + totalUnits + "</td></tr>" +
|
||||||
|
"</table>";
|
||||||
|
|
||||||
|
vimperator.commandline.echo(str, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var beforeTime = Date.now();
|
||||||
|
if (args && args[0] == ":")
|
||||||
|
vimperator.execute(args);
|
||||||
|
else
|
||||||
|
eval("with(vimperator){" + args + "}");
|
||||||
|
|
||||||
|
if (special)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var afterTime = Date.now();
|
||||||
|
|
||||||
|
if (afterTime - beforeTime >= 100)
|
||||||
|
vimperator.echo("Total time: " + ((afterTime - beforeTime) / 1000.0).toFixed(2) + " sec");
|
||||||
|
else
|
||||||
|
vimperator.echo("Total time: " + (afterTime - beforeTime) + " msec");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
vimperator.echoerr(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
vimperator.commands.add(["ve[rsion]"],
|
||||||
|
"Show version information",
|
||||||
|
function (args, special)
|
||||||
|
{
|
||||||
|
if (special)
|
||||||
|
vimperator.open("about:");
|
||||||
|
else
|
||||||
|
vimperator.echo(":" + vimperator.util.escapeHTML(vimperator.commandline.getCommand()) + "\n" +
|
||||||
|
vimperator.config.appName + " " + vimperator.version +
|
||||||
|
" running on:\n" + navigator.userAgent);
|
||||||
|
});
|
||||||
|
|
||||||
|
vimperator.commands.add(["viu[sage]"],
|
||||||
|
"List all mappings with a short description",
|
||||||
|
function (args, special, count, modifiers)
|
||||||
|
{
|
||||||
|
var usage = "<table>";
|
||||||
|
for (let mapping in vimperator.mappings)
|
||||||
|
{
|
||||||
|
usage += "<tr><td style='color: magenta; padding-right: 20px'> " +
|
||||||
|
vimperator.util.escapeHTML(mapping.names[0]) + "</td><td>" +
|
||||||
|
vimperator.util.escapeHTML(mapping.shortHelp || "") + "</td></tr>";
|
||||||
|
}
|
||||||
|
usage += "</table>";
|
||||||
|
|
||||||
|
vimperator.echo(usage, vimperator.commandline.FORCE_MULTILINE);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// initially hide all GUI, it is later restored unless the user has :set go= or something
|
// initially hide all GUI, it is later restored unless the user has :set go= or something
|
||||||
|
|||||||
Reference in New Issue
Block a user