From a16242ede43d2a0e34fc4e47ecc90359b052eb9d Mon Sep 17 00:00:00 2001 From: anekos Date: Sat, 6 Feb 2010 06:00:07 +0000 Subject: :extbisect を追加 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@36637 d0d07461-0603-4401-acd4-de1884942a52 --- extension-manager.js | 184 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 173 insertions(+), 11 deletions(-) (limited to 'extension-manager.js') diff --git a/extension-manager.js b/extension-manager.js index b6fd2d7..f46fa3e 100755 --- a/extension-manager.js +++ b/extension-manager.js @@ -39,7 +39,7 @@ let PLUGIN_INFO = アドオン管理 extension manager アドオンを管理します。 - 1.0.0 + 1.1.0 anekos new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) @@ -67,7 +67,7 @@ let PLUGIN_INFO = // INFO {{{ let INFO = <> - - :extstate sub-command name extension-names...

- Store or restore current extensions state with name. -

The following sub-commands are interpreted.

- if the extension-names arguments are specified, - this command is only for these extensions. - + 拡張の有効無効状態を name で保存復帰します。 + extension-names で拡張名を指定しておくと、指定された拡張のみが保存復帰の対象になります。 +

以下の sub-commands があります。

+
+
store
保存
+
restore
復帰
+
+

+
+ + + :extbisect + :extbisect sub-command + +

+ 問題のある拡張などをあぶり出すためのコマンドです。 + 二分探索ぽい方法よって、効率的に困った拡張を探し出します。 + 自動的に拡張の有効無効を切り替えていくので、かなり楽が出来ると思います。 +

+

+ 作業手順。 + (ok fail start を実行すると自動的に再起動します) +

    +
  1. ":extbisect start" で開始
  2. +
  3. 問題が起きていないかテスト
  4. +
  5. 起きていなければ":extbisect ok"、起きていれば":extbisect fail"を実行
  6. +
  7. 再起動するので、2 を再び繰り返す。
  8. +
+

+ 問題のある拡張がなんであるか、確定したら ok/fail したときにメッセージが出ます。 + メッセージを確認したら、":extbisect reset" で拡張の状態を元に戻してください。 +

+

+ テストを行うことで、エラーで Firefox が終了してしまう場合は、再起動後に ok / fail を実行してください。 +

@@ -130,6 +157,9 @@ let INFO = (function () { let states = storage.newMap('plugins-extman-states', {store: true}); + let bisect = storage.newMap('plugins-extman-bisect', {store: true}); + + states.modify = bisect.modify = function (name, func) this.set(name, func(this.get(name))); function xabled (id, enable) services.get("extensionManager")[enable ? 'enableItem' : 'disableItem'](id); @@ -149,6 +179,12 @@ let INFO = states.set(name, {extensions: es, date: new Date()}); } + function slash (ary, index) + [ary.slice(0, index), ary.slice(index)]; + + function isVimp (ext) + (ext.name == 'Vimperator'); + store('last'); let extState = { @@ -196,6 +232,106 @@ let INFO = } }; + let extBisect = { + start: function () { + if (this.__notReady(false)) + return; + let targets = liberator.extensions.filter(function (ext) !isVimp(ext) && ext.enabled); + bisect.set('store', liberator.extensions); + bisect.set('state', 'started'); + let ([a, b] = slash(targets, targets.length / 2)) { + bisect.set('yet', a); + bisect.set('current', b); + } + bisect.save(); + this.__reflectCurrent(); + liberator.restart(); + }, + + ok: function () { + if (this.__notReady(true)) + return; + if (this.__finished(true)) + return; + bisect.modify('yet', function (value) { + let [a, b] = slash(value, value.length / 2); + bisect.set('current', a); + return b; + }); + this.__reflectCurrent(); + liberator.restart(); + }, + + fail: function () { + if (this.__notReady(true)) + return; + if (this.__finished(false)) + return; + bisect.modify('current', function (value) { + let [a, b] = slash(value, value.length / 2); + bisect.set('yet', a); + return b; + }); + this.__reflectCurrent(); + liberator.restart(); + }, + + show: function () { + function f (ext) liberator.echo(' ' + ext.name); + liberator.echo('<>'); + bisect.get('current').forEach(f) + liberator.echo('<>'); + bisect.get('yet').forEach(f) + }, + + reset: function () { + if (this.__notReady(true)) + return; + bisect.set('state', ''); + bisect.get('store').forEach(function (ext) xabled(ext.id, ext.enabled)); + bisect.save(); + liberator.echo('extensions were reset'); + liberator.restart(); + }, + + __notReady: function (started) { + if (!!(bisect.get('state') == 'started') == !!started) + return false; + liberator.echoerr('extbisect has ' + (started ? 'not ' : '') + 'been started.'); + return true; + }, + + __finished: function (ok) { + function answer (ext) { + liberator.echo(util.escapeString(ext.name) + ' is the criminal!!'); + return true; + } + + let current = bisect.get('current'); + let yet = bisect.get('yet'); + + if (ok && yet.length <= 1) + return answer(yet[0]); + + if (!ok && current.length <= 1) + return answer(current[0]); + + return false; + }, + + __reflectCurrent: function () { + let current = bisect.get('current'); + liberator.extensions.forEach( + function (ext) + (xabled(ext.id, isVimp(ext) || current.some(function (e) e.id == ext.id))) + ); + }, + + __noSuchMethod__: function (name) { + liberator.echoerr(name + ' is not valid sub-command'); + } + }; + commands.addUserCommand( ['exts[tate]'], 'store / restore extensions state (enabled / disabled).', @@ -226,6 +362,32 @@ let INFO = true ); + commands.addUserCommand( + ['extbisect'], + 'bisectrrrrrrrrrrr', + function (args) { + let [cmd,] = args; + extBisect[cmd](); + }, + { + completer: function (context, args) { + if (args.length == 1) { + context.title = ['sub command', 'description']; + context.completions = [ + ['start', 'start bisect'], + ['ok', ''], + ['fail', ''], + ['reset', ''], + ['show', ''] + ]; + } + } + }, + true + ); + + + states.save(); })(); -- cgit v1.2.3