外国語の文献を読むとき、カーソル位置の単語を自動で取得できれば、それを辞書ソフトに投げることができて便利そうだなと思い、スクリプトを作った。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//!*script | |
// PPvのカーソル位置にある文字を返す | |
// 単語が空白区切りであることが前提 | |
// 例: *linemessage %*script(%0\Script\selectword.js) | |
var linetext = PPx.Extract('%*selecttext'); | |
var lh = PPx.Extract('%lH'); | |
// var blankpos = linetext.indexOf( ' ' ); | |
// 文字列を左右に分割し、空白前/後を削除 | |
var lstr = linetext.substr( 0, lh ).replace(/.*\s(.*?)$/, '$1'); | |
var rstr = linetext.substr( lh ).replace(/^(.*?)\s.*/, '$1'); | |
// 文字列を再結合 | |
var str = lstr+rstr; | |
// 句読点等を取り除く | |
var result = str.replace(/(\.|\,|\"|\'|\!|\?|\;|\:)/g, ''); | |
// ’以前を取り除く。フランス語の単語抽出用 | |
var result = result.replace(/.*’(.*)$/, '$1'); | |
// 文字数が45を超えていれば以降のコマンド実行を中止 | |
if (result.length > 45){ | |
PPx.SetPopLineMessage("文字数が多すぎます"); | |
PPx.Quit(-1); | |
} | |
PPx.Result = result; | |
PPx.Quit(); |
PPvをキャレットモードにし、以下のようなコマンドを打つ。
*linemessage %*script(%0Script\selectword.js)
0 件のコメント:
コメントを投稿