EmEditor (text editor) Forum Index
   Macro Samples
     Open corresponding file -- C/C++<->H
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
shaohao
Posted on: 3/21/2008 10:02 am
Not too shy to talk
Joined: 11/12/2006
From:
Posts: 21
Open corresponding file -- C/C++<->H
This Macro is useful when you are writing C/C++ code with EmEditor. It will switch between .h and .c/.cpp files.


#title = ""
#tooltip = "C/C++<->H"

fso = new ActiveXObject( "Scripting.FileSystemObject");

// get file full name
fn = document.FullName;

// get base name and extension
base = fso.GetParentFolderName(fn) + "\\" + fso.GetBaseName(fn);
ext = fso.GetExtensionName( fn);
if ( ext == "") Quit();

// get file name to be opened
if ( ext.toLowerCase() == "h") {
	fn = base + ".cpp";
	if ( ! fso.FileExists( fn)) fn = base + "c";
} else if ( ext.toLowerCase() == "c" || ext.toLowerCase() == "cpp") {
	fn = base + ".h";
} else {
	Quit(); // unsupported
}

// open the file
if ( fso.FileExists( fn)) editor.OpenFile( fn, 0, eeOpenAllowNewWindow);
Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文