<http://forum.pspad.com/read.php?f=2&i=12134&t=12082>
----------------------------------------------------------------
I make it a workable script by combining Ricky's code together. I am a
Fortran/C/Matlab guy, know nothing about jscript. but Rick's code is very
easy to follow. I wrote Fortran part by adding an extra "else if". The
technique Ricky used to comment xml file is nice and neat.
The script can comment, but not uncomment. (Ctrl+Shift+A) is much more
convenient in this case. The key combination (Ctrl+Shift+M) does not work
and I could not find the KeyMap.ini file under pspad directory.
Save the file under PSPad/script/Jscript, SetComment.js for example.
Restart pspad or PSPad menu/scripts/compile scripts.
Usage: 1)Select lines 2) Menu/Scripts/add comments
--------------------------------------
function getFileExtension( aFileName)
{
if ( aFileName == "") return "";
var name = aFileName.substr( aFileName.lastIndexOf( "\\"));
if ( name == "") return "";
var tab = name.split( ".");
return tab[ tab.length - 1].toLowerCase();
}
function curEditor()
{
var obj1 = newEditor();
obj1.assignActiveEditor();
return obj1;
}
function commentSelText()
{
var ed = curEditor();// hand made function to insert in your script
var ext = getFileExtension( ed.FileName()); // hand made function to
insert in your script
var selText = ed.selText();
if ( selText == "") {
if ( ext == "js") {
ed.CaretX( 1);
ed.lineText( "//" + ed.lineText());
} else if ( ext == "xml" || ext == "xsl") {
ed.CaretX( 1);
ed.lineText( "<!-- " + ed.lineText() + " -->");
} else if ( ext == "f" || ext == "f90" || ext == "for") {
ed.CaretX( 1);
ed.lineText( "! " + ed.lineText());
}
} else {
selLines = selText.split( "\n");
selText = "";
if ( ext == "js") {
for ( i=0; i<selLines.length; i++)
if ( selLines[ i] != "") selText = selText + "//" + selLines[
i];
ed.selText( selText);
} else if ( ext == "xml" || ext == "xsl") {
selText = "<!-- \n";
for ( i=0; i<selLines.length; i++)
if ( selLines[ i] != "") selText = selText + selLines[ i];
ed.selText( selText + "\n -->\n");
}else if (ext == "f" || ext == "f90" || ext=="for"){
for ( i=0; i<selLines.length; i++)
if ( selLines[ i] != "") selText = selText + "!" + selLines[ i];
ed.selText( selText);
}
}
}
function Init()
{
addMenuItem( "add comments", "", "commentSelText", "CTRL+ALT+M");
}
--
PSPad freeware editor http://www.pspad.com