The problem with
ReIndent Selection command and the definition of the indent and unindent strings is the different styles available for conditions/loops (
if,
for,
while) with only one statement.
Code: Select all
if(iValue == 2) return 0;
else return 1;
if(iValue == 2)
return 0;
else
return 1;
if(iValue == 2)
{
return 0;
}
else
{
return 1;
}
if(iValue == 2)
{
return 0;
}
else
{
return 1;
}
if(iValue == 2) {
return 0;
}
else {
return 1;
}
if(iValue == 2) {
return 0;
} else {
return 1;
}
if(iValue == 2) {
return 0; }
else {
return 1; }
if(iValue == 2)
{
return 0; }
else {
return 1; }
Yes, it is nearly unbelievable how humans make simple things really complicated.
And there are also mixtures of those styles with using
{ and
} for blocks with more than 1 statement and omitting the braces on a single statement.
If not using consequently the same style in the C/C++/C#/JavaScript and other language files with similar coding syntax, it is impossible to use the simple
ReIndent Selection command. In such cases a tool like Artistic Style is necessary which has true language intellisense and does really analyze the content of the file for reformatting it.
I'm using only first and third style from the example code. This makes it possible to use
Code: Select all
/Indent Strings = "{"
/Unindent Strings = "}"
I used for UltraEdit scripts very long time the fifth style as this is what JavaScript developers usually use as it saves bytes. But in the meantime I switched for the scripts also to the style I use in C/C++ files as I found out that this is the best style also for my UltraEdit scripts with JavaScript code. I write very often comments at beginning of a block below
if,
for,
while and I usually want a blank line between the condition/loop and the comment line for better readability. If this blank line is really completely empty or contains the opening
{ does not really matter in UltraEdit scripts where it is not necessary to save bytes as in JavaScript files or HTML files which must be downloaded by users. With
{ in same column as matching
} it is much easier to see where a block begins and where it ends and if the structure is correct.
Artistic Style support was improved with UE v20.00 by installing together with UE v20.00 version 2.03 of Artistic Style and updating the Artistic Style Formatter dialog to support all the options of this version of the tool. But I must add that the support for all the options of Artistic Style v2.03 was not done optimal by IDM as I found out during reading very, very carefully the documentation and revising the help page
Artistic Style Formatter dialog. The space padding options controlling formatting around parentheses would have been better offered separately as check box options or in a multi-select list as it should be possible to combine them to get the wanted formatting.
In the meantime the developers group of Artistic Style released v2.04 with some more new options and new features. This latest version of Artistic Style can be used from within UE v20.00 / UES v14.00 only by replacing file astyle.exe in subdirectory GNU of the program files directory of UE / UES and using a manually created options file specified in the Artistic Style Formatter dialog. Using a manually created options file for astyle.exe is currently also the only possibility combining the parentheses options.
Note: Help page
Artistic Style Formatter dialog within uedit32.chm was greatly improved in updated help installed with UE v20.00.0.1054 by coloring the characters which indicate the changes made on using an option. This helps to understand the differences between the available options controlling the formatting.
Update:
Artistic Style v2.04 is installed with UltraEdit v21.00.0.1027. The new features of this version in comparison to v2.03 are not supported via the dialog and can be used therefore only with using an options file. But the space padding options are now check box options which make it possible to enable multiple padding options to get the wanted format. Further with pressing button
Cancel now all modifications on the Artistic Style options made since opening the dialog are discarded which was not the case in all previous versions of UltraEdit. And finally for those interested in how UltraEdit will call astyle.exe according to currently selected and enabled options in the dialog, there is a box at bottom displaying the command line options according to the settings in the dialog.