This script illustrates how to install a syntax coloring parser in HomeSite or to swap which parser is used for a particular file extension using a script. This can be useful as an install script to include with parser distributions or as a way to easily swap between various parsers.
Modify the script for your own application paths or your own parameters.
To easily swap between several parsers for a particular file extension, make separate scripts for each, then create toolbar buttons for each script. For example, you could swap between "HTML Full tag coloring," "ASP/VBScript" and ASP/Jscript parsers for .ASP file editing.
Note: The following technique was written up by Christian Swoboda on the HomeSite forum in the threads: Swapping Color Coding Parsers - a start ... and Scripter Looking For Ideas. Copied, edited and posted here and to the Tips library.
Here's some info about how to deal with programmatically swapping/switching color coding:
/* InstallParserScript(const wsScriptFile, wsFileExtAssoc: WideString): WordBool; Description Boolean. Returns False on error. Installs a parser (color-coding) script and associates it with the passed list of semicolon- separated file extensions. If an existing parser is assigned to any of these extensions, they are removed from the existing parser and assigned to the new one. The parser script is copied from the passed location to the application \Parsers subdirectory. Example function Main(){ with (Application){ InstallParserScript('D:\\Download\\XHTML_2.scc', 'xhtml'); } } */ function Main() { var app = Application; var aFileObj=new ActiveXObject("Scripting.FileSystemObject"); app.MessageBox(app.AppPath+"Parsers\\","",0); var Folder = aFileObj.GetFolder(app.AppPath+"Parsers\\"); app.MessageBox(Folder.Name ,"",0); // Get Files in current directory var files = new Enumerator(Folder.files); // Loop through files for(; !files.atEnd(); files.moveNext() ) { app.MessageBox(files.item().Name,"",0); } // app.InstallParserScript(app.AppPath+"Parsers\\PHP 4.scc", "php"); // app.InstallParserScript('D:\\Download\\XHTML_2.scc', 'xhtml2'); }
Credit to Christian Swoboda, e9025902@stud2.tuwien.ac.at, edited by Jeff Wilkinson
This is a feature we should have, but I'm afraid it won't be in 4.0. We will add it a later date, though.
In the meantime, there's an easier way to swap parsers. Just use the "InstallParserScript" method of HomeSite's Application object. For example, create one script that does this:
Application.InstallParserScript "c:\homesite4\parsers\asp-vbscript.scc", "htm;html;"
and another that does this:
Application.InstallParserScript "c:\homesite4\parsers\html.scc", "htm;html;"
Just change the paths to the appropriate location on your system, then create custom buttons for each script. Then you can toggle between ASP and HTML coloring in HTM/HTML documents.