Suggestion for Diff wordfile

Suggestion for Diff wordfile

2
NewbieNewbie
2

    Sep 19, 2006#1

    Hello,

    For a quite a while I'm searching for a "wordfile" file for syntax highlighting for files which are into "diff" format. These files are generated into two ways :
    - from "diff" UNIX utility, which compares files and directories
    - and from "cvs diff" command, which compares different version for files

    Everyone ( I believe ) which was worked with this things is using "vim" editor to view these files, because it has perfect syntax highlighting for this purpose. So I try to make such file and for UltraEdit format.

    Here is my initial version, which is not perfect.

    6,683583
    Grand MasterGrand Master
    6,683583

      Sep 19, 2006#2

      Well, never have seen a DIFF file. A colored example and a PNG screenshot from vim would be helpful. However, your syntax highlighting definition contains some general errors.

      1) DIFF_LANG is an unknown keyword for UE/UES - delete it. Known language markers are listed in syntax.txt in the program directory of UE/UES or on the help page about Syntax Highlighting.

      2) The "/Delimiters =" line should contain the delimiter characters. Suggest at least space, tab, the string chars -+ and the comment chars ?@.

      3) The function strings can't really work because only the first one has the name "/Function String =". The second one must have "/Function String 1 =" and the 3rd one "/Function String 2 =". And do function string 2 and 3 not match the same? I suggest following single function string instead of the 3 regex you posted: /Function String = "%[ ^t]++^{Index:^}^{RCS file:^}[ ^t]+^([~ ^t^r^n]+^)"

      4) Member and Variable Strings are for Intellitips of UEStudio and not useful here. Delete these lines.

      5) No marker strings - delete line.

      6) No brace strings - delete lines.

      7) The names of the color groups are awful and the style keywords are not really needed here too (IntelliTips).

      8) Is highlighting the words +++ and --- with color /C1 and /C2 really working when the -+ characters are also delimiters for strings?

      9) The words in /C6 are not correct sorted - case-sensitive line sort.

      By the way: Edit - Insert Color is really helpful to get the standard names for standard colors:

      rgb(128,128,128) = Gray
      rgb(0,128,128) = Teal
      rgb(255,128,0) = similar to Orange
      rgb(255,128,192) = similar to Pink


      My suggestion without possibility to test it on a real DIFF file:

      /L12"Diff" DisableMLS Line Comment = diff Line Comment Alt = ? Block Comment On = @@ Block Comment Off = @@ String Chars = -+ File Extensions = DIFF
      /Delimiters = + -tab?@
      /Function String = "%[ ^t]++^{Index:^}^{RCS file:^}[ ^t]+^([~ ^t^r^n]+^)"
      /Open Fold Strings = "Index: "
      /Close Fold Strings = "Index: "
      /C1"New line"
      +++
      /C2"Deleted line"
      ---
      /C3"Index"
      Index:
      /C4"Dividing line"
      ===================================================================
      /C6"Keywords"
      RCS
      file:
      retrieving revision


      tab is a place holder for a horizontal tab because in HTML tabs are displayed as single space.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Sep 19, 2006#3

        Ok, let's first explain some special features for diff files :

        1. Whole lines are highlighting with color not some keywords
        2. Color for each line was define from its first symbol : "+" or "-"

        To understand me correct here are two files :

        =======first.txt=======
        First Line Is Here

        Second Line Is Here

        Third Line Is Here
        =======first.txt=======

        =======second.txt=======
        First Line Was Gone

        Second Line Is Here
        Third Line
        =======second.txt=======

        From these two files "diff" UNIX utility make such file :

        =======files.diff=======
        --- first.txt Tue Sep 19 19:52:06 2006
        +++ second.txt Tue Sep 19 19:53:49 2006
        @@ -1,5 +1,4 @@
        -First Line Is Here
        +First Line Was Gone

        Second Line Is Here
        -
        -Third Line Is Here
        \ No newline at end of file
        +Third Line
        =======files.diff=======

        This file I want to open from UltraEdit and to be highlighted with proper colors.

        Screenshot:


        In one word : diff file show the changes between two files :
        - lines starting with "+" are new lines which are added or modified
        - lines starting with "-" are old lines which are deleted
        - lines starting and ending with "@@" contains info for each difference
        - at the top of this file contains info for compared files

        More information you can view here : Wikipedia - Diff

        I do not know if UltraEdit supports highlighting of whole lines, therefore my wordfile is incorrect , because I want to use "backdoor" features to reach the desired effect.

        So, I'm sorry for my "stupid" errors. Thank you for your support. Do you believe UltraEdit development team would implement such feature for diff files?

        Andrei

        6,683583
        Grand MasterGrand Master
        6,683583

          Sep 24, 2006#4

          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.
          1. Lines starting with --- .
          2. Lines starting with +++ .
          3. Lines starting with a single - .
          4. 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 "^1nbsp"
          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.
          Best regards from an UC/UE/UES for Windows user from Austria