Skip to content

Instantly share code, notes, and snippets.

@tyru
Created April 28, 2010 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyru/381801 to your computer and use it in GitHub Desktop.
Save tyru/381801 to your computer and use it in GitHub Desktop.
altercmd.js - altercmd.vim in Vimperator plugin.
javascript <<EOS
liberator.modules.commands.addUserCommand(
['altercommand'],
'this is vimperator plugin version of vim plugin altercmd.vim',
function (arg) {
/*
* tw[itter]
* =>
* var pairs = {
* 'tw': 'twitter',
* 'twi': 'twitter',
* 'twit': 'twitter',
* 'twitt': 'twitter',
* 'twitte': 'twitter',
* 'twitter': 'twitter',
* }
*/
var pairs = (function () {
var original_arg = arg[0];
var r = {};
if (original_arg.match(/^([^\[\]]+)\[([^\[\]]+)\]$/)) {
// assert(arg[0] === RegExp.$1 + "[" + RegExp.$2 + "]");
var head = RegExp.$1, complete_str = head + RegExp.$2;
for (; head !== complete_str; head += complete_str[head.length]) {
r[head] = arg.literalArg;
}
r[head] = arg.literalArg;
}
else {
r[original_arg] = arg.literalArg;
}
return r;
})();
for (var original in pairs) {
var alternate = pairs[original];
abbreviations.add(
[modes.COMMAND_LINE],
original,
function ()
commandline.command == original ? alternate : original
);
}
},
{argCount: 2, literal: true, completer: completion.command},
true
);
EOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment