Fold strings for Visual FoxPro (VFP)

Fold strings for Visual FoxPro (VFP)

4
NewbieNewbie
4

    Oct 07, 2012#1

    Does anyone have a Syntax Highlighting / Code Folding file (UEW) for Microsoft Visual Foxpro PRG files? Thanks.

    I have the following lines but they are not quite working. In particular it gets totally confused if I have a DO CASE / ENDCASE inside of an IF / ENDIF.

    Thanks.

    Code: Select all

    /Open Fold Strings = "DO WHILE" "IF" "FOR" "FUNCTION" "PROCEDURE" "CASE" "OTHERWISE" "ELSE"
    /Close Fold Strings = "ENDDO" "ELSE" "ENDIF" "ENDFOR" "CASE" "ENDCASE" "OTHERWISE" "ENDFUNC" "ENDPROC"
    /Ignore Fold Strings = "DELETE FOR" "LOCATE FOR" "DO CASE"
    I think I figured out the problem, but not the solution. The problem is that ENDCASE is the closing fold both for DO CASE and the final CASE statement. Anyone figure this one out?

    6,675585
    Grand MasterGrand Master
    6,675585

      Oct 07, 2012#2

      While opening and closing braces must match, there is no such limitation for open and close fold strings. For UltraEdit it is enough if there is a close fold string for every open fold string. If the close fold string really belongs to the open fold string is not evaluated by UltraEdit as this would require knowledge about the language itself.

      So if you have a file which contains for example FUNCTION and in the next lines there are no other open or close fold strings up to a line with ENDCASE, UltraEdit would suggest code folding from the line with FUNCTION to the line with ENDCASE. Of course such a file could not be compiled as this is a big error in syntax structure.

      I don't know anything about Visual FoxPro and therefore have taken a quick look on the Wikipedia page about Visual FoxPro. It looks like the DO CASE ... CASE ... CASE ... OTHERWISE ... ENDCASE structure is like in C/C++/Javascript/...

      Code: Select all

      switch (variable):
      {
         case 1:  // code
                  break;
         case 2:  // code
                  break;
         case 3:  // code
                  break;
         default: // code
                  break;
      }
      OTHERWISE respectively default are just optional, not required. So a case block ends
      1. where next case block begins, or
      2. where the default block begins, or
      3. where the switch statement ends.
      If every switch statement contains a default block as required according to MISRA C/C++ for safe code, but not required by C/C++, there would be no problem to code folde also case blocks. And same is true for Visual FoxPro: If there would be always an OTHERWISE block, code folding of CASE blocks would be no problem.

      But in Visual FoxPro as well as in C/C++/Javascript/... often option 3 is used and that's bad for code folding of case blocks.

      As general text editor UltraEdit has no intellisense for any programming language, UE does not know that ENDCASE marks end of a DO CASE block and marks also end of a CASE block if there is no OTHERWISE block (and IF here!).

      The result is that when UltraEdit's code folding engine reaches the line with ENDCASE and there is no OTHERWISE block, UE interprets this line as end of the last CASE block and the DO CASE block is still not terminated.

      The only solution for this situation is to go without code folding for CASE blocks. Remove CASE from open and close fold strings definition lines and remove also OTHERWISE.

      You have to be satisfied with code folding for the entire DO CASE and fold a CASE block when needed by manually selecting the lines and hiding all lines except first line of the selection using View - Hide/Show Lines - Collapse All (by hotkey).

      An automatic code folding for CASE blocks would be possible only if always a line with OTHERWISE is present.

      In general this limitation of automatic code folding should not be a problem as a CASE block should not contain so many lines that all of them cannot be displayed on half of the screen.

      4
      NewbieNewbie
      4

        Oct 07, 2012#3

        Thanks for the reply. That is the conclusion I came to: fold on the DO CASE / ENDCASE, but not the individual CASE blocks.

        If anyone else is using VFP this is what I came up with so far:

        /Open Fold Strings = "DO WHILE" "IF" "FOR" "FUNCTION" "PROCEDURE" "DO CASE" "ELSE" "#IF" "#IFDEF" "#IFNDEF" "#ELSE" "#ELIF"
        /Close Fold Strings = "ENDDO" "ELSE" "ENDIF" "ENDFOR" "ENDCASE" "ENDFUNC" "ENDPROC" "#ELSE" "#ELIF" "#ENDIF"
        /Ignore Fold Strings = "DELETE FOR" "LOCATE FOR"

        You may also want to add the Nocase option to the first line.

        6,675585
        Grand MasterGrand Master
        6,675585

          Oct 09, 2012#4

          I forgot to answer your first question. There are 2 user-submitted wordfiles for FoxPro on page Downloads - Extras - Wordfiles: one for FoxPro 2.6 and one for Visual FoxPro 6.0.

          9
          NewbieNewbie
          9

            Oct 09, 2012#5

            This is the fold section of my wordfile for FoxPro. We use FoxPro daily, so our wordfile as changed over the years.

            Code: Select all

            /Open Fold Strings = "do case" "do while" "define" "for" "if" "try" "#if" "#ifdef" "#ifndef" "text to" "scan" "function" "procedure"
            /Close Fold Strings = "endcase" "enddo" "enddefine" "endfor" "endif" "endtry" "#endif" "#endif" "#endif" "endtext" "endscan" "endfunc" "endproc"
            /Ignore Fold Strings = "&&" "\" "between" "browse" "count" "define window" "for" "locate" "oError" "replace" "set" "throw" "timer"

            Attached is my wordfile for FoxPro.
            I am using 18.20.0.1020, so my wordfile makes use of 18.X features.
            My color scheme is dark, so you may have to change the colors for the highlighting to work.

            **********************************************************************
            Edited on 2012-10-19 18:08
            I uploaded the FoxPro word file again.
            I have removed the duplicates and the invalided words as reported by Mofi.
            I used the Color Scheme Management Tool to remove the duplicates and invalid words. I also have the words in each section sorted.
            FoxPro_WordFile.zip (13.4 KiB)   243

            4
            NewbieNewbie
            4

              Oct 09, 2012#6

              paul_ray wrote:This is the fold section of my wordfile for FoxPro. We use FoxPro daily, so our wordfile as changed over the years.
              Ah, thanks for reminding me about TRY/ENDTRY and DEFINE/ENDDEFINE.

                Oct 16, 2012#7

                Thanks for the wordfile. I'm wondering if there is a way to highlight values within [square brackets] ?

                6,675585
                Grand MasterGrand Master
                6,675585

                  Oct 17, 2012#8

                  I have taken a look on the wordfile contributed by Paul Ray. It contains 3 invalid word definitions:

                  Size<height>
                  Size<maxlength>
                  Size<width>

                  Those 3 words are invalid words as < and > are word delimiters.

                  There are some words duplicate because of keyword Nocase. But that's okay if auto-complete is used and therefore for example IsFLocked and Isflocked should be suggested. But there are 100% identical duplicate words which should be removed.

                  Code: Select all

                  DB_BUFLOCKTABLE -> in /C1
                  DB_BufLockTable -> in /C3
                  
                  DB_BUFOFF -> in /C1
                  DB_BufOff -> in /C3
                  
                  DB_BUFOPTTABLE -> in /C1
                  DB_BufOptTable -> in /C3
                  
                  DB_DELETEINSERT -> in /C1
                  DB_DeleteInsert -> in /C3
                  
                  DB_KEYANDMODIFIED -> in /C1
                  DB_KeyAndModified -> in /C3
                  
                  DB_KEYANDTIMESTAMP -> in /C1
                  DB_KeyAndTimestamp -> in /C3
                  
                  DB_KEYANDUPDATABLE -> in /C1
                  DB_KeyAndUpdatable -> in /C3
                  
                  DB_TRANSAUTO -> in /C1
                  DB_TransAuto -> in /C3
                  
                  DB_TRANSMANUAL -> in /C1
                  DB_TransManual -> in /C3
                  
                  DB_UPDATE -> in /C1
                  DB_Update -> in /C3
                  
                  BinToC -> in /C3
                  Bintoc -> in /C3
                  
                  CToBin -> in /C3
                  Ctobin -> in /C3
                  
                  DoEvents -> in /C3
                  Doevents -> in /C3
                  
                  Each -> in /C3
                  Each -> in /C3
                  
                  Edit -> in /C3
                  Edit -> in /C3
                  
                  IsFLocked -> in /C3
                  Isflocked -> in /C3
                  
                  IsRLocked -> in /C3
                  Isrlocked -> in /C3
                  
                  LoadPicture -> in /C3
                  Loadpicture -> in /C3
                  
                  SavePicture -> in /C3
                  Savepicture -> in /C3
                  
                  _Coverage -> in /C3
                  _Coverage -> in /C3
                  Now to your question: Highlighting a string between two characters within a line is possible using marker characters. Add above the line starting with /C1 following line:

                  /Marker Characters = "[]"

                  Next you have to add just [] to any color group like a word although both characters are word delimiters. You can use one of the existing 8 color groups or use a new color group. For example:

                  /C9"Values in Brackets"
                  []