Code folding for successive line commented lines

Code folding for successive line commented lines

3
NewbieNewbie
3

    Oct 12, 2011#1

    Hi,

    I have a problem. I am using currently UltraEdit 17.20.

    I downloaded the Korn and Bash... wordfile from the website, but folding did not work as it states here. :?

    I added the open and close fold strings and the folding showed up, but the comment block still doesn't work.

    I feel that some of the wordfiles on your website are not compatible with the latest UltraEdit.

    What can I do?

    6,602548
    Grand MasterGrand Master
    6,602548

      Oct 12, 2011#2

      All wordfiles stored on server of IDM and which can be downloaded from the Downloads - Extras - Wordfiles page are user-submitted files. None of them are checked by IDM on errors or mistakes and none of them are kept up-to-date with latest enhancements in UltraEdit. Users must fix errors they find in one of the user contributed wordfiles and enhance them for using new features and then send it to IDM support by email with the request to upload it to their server replacing the existing file.

      I have created a macro set which can be downloaded also from the user-submitted wordfiles page or from topic The ultimate syntax highlighting tools to check downloaded, modified or self-created wordfiles for common mistakes regarding not correct sorted words, duplicate words in different color groups and invalid words because of containing word delimiting characters. But all other possible mistakes must be checked by the wordfile creator or modifier by himself with the help of the community by using this forum if additional help is needed.

      What you can do is read entire UltraEdit help page Syntax Highlighting very carefully, and also what is written in topic Template for syntax highlighting language wordfile and what I wrote in the HTML files packed together with the macro file in The ultimate syntax highlighting tools and then improve the wordfiles.

      Further you can pack the 2 wordfiles you use and good example files highlighted with these wordfiles into a ZIP or RAR archive and upload this file as attachment to your next post where you describe what is not working and what you would like to see. Other users like me (this is a user-to-user forum) can then help you on improving the wordfile to make use of features introduced in the last few versions of UltraEdit. But please note that I and most other users familiar with syntax highlighting don't know the syntax of Korn and Bash. So you have to explain what you would like to have without assuming that we know anything about those languages. As a general text editor UltraEdit also does not know anything about syntax of Korn or Bash and therefore syntax highlighting must be based on rules which are independent on special knowledge about syntax of these 2 languages. Or is Korn and Bash the same language?

      By the way: There are several hundreds of wordfiles on IDM server for several hundreds of different languages. Do you really expect that IDM is familiar with the syntax of all these languages and has files to evaluate the syntax highlightings of the wordfiles on these files? Not really? The wordfiles are as good as the user who contributed made it. And while a wordfile for a language works perfect for one user, the same wordfile can produce not so fine results for another user just because of using a different style. A common problem on languages which allow many variants in coding like batch and C/C++ files and others.

      3
      NewbieNewbie
      3

        Oct 19, 2011#3

        OK, that was a lot of homework :)
        So, I am using korn shell. It is not very different from bash, but this is not important.
        I read everything you pointed. I even forked the korn&bash wordfile and started my own for Korn93 which I am using (the latest version).
        I managed to get rid of some rubish from the file and added some new, like showing a function list which was not working.

        My problem stays the same: I cannot manage to instruct UE to fold a block of comment lines.
        You can check out the attachment. This is the best I could do. But it is not what I wanted.
        The problems you'll see are: first - where the variable_x is defined, the fold line should not be there.
        Second - the comments before the function should also be foldable.
        Third - seems UE acts weird if the open and close comment block strings are the same 8O

        What I concluded is that actually UE does not support the following (what I thought was possible):
        to fold comments which are on consecutive lines with no blank lines between them.
        What is your opinion?

        p.s. yes, I ran your scripts and nothing important happened - sorting and some problems with redirection operators - but this is not the case at the moment.
        And, btw, UE was updated and I am now using v17.30
        korn_shell_script.zip (1.18 KiB)   245
        Sample script with a word file for korn93

        6,602548
        Grand MasterGrand Master
        6,602548

          Oct 19, 2011#4

          Okay, now I understand the problem. If a syntax highlighting language has a Block Comment On/Off = definition in the first line, UltraEdit interprets everything between these 2 strings as a block comment. If such a block comment spans over multiple lines, UltraEdit offers automatically folding for such a block.

          But UltraEdit does not interpret a sequence of line comments as a block for folding. That would be the feature you need. Well, such a feature would make sense not only for Korn shell and Bash, it would make also sense for many other script and programming languages. I will sent a feature request email to IDM support for such an enhancement. If you do the same, the "requested by user count" would be already 2.

          The Comment Fold Strings definition are for defining special strings right of a line comment string to be interpreted as start and end of a block to fold. That can be used for example for folding following C/C++ code

          Code: Select all

          #ifdef ___GNUC__  // DEFS_BEGIN for GNU C++ Compiler
          // Lots of definitions for GNU C++ Compiler
          #endif            // DEFS_END for GNU C++ Compiler
          
          #ifdef _MSC_VER   // DEFS_BEGIN for Microsoft Visual C++ Compiler
          // Lots of definitions for Microsoft Visual C++ Compiler
          #endif            // DEFS_END for Microsoft Visual C++ Compiler
          with following definition in the wordfile

          Code: Select all

          /Open Comment Fold Strings = "DEFS_BEGIN"
          /Close Comment Fold Strings = "DEFS_END"
          The yet in UE v17.30 not available feature of interpreting a sequence of line comment lines with nothing or just spaces/tabs between start of a line and the line comment starting string on every line can be worked around by you by marking the begin and end of such a block with special strings. You can see what I mean in the modified files in the attached archive file.

          A method to quickly fold a block of line comments is to use following macro with a hotkey assigned for fast execution and stored in a macro file automatically loaded on startup of UltraEdit.

          Code: Select all

          InsertMode
          ColumnModeOff
          HexOff
          PerlReOn
          IfColNumGt 1
          GotoLine 0 1
          EndIf
          Find RegExp "^(?:#.*\r\n){2,}"
          IfFound
          HideShowSelection
          EndIf
          You can enhance the macro further or translate it to a script and enhance the script in case you want more like folding a sequence of line comment lines independent of current position within such a block.

          Some more hints in case you compare your wordfile with the modified version in the attached archive file.

          The regular expression search for function strings is always executed not case sensitive. Therefore [a-zA-Z] and [A-Z] are equal [a-z].

          Regular expression ++ means preceding character or expression 0 or more times. A character set definition like [ ] with only 1 character inside does not make much sense. In this case simple using just the space character without the square brackets is enough.

          What (^(^)) should be in the second function string is not really understandable for me. ^( and ^) are for marking what part of the found string should be displayed in the function list view. With nothing between and with the fact that there is already such a tagging group over left part of the expression, it does not make sense.

          Your highlighting problem with >& and <& in comparison to just & is caused by the fact that <, and >, and & are defined as word delimiting characters. Therefore the syntax highlighting engine reads the string >& as "word" > and as "word" & and highlight them accordingly.

          If you have always spaces around >, >&, >>, <, <&, <<, and &, you can remove <, and >, and & from the list of delimiters and specify them all in C4 and C8 to get them highlighted as formatted here.
          korn_shell_wordfile.zip (1.2 KiB)   258
          Contains the updated wordfile and modified example file.

          3
          NewbieNewbie
          3

            Oct 20, 2011#5

            You did quite an exhaustive work, I see, 10x.

            As for the macro thing, i don't think I would spend time on it. This is going too complex.

            Indeed what I expected was that UE can recognize a block of commented lines and allow me to fold them. This feature is quite useful, because I put a lot of comments on my scripts, describing usage and functionality, but when I want to edit it, I want to hide all this text and focus on coding.

            Furthermore, this is automatically working on the freely available Notepad++. You can check.
            Anyway, I will also order a request for this. It is surprising for me that UE doesn't still have it.
            Mofi wrote:The regular expression search for function strings is always executed not case sensitive. Therefore [a-zA-Z] and [A-Z] are equal [a-z].
            Well, this is very surprising for me. Then why UE Help file topic about syntax highlighting has the following line:
            /Function String = "%[ a-zA-Z]*)"
            This purely shows IDM don't update their help files accordingly. Also I saw several wordfiles having this string inside. It is misleading.

            Regarding my function string 2 - yes, I thought I was escaping the parenthesis, or was just some copy&paste mistake. I tested the regexp with UE search, and after I saw it was selecting the proper function name, I just left it.
            Anyway, in Korn you cannot have anything between ( and ), so the * inside would be wrong.
            Also I wanted to make it work not just a single space but any whitespace, but I did not make the effort to do it. I think UE regexp is just stupid. There is already a very well establishted regular expression language, even Perl and Unix variaties, why would I need to learn another one. OK, it says I can use the Perl one, but anyway, I based it all on examples.

            So, 10x for the help and let's see if IDM will decide to bring another cool feature in UE soon.

            6,602548
            Grand MasterGrand Master
            6,602548

              Oct 20, 2011#6

              About [a-zA-Z] in function strings:
              I have never reported this to IDM support and I'm quite sure that the help writer does not know that just [a-z] is the same. Using [a-zA-Z] is not really wrong. It just results in a little bit slower parsing of the regular expression string, perhaps just a few nanoseconds. Many wordfile creators also don't know that the regular expression searches are always executed not case sensitive because not documented in help.

              About usage of UltraEdit regular expression in wordfiles:

              The syntax highlighting with the function list feature is very, very old. The UltraEdit regular expression engine was the first one in UltraEdit and because of downwards compatibility most wordfiles are still using this regular expression engine although the Perl regular expression can be used too. The advantage of the UltraEdit regular expression engine is that the syntax is very simple in comparison to Perl and the engine is extremly stable because the engine and the syntax is simple.

              If you prefer Perl, you can use Perl also for the function string search. You don't need to learn UltraEdit regexp syntax if you are already familiar with Perl regexp syntax.

              If you just want to collapse all blocks of line commented lines, you could use following macro (not tested):

              Code: Select all

              InsertMode
              ColumnModeOff
              HexOff
              Top
              PerlReOn
              Loop 0
              Find RegExp "^(?:#.*\r\n){2,}"
              IfFound
              HideShowSelection
              Key DOWN ARROW
              Else
              ExitLoop
              EndIf
              EndLoop
              Top