User to user discussion and support for UltraEdit, UEStudio, UltraCompare, and other IDM applications.

Help with writing and running scripts
6 posts Page 1 of 1
I've written a script for commenting out multiple lines of code at a time. It detects what language you are using from the file extension, and then adds a comment symbol at the start of each selected line. If the selected lines are already commented out then they are uncommented, so it lets you toggle comments on/off as needed. Languages supported include Java, JavaScript, PHP, C-Sharp, Perl, Ruby, UNIX Shell, and VB. It can also comment out sections of an XML/HTML document.

It is a bit long to post here, but you can download it from http://codebox.org.uk/pages/ultraedit-scripts/block-comments
Does this do something that the built-in Comment Add and Comment Remove commands don't?
Well I never knew about that feature, just found it now. Thanks for the heads-up. Luckily, the answer is yes! The script copes better with commented lines that don't have the comment character/s at the very start of the line. It will remove comments even if the comment is preceded by whitespace. It also works for blocks of HTML/XML which I don't think the built-in feature does. Also, since it's open-source and (I hope) fairly clearly written you can add in your own commenting code to process things differently if you want. If none of those advantages are important to you then I say just use the native feature, since its probably more robust than mine.

Rob
Thanks for the script! Great to see contributions for UE community benefit!
Hey Rob, I tried the script but I couldn't get it to work. Is it working for anyone else?
The script works still fine. I saved the script code into a new ANSI file saved as CommentAddRemove.js and added this file to Script list.

Then I opened a *.html file, selected a block not containing an HTML block comment and executed the script with a double click on it in Script list. The selected block was embedded after script execution within <!-- and -->. I reselected the commented block and executed the script once again and <!-- and --> were removed by the script.

Next I opened a *.js file, selected a block containing already some lines with // after preceding spaces and executed the script. The line comment starting // were removed on all lines in selection. I reselected the block, executed the script once again and all lines started with // as expected.

The HTML and the JavaScript file were both ANSI encoded files.

However, the built-in commands Comment Add and Comment Remove for adding/removing line comments working in the meantime also when there are preceding whitespaces and Comment Selection and Uncomment Selection for adding/removing a block comment do the same as the script based on line/block comments defined in syntax highlighting language used for active file respectively active section in file (HTML with other languages like CSS, PHP, JavaScript, etc. embedded).
Best regards from Austria
6 posts Page 1 of 1