Folding only after carriage return or when first character

Folding only after carriage return or when first character

1
NewbieNewbie
1

    Mar 10, 2006#1

    In my wordfile.txt I have the two following lines

    Code: Select all

    /Open Fold Strings = "Sub"
    /Close Fold Strings = "/return"
    Is there a way to make it so that /return is only picked up when follows a carriage return (it's in the first character position) and / or when it's the first logical character (first character following any number of spaces and / or tabs)

    Code: Select all

    Sub MySubName
       /if (A > B) /return
       /if (A < B) {
          /echo whatever
          /beep
       }
    /return
    In this case, "Sub" is my Open fold string and "/return" is my close fold string. In the example above, it assumes that the /return in the second line is the close, not the last line. is there a way that I can tell it "<carriage return>/return" or something of the sort. Is there a special character / escape charatcter that represents a <cr> that I can use in my search criteria?

    there will also be times where, say the above text was imbedded in an IF statement. the /return (at the bottom of the code shown above) would not be in the first character position but it would be the first logical text on the line (characters not counting spaces and or tabs) following the last carrage return. I'd still like it to catch this.

    Same thing would be useful because the language I'm writing in uses the "|" character to declare a comment line if it's at the first character of the line. The "|" character is also used in operators. I would like UE to know that | is the beginning of a comment line ONLY if it's in the first character following a carriage return (and spaces and tabs)

    Code: Select all

    /sub MySubroutine(variable1|variable2|variable3)
         Blah Blah
         |the line above this calculates the meaning of life
         Blah Blah
         |the line above should equate to 42
    /return
    The 3rd and 5th lines are comment lines, the first line shouldn't have any comments

    Thanks in Advance!

    6,686585
    Grand MasterGrand Master
    6,686585

      Mar 10, 2006#2

      For the | as line comment only if all preceding characters of the line are white-space characters you could use for example

      Line Comment Preceding Chars = [~0-9A-Za-z_]

      But this will still fail on MySubroutine(variable1 | variable2 | variable3).

      Similar line comment problems were discussed several times here in this forum. It's simply a bad syntax of the language if it use a single character for line comment but also the same character as operator and interpretes it according to the characters before. It is not possible to write a general syntax highlighting mechanism to handle all such "crazy" special language depending conditions. An editor is an editor and not an interpreter or compiler which is designed for only one purpose.

      Best practice in such situations is to extend the single line comment by the programmers to something which can be easily detected as line comment. For your example I would simply always write |. or |_ as line comment instead of single character | . Then it could be easily detected by UE as line comment.

      Why should a programmer adapt his programming style to a general text editor and not the editor to the programmers style?

      Counterquestion: Why not?

      If the adaption of the personal programming style helps you because the editor can highlight it correct, so why not changing the personal style. Syntax highlighting is really a big help for programming. And you also could benefit from it because you can easier find | as operator. If developers of a general editor will try to handle all "crazy" syntax language specifications existing in the world of computer languages, it will become too complex and will not work good and fast anymore for all "normal" languages.

      If you are willing to change your line comment style for example to |. you will have the problem with existing line comments. But a simple regular expression replace in UltraEdit style can convert all | line comments into |. line comments.

      Find What: %^([ ^t]+|^)
      Replace With: ^1.


      About the code folding problem:

      Next major release of UltraEdit (v12.00 release candidate 1 is already available for the beta testers) will have a new keyword for the specification of strings which if found in a line tells the fold logic to ignore this line. For your example it would be:

      /Ignore Fold Strings = "/if"

      UEStudio v5.10+1 already supports the specifications of ignore fold strings.
      Best regards from an UC/UE/UES for Windows user from Austria