web404

単語を左または右方向に順次選択するマクロ

単語を左または右方向に選択します。
連続して実行すると、指定方向の次の単語を選択します。
記号や改行は飛ばして、単語のみを選択します。

全角文字でも使えますが、半角英数字のほうがより効果的です。
サルネン風単語範囲選択マクロと相性がいいです。


ダウンロード

word_lr.zip


更新履歴

Version 1.10 (2025/2/14)
マクロ名の変更
範囲選択に関する修正
サブルーチンの修正
ファイル先頭・末尾の処理の修正
対象が見つからなければ警告音で終了するようにした
ソースコードの整理
過去の履歴
Version 1.00 (2023/8/28)
公開

ソースコード

単語を左方向に順次選択するマクロ

#x = x; #y = y;
disabledraw;

if (selecting) escape;

if (!(x + y)) {	//ファイル先頭なら終了
	beep;
	goto End;
}

call MoveLeft;

while (code == 13) call MoveLeft;	//論理行末の処理

wordrightsalnen2;
beginsel;
wordleft2;
endsel;

goto End;

MoveLeft:	//単語の左に移動
	wordleft2;
	if ((!(x + y)) && (code == 9 || code == 13 || (code >= 32 && code <= 47)
	 || (code >= 58 && code <= 64) || (code >= 91 && code <= 94)
	 || (code >= 123 && code <= 126))) {	//ファイル先頭の処理
		moveto #x, #y;
		beep;
		goto End;
	}
	return;

End:	//終了処理
	enabledraw;
	endmacro;

単語を右方向に順次選択するマクロ

#x = x; #y = y;
disabledraw;

if (selecting) escape;

if (code == -1) {	//ファイル末尾なら終了
	beep;
	goto End;
}

call MoveRight;
if (column && code == 13) {	//論理行末の処理
	#col = column;
	wordleft2;
	wordrightsalnen2;
	if (column < #col) {
		golineend2;
		wordrightsalnen2;
	}
}
wordleft2;

if ((!(x + y)) && (code == 9 || (code >= 32 && code <= 47)
 || (code >= 58 && code <= 64) || (code >= 91 && code <= 94)
 || (code >= 123 && code <= 126))) wordright2;	//ファイル先頭の処理

while (code == 13) {	//論理行末の処理
	wordright2;
	call MoveRight;
	wordleft2;
}

beginsel;
wordrightsalnen2;
endsel;

goto End;

MoveRight:	//単語の右に移動
	#col = column; #ln = lineno;
	wordrightsalnen2;
	if (code == -1) {	//ファイル末尾の処理
		wordleft2;
		if (code == 13 || (column < #col && lineno == #ln)) {
			moveto #x, #y;
			beep;
			goto End;
		}
		wordright2;
	}
	return;

End:	//終了処理
	enabledraw;
	endmacro;

目的とする機能は単純なんですが、左方向と右方向でソースコードはかなり違います。
改行周辺の処理が異なるためです。