How to create a wordfile for syntax highlighting *.jsx Photoshop script files with customized code folding?

How to create a wordfile for syntax highlighting *.jsx Photoshop script files with customized code folding?

1002
Power UserPower User
1002

    Feb 09, 2018#1

    Hi!

    I'm editing many Photoshop script files. Those files have JSX extension. I have added this file extension already to javascript.uew wordfile. That's OK.

    Because I have to handle files with thousand of lines, and I need to move and copy many blocks with similar lines. I thought about customizing the code folding feature to hide/show some blocks.

    I tried to use Hide/Show Selection feature, but it would be far better if the JSX file would open with code folding already working, with [+][-] icons appearing to expand and collapse lines.

    I already checked Brace match in comments in Editor - Braces / strings because the code folding I want to do is not part of the code itself and must be inside a comment.

    I think an example would explain better.

    This is part of my file:

    Code: Select all

    // ================ Copia Layer =========================={
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
    
    // =======================================================
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
    
    // =======================================================
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
    
    // =======================================================
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
    
    // =======================================================
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
    
    // }=============== Seleciona "Cima" ====================={
    var idsetd = charIDToTypeID( "setd" );
        var desc4 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref3 = new ActionReference();
            var idChnl = charIDToTypeID( "Chnl" );
            var idfsel = charIDToTypeID( "fsel" );
            ref3.putProperty( idChnl, idfsel );
        desc4.putReference( idnull, ref3 );
        var idT = charIDToTypeID( "T   " );
            var ref4 = new ActionReference();
            var idChnl = charIDToTypeID( "Chnl" );
            ref4.putName( idChnl, "Cima" );
        desc4.putReference( idT, ref4 );
    executeAction( idsetd, desc4, DialogModes.NO );
    
    // }=============== Esconde Layer corrente ==============={
    var idHd = charIDToTypeID( "Hd  " );
        var desc5 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var list3 = new ActionList();
                var ref5 = new ActionReference();
                var idLyr = charIDToTypeID( "Lyr " );
                var idOrdn = charIDToTypeID( "Ordn" );
                var idTrgt = charIDToTypeID( "Trgt" );
                ref5.putEnumerated( idLyr, idOrdn, idTrgt );
            list3.putReference( ref5 );
        desc5.putList( idnull, list3 );
    executeAction( idHd, desc5, DialogModes.NO );
    // }
    I need to folding from line 2 to 20, because it means the same action and no need to show them.
    So, I put "{" at the final of line 1 and "}" at the beginning of file 21, both inside a comment.
    The result of this customization would be the following:

    Code: Select all

    [+]// ================ Copia Layer =========================={
    
    [+]// }=============== Seleciona "Cima" ====================={
    
    [+]// }=============== Esconde Layer corrente ==============={
    When I could customize that UEW file, I would not use javascript.uew anymore. I would have a new file and use a different name for it, like PhotoshopScript.uew to open and format JSX extension files.

    Or is there any another solution for that issue? Please let me know.

    Two and a half hours later:

    After making some tests I realized that selection folding is kept after closing UltraEdit. Because it seems to be a temporary selection/folding, I expected that those folding had gone after starting a new session. But no. All selection foldings I had made were still there. I searched uedit64u.ini file to look for that saved state, but could get no track of it.

    Anyone has the answers?

    But if I could have a customized wordfile just for this kind of situation, i.e. code folding across comment lines as previous described, it would be great.

    Five minutes later:

    Looking more carefully, now I see where such settings are stored: [Hidden Lines] entry of uedit64u.ini file.

    Six and a quarter hours later:

    Playing a little more with that code, I realized that the closing brace would be a line before, like this:

    Code: Select all

    // ================ Copia Layer =========================={
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
    
    // =======================================================
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
    
    // =======================================================
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
    
    // =======================================================
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
    
    // =======================================================
    var idCpTL = charIDToTypeID( "CpTL" );
    executeAction( idCpTL, undefined, DialogModes.NO );
    // }
    // ================ Seleciona "Cima" ====================={
    var idsetd = charIDToTypeID( "setd" );
        var desc4 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref3 = new ActionReference();
            var idChnl = charIDToTypeID( "Chnl" );
            var idfsel = charIDToTypeID( "fsel" );
            ref3.putProperty( idChnl, idfsel );
        desc4.putReference( idnull, ref3 );
        var idT = charIDToTypeID( "T   " );
            var ref4 = new ActionReference();
            var idChnl = charIDToTypeID( "Chnl" );
            ref4.putName( idChnl, "Cima" );
        desc4.putReference( idT, ref4 );
    executeAction( idsetd, desc4, DialogModes.NO );
    // }
    // ================ Esconde Layer corrente ==============={
    var idHd = charIDToTypeID( "Hd  " );
        var desc5 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var list3 = new ActionList();
                var ref5 = new ActionReference();
                var idLyr = charIDToTypeID( "Lyr " );
                var idOrdn = charIDToTypeID( "Ordn" );
                var idTrgt = charIDToTypeID( "Trgt" );
                ref5.putEnumerated( idLyr, idOrdn, idTrgt );
            list3.putReference( ref5 );
        desc5.putList( idnull, list3 );
    executeAction( idHd, desc5, DialogModes.NO );
    // }
    This way, I can use CTRL-B to select to matching brace and CTRL-Subtract to hide/show selection.

    And the result is:

    Code: Select all

    [+]// ================ Copia Layer =========================={
    [+]// ================ Seleciona "Cima" ====================={
    [+]// ================ Esconde Layer corrente ==============={
    But I'm still trying to find a way to have a wordfile to show indents and code folding automatically, without selection action, based only on "{" and "}" characters to open and close blocks.

    It's not mandatory that open and close characters are "{" and "}".

    It would be anything else like "$" and "&", or "!" and "#", or even "[" and "]" also possible if they don't conflict with reserved ones.

    6,675585
    Grand MasterGrand Master
    6,675585

      Feb 10, 2018#2

      First, I recommend for the future not opening uedit64u.ini and try to edit settings directly in INI file. With the exception of some very special expert settings, everything stored in this file can be easily modified from within UltraEdit via a configuration dialog or a context menu option. For example open Advanced - Settings or Configuration - Editor display - Code folding which has the configuration setting Save folded lines which you was searching for. The configuration dialog has at top also a search field. And each configuration dialog has a button Help to open the help page for this configuration dialog explaining the settings in this dialog.

      Second, copy the file %ProgramFiles%\IDM Computer Solutions\UltraEdit\wordfiles\javascript.uew to folder %APPDATA%\IDMComp\UltraEdit\wordfiles and replace javascript.uew to restore this file to original content.

      Third, open a new ANSI encoded file with DOS line endings (see status bar at bottom) and copy and paste into this file the following lines:

      Code: Select all

      /L20"JSX" Line Comment = // Block Comment On = /* Block Comment Off = */ Escape Char = \ String Chars = '" DisableMLS File Extensions = JSX
      /Delimiters = ! " %&'()*+,-./:;<=>?@[\]^{|}~
      /Function String = "%[^t ]++//[ }]++===+ ^(*^) ===+{"
      /Indent Strings = "{"
      /Unindent Strings = "}"
      /Open Brace Strings =  "{" "(" "[" "<"
      /Close Brace Strings = "}" ")" "]" ">"
      /Open Fold Strings = "{"
      /Close Fold Strings = "}"
      /Open Comment Fold Strings = "==={"
      /Close Comment Fold Strings = "}"
      /C1"Keywords"
      undefined
      var
      /C2"Operators"
      !
      $
      %
      &
      *
      +
      -
      // /
      :
      <
      =
      >
      ?
      [
      ]
      ^
      new
      |
      ~
      /C3"Separators"
      (
      )
      ,
      .
      ;
      {
      }
      
      Note: There should be a horizontal tab character instead of the space between " and % in second line. So please replace this space by a tab after pasting the text into the file. Your browser display the tab character in the code block above with 1 or more spaces according to HTML standard.

      Save this file for example with name jsx.uew or PhotoshopScript.uew into folder %APPDATA%\IDMComp\UltraEdit\wordfiles.

      The language name after /L20 in double quotes can be also Photoshop Script instead of JSX if you like that more. But please note that the language selector in status bar at bottom of UltraEdit main window has a limited width. So the language name should not be too long.

      Then restart UltraEdit to make sure that UltraEdit recognizes this new wordfile. A restart of UltraEdit is not necessary on making modifications on a *.uew file in configured wordfiles directory opened in same instance of UltraEdit in which also a file is syntax highlighted by the wordfile existing already on startup of UltraEdit. After each save the changes are applied to syntax highlighted file. For same features like code folding and function list it is necessary to retrigger scanning the already opened and syntax highlighted file. I use for this always the command Revert to Saved executed by hotkey which I assigned to this command.

      See for example the post How to change color or font style for a syntax highlighting language color group? with instructions on how to customize the colors and font styles for syntax highlighting language JSX (or Photoshop Script) after restart of UltraEdit.

      Fourth, open Advanced - Settings or Configuration - Editor display - Syntax highlighting and click on button Help. The opened help page explains the wordfile posted by me. Close the configuration dialog with button Cancel. Additional information about UltraEdit syntax highlighting can be found in forum post Template for syntax highlighting language wordfile.

      I don't know anything about syntax of Photoshop script files. So the wordfile posted by me is based on what you wrote above and your example.

      The UltraEdit regular expression /Function String finds text in line comment lines between at least three equal signs on left side and on right side and list them in Function List view. Then you can easily jump to the appropriate block and on moving caret in file you see in Function List in which block the caret is currently positioned. I used old style function string definition using UltraEdit regular expression engine for maximum compatibility with older versions of UltraEdit in case of other users of UltraEdit using such an older version are interested in this wordfile for Photoshop scripts too.

      There are the two lines:

      Code: Select all

      /Open Comment Fold Strings = "==={"
      /Close Comment Fold Strings = "}"
      Those two lines results for your example in the code folding you would like to have.
      Best regards from an UC/UE/UES for Windows user from Austria

      1002
      Power UserPower User
      1002

        Feb 10, 2018#3

        Mofi wrote:First, I recommend for the future not opening uedit64u.ini and try to edit settings directly in INI file. With the exception of some very special expert settings, everything stored in this file can be easily modified from within UltraEdit via a configuration dialog or a context menu option. For example open Advanced - Settings or Configuration - Editor display - Code folding which has the configuration setting Save folded lines which you was searching for. The configuration dialog has at top also a search field. And each configuration dialog has a button Help to open the help page for this configuration dialog explaining the settings in this dialog.
        Copy that.
        Yes, I didn't see Save folded lines, the same I was searching for inside ini file...😐

        Mofi wrote:Second, copy the file %ProgramFiles%\IDM Computer Solutions\UltraEdit\wordfiles\javascript.uew to folder %APPDATA%\IDMComp\UltraEdit\wordfiles and replace javascript.uew to restore this file to original content.
        Done.

        Mofi wrote:Third, open a new ANSI encoded file with DOS line endings (see status bar at bottom) and copy and paste into this file the following lines:
        Perfect! Very good job!
        You do master all kind of wordfile files.
        Congrats.

        Mofi wrote:The language name after /L20 in double quotes can be also Photoshop Script instead of JSX if you like that more. But please note that the language selector in status bar at bottom of UltraEdit main window has a limited width. So the language name should not be too long.
        PhotoshopScript name fit well at that width.

        Mofi wrote:Then restart UltraEdit to make sure that UltraEdit recognizes this new wordfile.
        All things running very well here. 🙂

        Mofi wrote:Fourth, open Advanced - Settings or Configuration - Editor display - Syntax highlighting and click on button Help. The opened help page explains the wordfile posted by me.
        I have to book some time later to study hardly such things.

        Mofi wrote:I don't know anything about syntax of Photoshop script files. So the wordfile posted by me is based on what you wrote above and your example.
        Your wordfile is perfect!

        Mofi wrote:The UltraEdit regular expression /Function String finds text in line comment lines between at least three equal signs on left side and on right side and list them in Function List view. Then you can easily jump to the appropriate block and on moving caret in file you see in Function List in which block the caret is currently positioned. I used old style function string definition using UltraEdit regular expression engine for maximum compatibility with older versions of UltraEdit in case of other users of UltraEdit using such an older version are interested in this wordfile for Photoshop scripts too.
        I never used that Function List view.
        Now I see how it is useful!
        Here is a capture of Function List and Find String List:

        FunctionListView.png (156.66KiB)

        You said I can easily jump to the appropriate block and on moving caret in file, but I didn't see how to select the whole block, like I use to do when working with Select the Matching Brace.
        Am I missing something?

        Mofi wrote:There are the two lines:

        Code: Select all

        /Open Comment Fold Strings = "==={"
        /Close Comment Fold Strings = "}"
        Those two lines results for your example in the code folding you would like to have.
        I don't understand those lines.
        They are already present in wordfile.

        6,675585
        Grand MasterGrand Master
        6,675585

          Feb 10, 2018#4

          /Open Fold Strings = "{" and /Close Fold Strings = "}" define the open/close fold strings outside of line or block comments.

          /Open Comment Fold Strings = "==={" and /Close Comment Fold Strings = "}"  define the open/close fold strings inside of line or block comments, i.e. right of // and between /* and */. Those two lines are what you were searching for. You can use just { instead of ==={ too.

          The Find String List has nothing to do with syntax highlighting. This list is filled with lines on running on active file a regular Find with advanced option List lines containing string checked (gearwheel button in Find window).
          Best regards from an UC/UE/UES for Windows user from Austria

          1002
          Power UserPower User
          1002

            Feb 10, 2018#5

            Mofi wrote:/Open Fold Strings = "{" and /Close Fold Strings = "}" define the open/close fold strings outside of line or block comments.
            /Open Comment Fold Strings = "==={" and /Close Comment Fold Strings = "}"  define the open/close fold strings inside of line or block comments, i.e. right of // and between /* and */. Those two lines are what you were searching for. You can use just { instead of ==={ too.
            It's very clear now.

            Mofi, once again, thank you very much for your valuable help and guidance.
            I'm editing and handling huge script files, some with almost 10,000 lines, resulting from automatic macros.
            With this wordfile, my work will become less painful.

            Many thanks!

            6,675585
            Grand MasterGrand Master
            6,675585

              Feb 10, 2018#6

              You can double click on a line in Function List to set caret to start of the line on which the displayed string was found.

              UltraEdit selects in Function List always the line according to position of caret in document window. So when moving the caret in document window for example with the keys PgUp (page up) and PgDn (page down) resulting in leaving a certain block and being now in a different block, you can see on Function List in which block you are currently.

              The Function List is not for selecting a block (= function) in file although that seems to be a good idea for an enhancement.

              Right click into the Function List view to open its context menu with additional options. It could be useful for you to enable Flat List and Sort List.

              And remove the space character after ^) in the regular expression search string for the function list as otherwise the string Seleciona 8 Copy with no space before === is not found by this regular expression or insert a space on this comment line.
              Best regards from an UC/UE/UES for Windows user from Austria

              1002
              Power UserPower User
              1002

                Feb 10, 2018#7

                Mofi wrote:UltraEdit selects in Function List always the line according to position of caret in document window. So when moving the caret in document window for example with the keys PgUp (page up) and PgDn (page down) resulting in leaving a certain block and being now in a different block, you can see on Function List in which block you are currently.
                Excellent!
                Not only the wordfile was the very nice thing happening for today, Function List is the gold nugget I could find among the vast mining area UltraEdit is.
                Everyday learning something new and useful.

                Mofi wrote:And remove the space character after ^) in the regular expression search string for the function list as otherwise the string Seleciona 8 Copy with no space before === is not found by this regular expression or insert a space on this comment line.
                Done.

                Thread fully solved. Thanks. 👏