// // 括弧を外す // Version 2.0 (2015/11/08) // by mobitan http://mobitan.org/ // $Paren = "[()\\[\\]{}<>()〔〕[]{}〈〉《》「」『』【】]"; // 正規表現 $Opens = "([{<(〔[{〈《「『【"; // 文字列 setcompatiblemode 0x12020F; loaddll("hmjre.dll"); ##_ = dllfunc("SetUnicodeIndexAutoConvert", 1); begingroupundo; disableerrormsg; if (!#debug) disabledraw; call ForEachRegion "Main"; enabledraw; enableerrormsg; endgroupundo; freedll; endmacro; Main: if (selecting) { moveto seltopx, seltopy; } escape; ##ol = lineno; ##oc = column; if (colorcode & 0x1F == 0x03) { searchup $Paren, regular, maskcomment, maskonly, nohilight; } else { searchup $Paren, regular, maskcomment, nohilight; } while (result && strstr($Opens, char(code)) < 0) { gokakko; // 閉じ括弧→開き括弧 if (!result) break; findup; } if (result) { ##bl = lineno; ##bc = column; beginsel; gokakko; // 開き括弧→閉じ括弧 } if (result) { right; endsel; ##dl = lineno; ##dc = column; } else { escape; moveto2 ##oc, ##ol; message "カーソル位置を囲む括弧が見つかりません"; return; } $$text = gettext2(##bc, ##bl, ##dc, ##dl, true); // 括弧を含む if (##bl < ##dl) { // インデント補正 call GetIndent ##bl; $$indent = $$return; call Match $$text, "\\n[ \\t]*"; call Subst $$text, $$return, "\\n" + quote($$indent); $$text = $$return; } insert wcsmidstr($$text, 1, wcslen($$text) - 2); beginsel; moveto2 ##bc, ##bl; endsel; return; ForEachRegion: // 各副範囲を処理 // $$1 = サブルーチン名 if (multiselecting || rectselecting) { $$z1 = currentmacrobasename + "#multisel1"; $$z2 = currentmacrobasename + "#multisel2"; colormarker 0xFFFFFF, 0xCC6666, 11, 1, 0, $$z1; gofiletop; nextcolormarker 0x09, 0, $$z1; while (result) { beginsel; nextcolormarker 0x0A, 0, $$z1; endsel; deletecolormarker $$z1; call $$1; colormarker 0xFFFFFF, 0x663333, 11, 1, 0, $$z2; nextcolormarker 0x01, 0, $$z1; if (!result) { prevcolormarker 0x01, 0, $$z1; } } selectcolormarker $$z2; deletecolormarker $$z2; } else { call $$1; } return; GetIndent: // 指定行のインデントを取得 // ##1 = lineno call Match gettext2(0, ##1, 80, ##1, true), "^[ \\t]*"; return $$return; Match: // 正規表現検索 // $$1 = 対象文字列 // $$2 = 検索パターン // ##3 = true:大文字小文字を区別する if (##3) { ##p = dllfunc("FindRegularNoCaseSense", $$2, $$1, 0); } else { ##p = dllfunc("FindRegular", $$2, $$1, 0); } if (##p < 0) return ""; return midstr($$1, ##p, dllfunc("GetLastMatchLength")); Subst: // 正規表現置換 // $$1 = 対象文字列 // $$2 = 検索パターン // $$3 = 置換パターン // ##4 = true:大文字小文字を区別する if (##4) { return dllfuncstr("ReplaceRegularNoCaseSense", $$2, $$1, 0, $$3, 2); } else { return dllfuncstr("ReplaceRegular", $$2, $$1, 0, $$3, 2); } return; // (c) mobitan 2015