>>759
ちょっと趣旨は変わるが,こんな感じだろうか?
// 括弧補完
// 同一行内直近の閉じていない括弧を閉じます。
String.prototype.toEscape = function () { return this.replace(/(\W)/g, '\\$1'); }

var brL = '“‘【[〔〈《「『[{(';
var brR = '”’】]〕〉》」』]})';

MoveHistSet(); // カーソル位置保存
GoLineTop(0x04 + 0x08);
var str = GetSelectedString();
MoveHistPrev(); // カーソルを戻す
var re;
for (var i = 0; i < brL.length; i++) {
var cL = brL.charAt(i).toEscape();
var cR = brR.charAt(i).toEscape();
re = new RegExp(cL +'[^'+ cL +']*?'+ cR, 'g');
var str_bak;
do {
str_bak = str;
str = str.replace(re, '');
} while (str_bak !== str);
}
re = new RegExp('(['+ brL.toEscape() +'])[^'+ brL.toEscape() +']*$');
if (re.exec(str)) {
InsText(brR.charAt(brL.indexOf(RegExp.$1)));
}