web404

HTMLタグを左または右方向に順次選択するマクロ

HTMLタグを左または右方向に選択します。
連続して実行すると、指定方向の次のタグを選択します。
コメントやPHPのタグも選択します。


ダウンロード

tag_lr.zip


更新履歴

Version 1.10 (2025/2/17)
マクロ名の変更
範囲選択に関する修正
未検出時の動作の修正
ソースコードの整理
過去の履歴
Version 1.02 (2024/1/8)
コメント、PHPタグに関する修正
Version 1.01 (2023/11/1)
ソースコードの整理
タグが見つからなければ警告音を出すようにした
Version 1.00 (2023/10/7)
公開

ソースコード

HTMLタグを左方向に順次選択するマクロ

setcompatiblemode 0x20200;
#x = x; #y = y;
disabledraw;

if (selecting) escape;

while (1) {
	searchup "<[a-zA-Z!/?]", regular;
	if (!result) {
		if (x != #x || y != #y) moveto #x, #y;
		beep;
		goto End;
	}
	#xr = x; #yr = y;
	$str = gettext2(column, lineno, column + 4, lineno);
	if (!strstr($str, "<!--")) searchdown "-->";
	else if (!strstr($str, "<?")) searchdown "?>";
	else searchdown "[^ <=>?-]>", regular;
	if (result) break;
}

moveto selendx, selendy;
beginsel;
moveto #xr, #yr;
endsel;

goto End;

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

HTMLタグを右方向に順次選択するマクロ

setcompatiblemode 0x20200;
#x = x; #y = y;
disabledraw;

if (selecting) escape;

left;
while (1) {
	searchdown2 "([^ <=>-]|--)>", regular;
	if (!result) {
		if (x != #x || y != #y) moveto #x, #y;
		beep;
		goto End;
	}
	#xre = selendx; #yre = selendy;
	$str = gettext(seltopx, seltopy, selendx, selendy);
	if (!strstr($str, "-->")) searchup "<!--";
	else if (!strstr($str, "?>")) searchup "<?";
	else searchup "<[a-zA-Z!/]", regular;
	if (result) break;
	moveto #xre, #yre;
}

beginsel;
moveto #xre, #yre;
endsel;

goto End;

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

演算子のような記述は検出しないようにしてあります。
タグの判定は良くも悪くもアバウトです。
判定を厳しくしすぎると、かえって使いにくくなるからです。