From 2160e7633a2e4e33bdab364ded4495385615fbee Mon Sep 17 00:00:00 2001 From: trapezoid Date: Fri, 4 Apr 2008 15:19:24 +0000 Subject: lang/javascript/vimperator-plugins/browser_object.js: add g:browser_object_prefix variable git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@8895 d0d07461-0603-4401-acd4-de1884942a52 --- browser_object.js | 96 ++++++++++++++++--------------------------------------- 1 file changed, 28 insertions(+), 68 deletions(-) (limited to 'browser_object.js') diff --git a/browser_object.js b/browser_object.js index 2cdbec4..67b5cf0 100755 --- a/browser_object.js +++ b/browser_object.js @@ -1,13 +1,19 @@ // Vimperator plugin: 'Map behave like text-object' -// Version: 0.1 -// Last Change: 04-Apr-2008. Jan 2008 +// Version: 0.2 +// Last Change: 05-Apr-2008. Jan 2008 // License: Creative Commons // Maintainer: Trapezoid - http://unsigned.g.hatena.ne.jp/Trapezoid // // Map behave like text-object for vimperator0.6.* // +// Variables: +// g:browser_object_prefix: +// default: '' +// usage: let g:browser_object_prefix = ',' // Mappings: -// {motion}{scope}{target} +// 'dd' +// Delete current tab (when prefix is '' only) +// '{motion}{scope}{target}' // Motions: // 'd' : Delete // 'y' : Yank @@ -42,36 +48,11 @@ } } - function Motions(){ - var motions = {}; + function Container(){ + var collections = {}; function iterator(){ - for(let i in motions) - yield motions[i]; - throw StopIteration; - } - return { - __iterator__:function(){ - return iterator(); - }, - add: function(id,handlerName){ - motions[id] = { - id: id, - handler: handlerName, - }; - }, - get: function(i){ - return motions[id]; - }, - getAll: function(){ - return motions; - } - } - } - function Scopes(){ - var scopes = {}; - function iterator(){ - for(let i in scopes) - yield scopes[i]; + for(var i in collections) + yield collections[i]; throw StopIteration; } return { @@ -79,46 +60,22 @@ return iterator(); }, add: function(id,handler){ - scopes[id] = { + collections[id] = { id: id, handler: handler, }; }, get: function(id){ - return scopes[id]; - }, - getAll: function(){ - return scopes; - } - } - } - function Targets(){ - var targets = {}; - function iterator(){ - for(var i in motions) - yield targets[i]; - throw StopIteration; - } - return { - __iterator__: function(){ - return iterator(); - }, - add: function(id,handler){ - targets[id] = { - id: id, - handler: handler, - }; - }, - get: function(id){ - return targets[id]; + return collections[id]; }, } } var browserObject = {}; - browserObject.motions = new Motions(); - browserObject.scopes = new Scopes(); - browserObject.targets = new Targets(); + + browserObject.motions = new Container(); + browserObject.scopes = new Container(); + browserObject.targets = new Container(); browserObject.motions.add('d','close'); browserObject.motions.add('y','yank'); @@ -133,7 +90,6 @@ }); browserObject.scopes.add('o',function(ary){ var active = this.active(); - liberator.log([i for (i in ary) if (i != active)]); return [ary[i] for (i in ary) if (i != active)]; }); browserObject.scopes.add('i',function(ary){ @@ -144,13 +100,15 @@ }); browserObject.targets.add('t',new Tab()); + + var prefix = liberator.globalVariables.browser_object_prefix || ""; for (let m in browserObject.motions){ for (let s in browserObject.scopes){ let motion = m; let scope = s; liberator.log(motion.id + scope.id); - liberator.mappings.addUserMap([liberator.modes.NORMAL], [motion.id + scope.id], + liberator.mappings.addUserMap([liberator.modes.NORMAL], [prefix + motion.id + scope.id], "Browser Object Mapping", function (arg) { var target = browserObject.targets.get(arg); @@ -162,8 +120,10 @@ { flags: liberator.Mappings.flags.ARGUMENT}); } } - liberator.mappings.addUserMap([liberator.modes.NORMAL], ["dd"], - "Delete current buffer", - function (count) { liberator.tabs.remove(getBrowser().mCurrentTab, count, false, 0); }, - { flags: liberator.Mappings.flags.COUNT }); + + if(prefix == "") + liberator.mappings.addUserMap([liberator.modes.NORMAL], ["dd"], + "Delete current buffer", + function (count) { liberator.tabs.remove(getBrowser().mCurrentTab, count, false, 0); }, + { flags: liberator.Mappings.flags.COUNT }); })(); -- cgit v1.2.3