/* * 選択行を前後(上下)に移動する秀丸マクロ * Ver.1.4 (2014-04-16) * * このマクロが実行されたときに↑キーが押されていたかどうかによって、 * 選択中の行(またはカーソル行)を上または下に移動します。 * * Yasunori Miyamoto * http://tipszone.jp/20121003_hidemaru-config/ * mailto: nori@tipszone.jp */ // 移動方向 #UP = 0x26; if (iskeydown(#UP)) ##direction = -1; else ##direction = 1; // 移動対象の先頭行と最終行 if (selecting) { ##top = seltoplineno; ##end = selendlineno; if (selendcolumn == 0) ##end = ##end - 1; } else { ##top = lineno; ##end = lineno; } disabledraw; // 移動可能か? // ファイル末尾の空行は移動不可とする。 ##movable_linecount = linecount2; call IS_LAST_LINE_EMPTY; if (##return) ##movable_linecount = ##movable_linecount - 1; if (##direction == -1 && (##top == 1 || ##movable_linecount < ##end)) endmacro; if (##direction == 1 && ##movable_linecount <= ##end) endmacro; begingroupundo; call SAVE_CURSOR; call MOVE_LINES ##top, ##end, ##direction; call RESTORE_CURSOR_EX ##direction; endgroupundo; enabledraw; endmacro; // 行を前後に移動する。 // Param: integer 移動対象開始行の lineno // Param: integer 移動対象終了行の lineno // Param: integer 移動方向。上(-1)、または、下(1) MOVE_LINES: ##top = ##1; ##end = ##2; ##direction = ##3; // 最後の行が移動されるか? ##last_line_moved = (##end == linecount2 || ##end + ##direction == linecount2); if (##last_line_moved) { // 正しく処理できるように、ファイル末尾に改行を追加する。 escape; gofileend; insert "\n"; } call SELECTLINES ##top, ##end; $$str = gettext2(seltopcolumn, seltoplineno, selendcolumn, selendlineno, 1); delete; if (##direction == -1) up; else down; insert $$str; if (##last_line_moved) { gofileend; backspace; } return; // カーソル位置と範囲選択の状態をグローバル変数 #_cursor_info に保存する。 SAVE_CURSOR: #_cursor_info[0] = selecting; #_cursor_info[1] = rectselecting; #_cursor_info[2] = selopenx; #_cursor_info[3] = selopeny; #_cursor_info[4] = x; #_cursor_info[5] = y; return; // #_cursor_info の値から、カーソル位置と範囲選択の状態を復元する。 // Param: integer 元のカーソル位置から、ここで指定した行数分ずらして復元する。 RESTORE_CURSOR_EX: ##selecting = #_cursor_info[0]; ##rectselecting = #_cursor_info[1]; ##selopenx = #_cursor_info[2]; ##selopeny = #_cursor_info[3] + ##1; ##x = #_cursor_info[4]; ##y = #_cursor_info[5] + ##1; escape; if (##selecting) { moveto ##selopenx, ##selopeny; if (##rectselecting) beginrect; else beginsel; moveto ##x, ##y; endsel; } else { moveto ##x, ##y; } return; // 指定された行を選択状態にする。 // Param: integer 選択する先頭行の lineno // Param: integer 選択する最終行の lineno SELECTLINES: moveto2 0, ##2; beginlinesel; moveto2 0, ##1; endsel; return; // 最終行が空か判定する。 // Return: bool 空であれば true そうでなければ false を返す。 IS_LAST_LINE_EMPTY: call SAVE_CURSOR; gofileend; ##result = column == 0; call RESTORE_CURSOR_EX; return ##result;