diff options
Diffstat (limited to 'echopy.js')
-rw-r--r-- | echopy.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/echopy.js b/echopy.js new file mode 100644 index 0000000..908f14b --- /dev/null +++ b/echopy.js @@ -0,0 +1,61 @@ +// ==VimperatorPlugin== +// @name echo and copy +// @description echo and copy +// @description-ja echo and copy +// @license Creative Commons 2.1 (Attribution + Share Alike) +// @version 1.0 +// @author anekos (anekos@snca.net) +// @maxVersion 2.0pre +// @minVersion 2.0pre +// ==/VimperatorPlugin== +// +// Usage: +// :echo <EXPRESSION> +// echo with copy (to clipboard). +// +// Usage-ja: +// :echo <EXPRESSION> +// echo $B$9$k$7$FF1;~$K%/%j%C%W%\!<%I$K%3%T!<(B +// +// Links: +// http://d.hatena.ne.jp/nokturnalmortum/20081111#1226414487 + +(function () { + + function neko (obj, useColor) { + switch (typeof obj) { + case 'object': + return liberator.modules.util.objectToString(obj, useColor); + case 'function': + return liberator.modules.util.escapeHTML(obj.toString()); + case 'number': + case 'boolean': + return '' + obj; + case 'undefined': + return 'undefined'; + } + return obj; + } + + let echo = commands.get('echo'); + let original_action = echo.action; + + echo.action = function (arg, bang) { + if (bang) { + try { + if (arg.string == '') + return; + let obj = liberator.eval(arg.string); + liberator.echo(neko(obj, true)); + liberator.modules.util.copyToClipboard(neko(obj, false)); + } catch (e) { + liberator.echoerr(e); + } + } else { + original_action.apply(this, arguments); + } + }; + echo.bang = true; + + +})(); |