タグジャンプ

2015年7月23日 (木) 12:09時点における113.36.79.93 (トーク)による版

いわゆるタグジャンプを行います。
相対パスでもある程度行けるかと思います。

c:\abc\def.ghi(123): ○○
..\..\abc\def.ghi(123): ○○

のような行にカーソルを合わせ実行するとそのファイルを開き、その行に移動します。


// タグジャンプ
// NYSL
 
// ファイルパスからドキュメントを開く
function FindDocument( path )
{
	path = path.toLowerCase();
	var docs  = Editor.Documents;
	var count = docs.Count;
	for( var i = 0 ; i < Editors.Count ; ++i ){
		var docs  = Editors.Item(i).Documents;
		var count = docs.Count;
		for( var j = 0 ; j < count ; ++j ){
			var doc = docs.Item(j);
			if( doc ){
				if( doc.FullName.toLowerCase() == path ){
					return	doc;
				}
			}
		}
	}
	return	null;
}
 
// カーソル行からファイルパスと行番号検索
var line = Document.GetLine( Document.selection.GetActivePointY(mePosLogical) );
var matched = line.match( /^\s*(.+)\((\d+)\):/ );
if( matched && matched.length >= 3 ){
	// 念のためフルパスに変換
	var shell = new ActiveXObject( "WScript.Shell" );
	var prev_curdir = shell.CurrentDirectory;
	shell.CurrentDirectory = Document.Path;
	var fso = new ActiveXObject( 'Scripting.FileSystemObject' );
	var path = fso.GetAbsolutePathName( matched[1] );
	shell.CurrentDirectory = prev_curdir;
 
	var doc = FindDocument( path );
	if( doc ){
		// 既に開かれてるならアクティブにする
		doc.Activate();
	}else{
		// まだ開いてないなら開く
		Editor.NewFile();
		if( Editor.EnableTab ){
			Editor.OpenFile( path );
		} else {
			Editors.Item(Editors.Count-1).OpenFile( path );
		}
		doc = FindDocument( path );
	}
	// 指定行に移動
	if( doc ){
		doc.selection.SetActivePoint( mePosLogical, 1, matched[2], false );
	}
}
スポンサーリンク