「タグジャンプ」の版間の差分

提供: MeryWiki
ナビゲーションに移動 検索に移動
編集の要約なし
MSY-07 (トーク | 投稿記録)
SyntaxHighlightにcopyの追加
 
(2人の利用者による、間の4版が非表示)
1行目: 1行目:
いわゆるタグジャンプを行います。
いわゆるタグジャンプを行います。
相対パスでもある程度行けるかと思います。


c:\abc\def.ghi(123): ○○
ジャンプ元文書が保存済みであれば、相対パスであっても移動できるかと思います。
 
c:\abc\def.ghi(123): ○○<br>
..\..\abc\def.ghi(123): ○○
..\..\abc\def.ghi(123): ○○


のような行にカーソルを合わせ実行するとそのファイルを開き、その行に移動します。
のような行にカーソルを合わせ実行すると、そのファイルを開きカッコ内で指定された行に移動します。
 


<source lang="javascript">
<syntaxhighlight lang="javascript" copy>
// タグジャンプ
// タグジャンプ
// NYSL
// NYSL
 
// ファイルパスからドキュメントを開く
// ファイルパスからドキュメントを開く
function FindDocument( path )
function FindDocument( path )
{
{
path = path.toLowerCase();
path = path.toUpperCase();
var docs  = Editor.Documents;
var docs  = Editor.Documents;
var count = docs.Count;
var count = docs.Count;
24行目: 24行目:
var doc = docs.Item(j);
var doc = docs.Item(j);
if( doc ){
if( doc ){
if( doc.FullName.toLowerCase() == path ){
if( doc.FullName.toUpperCase() == path ){
return doc;
return doc;
}
}
32行目: 32行目:
return null;
return null;
}
}
 
// カーソル行からファイルパスと行番号検索
// カーソル行からファイルパスと行番号検索
var line = Document.GetLine( Document.selection.GetActivePointY(mePosLogical) );
var line = Document.GetLine( Document.selection.GetActivePointY(mePosLogical) );
var matched = line.match( /^\s*(.+)\((\d+)\):/ );
var matched = line.match( /^\s*(.+)\((\d+)\):/ );
if( matched && matched.length >= 3 ){
if( matched && matched.length >= 3 ){
// 念のためフルパスに変換
var path = matched[1];
var shell = new ActiveXObject( "WScript.Shell" );
var fso  = new ActiveXObject( 'Scripting.FileSystemObject' );
var prev_curdir = shell.CurrentDirectory;
 
shell.CurrentDirectory = Document.Path;
// フルパスへ変換
var fso = new ActiveXObject( 'Scripting.FileSystemObject' );
var dir = Document.Path;
var path = fso.GetAbsolutePathName( matched[1] );
if( dir && dir.length > 0 ){
shell.CurrentDirectory = prev_curdir;
var shell = new ActiveXObject( "WScript.Shell" );
var prev  = shell.CurrentDirectory;
shell.CurrentDirectory = dir;
path = fso.GetAbsolutePathName( path );
shell.CurrentDirectory = prev;
}
   
   
var doc = FindDocument( path );
var doc = FindDocument( path );
49行目: 54行目:
// 既に開かれてるならアクティブにする
// 既に開かれてるならアクティブにする
doc.Activate();
doc.Activate();
}else{
}else if( fso.FileExists( path ) ){
// まだ開いてないなら開く
// まだ開いてないなら開く
Editor.NewFile();
Editor.NewFile();
64行目: 69行目:
}
}
}
}
</source>
</syntaxhighlight>

2025年6月30日 (月) 00:21時点における最新版

いわゆるタグジャンプを行います。

ジャンプ元文書が保存済みであれば、相対パスであっても移動できるかと思います。

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

のような行にカーソルを合わせ実行すると、そのファイルを開きカッコ内で指定された行に移動します。

// タグジャンプ
// NYSL

// ファイルパスからドキュメントを開く
function FindDocument( path )
{
	path = path.toUpperCase();
	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.toUpperCase() == 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 path = matched[1];
	var fso  = new ActiveXObject( 'Scripting.FileSystemObject' );

	// フルパスへ変換
	var dir = Document.Path;
	if( dir && dir.length > 0 ){
		var shell = new ActiveXObject( "WScript.Shell" );
		var prev  = shell.CurrentDirectory;
		shell.CurrentDirectory = dir;
		path = fso.GetAbsolutePathName( path );
		shell.CurrentDirectory = prev;
	}
 
	var doc = FindDocument( path );
	if( doc ){
		// 既に開かれてるならアクティブにする
		doc.Activate();
	}else if( fso.FileExists( path ) ){
		// まだ開いてないなら開く
		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 );
	}
}
スポンサーリンク