auto_word_select_mode

Description
Add auto word select mode.単語を自動選択するモードを追加します
Latest version
1.2.3
Author
snaka
License
MIT style license

for 2.2
http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/branches/2.2/auto_word_select_mode.js
for 2.1
http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/branches/2.1/auto_word_select_mode.js
for 2.0
not supported
for 1.2
not supported
for Nightly
http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/trunk/auto_word_select_mode.js

Subject

Add auto word select mode.
Mode name is "AUTO_WORD_SELECT".
Press 'I' key to entering to AUTO_WORD_SELECT mode.
If you want exit mode, press 'I' key again.
This mode alway selects current word.

Global variables

g:auto_word_select_key
The key that entering to AUTO_WORD_SELECT mode.
Default is 'I'.

About define keymap with AUTO_WORD_SELECT mode

The example of defining the key-map for the AUTO_WORD_SELECT mode
is shown as follows.
The following definitions are examples of assign behavior that
displays the translation result of the word selecting it by 'alc'
service by using multi_requester.js for 's' key.
liberator.registerObserver("enter", function() {
  mappings.addUserMap(
    [modes.AUTO_WORD_SELECT],
    ["s"],
    "Translate selected word by multi_requester.js.",
    function() {
      // FIXME:
      // A present mode is preserved in the stack beforehand by the push() method
      // because it doesn't return to AUTO_WORD_SELECT mode before that when
      // returning from the OUTPUT_MULTILINE mode.
      modes.push(modes.AUTO_WORD_SELECT, null, true);

      var selText = content.getSelection().toString();
      var pattern = /[a-zA-Z]+/;
      selText = pattern.test(selText) ? pattern.exec(selText) : selText;
      events.feedkeys(":mr alc " + selText + "<CR>", true, true);
    }
  );
});

概要

単語を自動選択するモード(AUTO_WORD_SELECT)を追加します。
'I'キーを押すことによって、AUTO_WORD_SELECTモードに移行します。
このモードを抜けるには、再度'I'キーを押します。
このモードでは常に単語が選択されている状態になり、キャレットの
移動の単位も単語毎の移動になります。
コンテンツ内の単語を頻繁に選択&検索する場合などに便利です。

グローバル変数

g:auto_word_select_key
AUTO_WORD_SELECTモードに移行するためのキーです。
デフォルトは'I'です。

AUTO_WORD_SELECTモード用のマップの定義について

このモード用のマップの定義例として、multi_requester.jsを使用して
web上の辞書サービスを使用して検索結果を表示するためのマップを
定義する例を示します。
liberator.registerObserver("enter", function() {
  mappings.addUserMap(
    [modes.AUTO_WORD_SELECT],
    ["s"],
    "Translate selected word by multi_requester.js.",
    function() {
      // FIXME:
      // A present mode is preserved in the stack beforehand by the push() method
      // because it doesn't return to AUTO_WORD_SELECT mode before that when
      // returning from the OUTPUT_MULTILINE mode.
      modes.push(modes.AUTO_WORD_SELECT, null, true);

      var selText = content.getSelection().toString();
      var pattern = /[a-zA-Z]+/;
      selText = pattern.test(selText) ? pattern.exec(selText) : selText;
      events.feedkeys(":mr alc " + selText + "<CR>", true, true);
    }
  );
});
上記の例ではAUTO_WORD_SELECTモードにおいて、単語を選択した後、's'キーを
押すと'alc'で登録されているサービスに対して検索を依頼し、その結果を
画面下部のバッファに表示します。
modes.push()は、OUTPUT_MULTILINEモードから抜けたときに、AUTO_WORD_SELECT
モードに復帰させるために行っています。
追加されたモードに対するマッピングはプラグインを読み込んだ後に行う必要
があるので、registerObserver()で"enter"のタイミングでaddUserMap()している。
multi_requester.jsの使い方については、ソースのコメントや以下の
サイトなどを参照してください。
  • http://vimperator.kurinton.net/plugins/multi_requester.html
  • http://d.zeromemory.info/2008/11/20/vimperator-multi_requester.html
back to index