Custom fold strings for brace blocks are not working as expected in *.xml files

Custom fold strings for brace blocks are not working as expected in *.xml files

1

    Aug 03, 2019#1

    I am attempting to create indentation guidelines between brackets (similar to Notepad++). I am working in JavaScript embedded in XML.
    It seems the best way to accomplish this is through folding specifically the /Open Fold Strings & /Close Fold Strings elements of syntax highlighting.

    To wrap my head around how syntax highlighting works I copied some simple code from another post and modified it but I can't seem to get to fold where I want it to.

    At one point it seemed as if something else was interfering so moved all other .uew files (backups and all) into a new folder. (Something to do with how I configured the files to be highlighted, I'll fix it later.)
    This worked and now changes that I make directly affect whatever .xml files I have open.

    Besides not folding in places I believe it should, block comments fold like there's no tomorrow. I can't see where it's specified that block comment's fold, unless it's by default.

    If anyone has an idea as to what I'm doing wrong I'd really appreciate it!

    I'm using 64 bit UltraEdit, version 26.10.0.72.

    Problems.png (13.52KiB)

    Code: Select all

    /L20"XML" Line Comment = // Block Comment On = /** Block Comment Off = **/ String Chars = '" EnableMLS File Extensions = XML
    /Delimiters = ! " %&'()*+,-./:;<=>?@[\]^{|}~
    /Function String = "%[^t ]++//[ }]++<<<+ ^(*^) >>>""
    /Indent Strings = "{"
    /Unindent Strings = "}"
    /Open Brace Strings =  "{" "(" "[" "<"
    /Close Brace Strings = "}" ")" "]" ">"
    /Open Fold Strings = "{"
    /Close Fold Strings = "}"
    /C1"Keywords"
    undefined
    var
    /C2"Operators"
    !
    $
    %
    &
    *
    +
    -
    // /
    :
    <
    =
    >
    ?
    [
    ]
    ^
    new
    |
    ~
    /C3"Separators"
    (
    )
    ,
    .
    ;
    {
    }

    6,686585
    Grand MasterGrand Master
    6,686585

      Aug 03, 2019#2

      First, you should not have two or even more *.uew files in wordfiles directory with XML specified after File Extensions = as otherwise it is unclear for UltraEdit which syntax highlighting language definition should be used for a *.xml file. It is indicated by UltraEdit in status bar at bottom which syntax highlighting is active for active file at current position of caret. This indication is of course of no help for the user if there is more than one *.uew file which UltraEdit can use for example for an XML file and in all the *.uew files the same string like XML is used as language name.

      For that reason I recommend first:
      1. Remove from first line in xml.uew after File Extensions = the file extension XML before moving the wordfile xml.uew back into wordfiles directory.
      2. Change in first line of your wordfile for *.xml files the language name from /L20"XML" for example to /L20"XML+JS"
      If there is more than one wordfile associated with file extension XML, UltraEdit syntax highlights the *.xml file by default with the language defined in the *.uew file which is first found by UltraEdit in wordfiles directory depending on file name respectively directory listing returned by the file system.

      It would have been good to attached also an example *.xml file which contains JavaScript code. It is not possible to open an image in UltraEdit for testing a syntax highlighting language definition. Your attached image shows unfortunately not what is at top and at bottom of the *.xml file. I suppose there are XML tags.

      There are built-in special syntax highlighting features for XML files. If a file contains at top <?xml, the file is syntax highlighted with the wordfile containing language marker XML_LANG even if the file has no file extension or it has a file extension not associated with any syntax highlighting definition in any *.uew file in wordfiles directory. This is does not occur on your configuration because of xml.uew was moved to another folder and your language definition contains File Extensions = XML.

      A file having the file extension XML is parsed by UltraEdit as XML file independent on file being syntax highlighted with a language definition not containing language marker XML_LANG as your wordfile. So code folding is applied on XML tags based on the internal data of XML parser. This is done here with your configuration, too. But your wordfile contains additionally an open/close fold strings definition although UltraEdit uses built-in XML parser data for code folding because of file extension XML as you can see by removing those two lines in wordfile, save the wordfile and use on XML file the command Revert to saved to force a re-parsing of active file regarding to code folding with just changed folding definition in wordfile opened in same UE instance.

      The result of code folding according to built-in XML parsing in combination with the self-defined open/close fold strings results in the unexpected code folding behavior as you see: only block comments are offered for folding as being of highest priority, but no XML tags and also no brace blocks.

      It is the first time that I see somebody using an XML file with code of another programming or scripting language embedded and who wants the code of this other language special interpreted by syntax highlighting of UltraEdit. UltraEdit supports multi-language syntax highlighting, but only for HTML files for which international standards exist to detect the beginning and end of a language block and which language this block contains. XML files are used usually for data and not for programming or scripting code. Well, it is of course possible to define a JavaScript code block as data block and handle multiple such code blocks using an XML file, but there is no international standard for that as far as I know.

      I have no idea how built-in XML folding for *.xml files should work in combination with user defined open/close fold strings. I am quite sure that you are the first UltraEdit user who tried that. I played around more than two hours, but I could not find any method to disable built-in XML parsing on file having file extension XML. There is no method according to my tests to get a self-defined folding applied on a file with file extension XML. The only possibility to get the folding on brace blocks as wanted by you is changing the file extension to something different than XML in name of highlighted file and in wordfile.
      Best regards from an UC/UE/UES for Windows user from Austria