Okay, today I looked into this issue and I think have found a practicable solution to highlight DIFF files in unified format.
The problem here is that 4 different methods are needed to highlight a whole line with at least 3 different colors.
- Lines starting with --- .
- Lines starting with +++ .
- Lines starting with a single - .
- Lines starting with a single + .
The problem is that UltraEdit/UEStudio only supports 2 methods to highlight a whole line when a specified string is found in a specified area:
Line Comment = and
Line Comment Alt = with its additional specification
Line Comment Valid Columns = [...] and
Line Comment Valid Columns Alt = [...]. Both line comments have the same colors/styles.
The 2 block comment definitions can be used as 3rd and 4th line comment by defining only the
On string without an
Off string. But 3rd line comment will have the same colors/styles as the real line comments and it's not possible to limit 3rd and 4th line comment to a specified area. So they are not really helpful here.
My solution is to use marker characters to highlight lines starting with a single
- or
+. The problem with marker characters is that they highlight a text within a line only if both characters (start and end) are found on the line and the line termination characters carriage return or line-feed cannot be used. They also cannot be limited to a specified area (column).
The solution I suggest is to insert at end of every line which starts with a single
- or
+ a special but non visible character: the non breaking space with ASCII code 160 (hex A0). Now marker characters can be defined which marks everything from
- or
+ till the non breaking space. A special visible character could be used too, but that's not good for reading and printing.
Well, this means the DIFF file must be always modified before the syntax highlighting works. But this is no problem. In UE/UES a macro can be specified to be executed on every file load and a second macro on every file save.
Here is the macro which should be executed on every file save, named for example
RemoveDiffSpace:
IfExtIs "diff"
HexOff
UnixReOff
Top
Find RegExp "%^([^-+][~
nbsp^r^n]++^)
nbsp+$"
Replace All "^1"
EndIf
Note: The 2
nbsp in the regular expression are the special non breaking spaces (0xA0).
The macro deletes from files with the extension DIFF (in any case) the trailing non breaking space(s) on every line starting with a
- or
+.
And here is the macro which should be executed on every file load, named for example
AddDiffSpace:
IfExtIs "diff"
HexOff
UnixReOff
Bottom
IfColNum 1
Else
"
"
EndIf
Top
Find RegExp "%^([^-+][~
nbsp^r^n]++^)
nbsp+$"
Replace All "^1"
Find RegExp "%^([^-+]*^)$"
Replace All "^1
nbsp"
Find RegExp "%^(^{--^}^{^+^+^+^}[~
nbsp^r^n]++^)
nbsp+$"
Replace All "^1"
EndIf
Note: The 5
nbsp in the regular expressions (Find and Replace) are the special non breaking spaces (0xA0).
This macro checks first if the last line of the file is terminated because all regular expressions use $ and this works only at end of line and not at end of file. So the macro adds CRLF (or LF only or CR only depending on the file type) at end of the file if the last line is not terminated.
Next it makes the same as macro RemoveDiffSpace just for security. Then it adds a single non breaking space at end of every line starting with
- or
+. Although it would not harm the line comment highlighting the last regular expression replace removes the non breaking space from lines starting with
--- or
+++.
The macro property
Continue if a Find with Replace not found must be checked for both macros. Add UnixReOn or PerlReOn (v12+ of UE) above the EndIf macro command if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style. You can also convert the regular expressions to Unix/Perl format.
Now with an appropriate syntax highlighting definition the highlighting for DIFF files should work for every file which does not contain by itself already a non break space (0xA0) anywhere in a line with a
- or
+ before. So I think it is a 99.8% solution.
The syntax highlighting definition in the wordfile is:
/L20"Diff" DisableMLS Noquote Line Comment = --- Line Comment Valid Columns = [1] Line Comment Alt = +++ Line Comment Valid Columns Alt = [1] Block Comment On Alt = @@ Block Comment Off Alt = @@ File Extensions = DIFF
/Delimiters = + -
tab@
/Function String = "%[ ^t]++^{Index:^}^{RCS file:^}[ ^t]+^([~ ^t^r^n]+^)"
/Open Fold Strings = "Index: "
/Close Fold Strings = "Index: "
/Marker Characters = "+
nbsp-
nbsp"
/C1"New/modified line"
+
nbsp
/C2"Deleted line"
-
nbsp
/C3"Index"
Index:
/C4"Dividing line"
===================================================================
/C6"Keywords"
RCS
file:
retrieving revision
Note: The 4
nbsp are the special non breaking spaces (0xA0). The
tab is a single horizontal tab.
Use once
View - ASCII Table to insert the non breaking space into a file and then copy it to clipboard and replace the
nbsp in the 2 macros and the syntax highlighting definition with this special character.
And there are 2 normal spaces after first @@ (block on) and also before second @@ (block off). The additional spaces at block comment on and off are necessary for highlighting lines with @@ ... @@ correct as alternate block comment. Alternate block comment is used instead of normal block comment because the alternate block comment can have a different color/style setting than all other comments.
I hope this is now helpful for you.
PS: The function
Format - Trim Trailing Spaces will not working anymore as expected on the lines starting with
- or
+ because of the non breaking space added at end of those lines. If you want to trim the trailing spaces use the macro command
TrimTrailingSpaces after first regex Find+Replace in the macro
AddDiffSpace.