web404

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

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

このマクロにショートカットキーを割り当てて使います。
個人的には、「Alt+Shift+←」「Alt+Shift+→」に設定しています。

ダウンロード

tag_lr.zip

更新履歴

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;

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;

while (1) {
	if (selecting) escape;
	left;
	searchdown2 "([^ <=>-]|--)>", regular;
	if (!result) {
		if (x != #x || y != #y) moveto #x, #y;
		beep;
		goto End;
	}
	#xr = selendx; #yr = 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;
}

beginsel;
moveto #xr, #yr;
endsel;

goto End;

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

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