Problem with Code Folding for SQL Files (solved)

Problem with Code Folding for SQL Files (solved)

19
Basic UserBasic User
19

    Mar 15, 2016#1

    Hi

    I'm hoping someone can suggest a fix for my code folding problem (though I wonder if what I want is possible).

    Please refer to the first image below. As you will see, there is no code folding option against the FUNCTION or PROCEDURE lines. This is is what I would like if it's possible. I have the following code folding entries in my pl/sql wordfile:

    Code: Select all

    /Open Fold Strings = "BEGIN" "CASE" "FUNCTION" "IF" "LOOP" "PROCEDURE"
    /Close Fold Strings = "END;" "END CASE" "END IF;" "END LOOP;"
    
    I've tried adding a "END " string to the close line in the hope that this would allow a match with the "FUNCTION" and "PROCEDURE" entries in the open line but this still doesn't work - please see the second image below for the the effect adding an "END " entry has.

    Any suggestions anyone could give would be most appreciated.

    Many thanks, PG.
    Capture1.PNG (49.29KiB)
    Without "END " in the close line
    Capture2.PNG (46.44KiB)
    With "END " in the close line
    UltraEdit version and OS info:
    UltraEdit 15.20.0.1017;Windows 7

    6,681583
    Grand MasterGrand Master
    6,681583

      Mar 15, 2016#2

      Please could you post the code examples also as a text block formatted as code block. I don't want to write off the code block from image. You have the code block already as text data. So please post it as text.

      What happens if you replace

      Code: Select all

      "END;" "END CASE" "END IF;" "END LOOP;"
      by

      Code: Select all

      "END"
      because it looks like this word marks the end of any block?
      Best regards from an UC/UE/UES for Windows user from Austria

      19
      Basic UserBasic User
      19

        Mar 15, 2016#3

        Hi Mofi

        I tried using "END" in place of "END;" "END CASE" "END IF;" "END LOOP;" but this changed the code folding indicators from Capture1.PNG to Capture2.PNG below.

        Please find the source code below.

        Regards, PG.

        Code: Select all

          FUNCTION f_cust_exists(i_custno IN NUMBER)
          RETURN VARCHAR2  -- return 'Y'/'N'
          IS
        
          lv_return                   VARCHAR2(1);
        
          BEGIN
        
            IF dbg.f_dbg_on THEN
              dbg.p
              (
                  'i_custno: ' || TO_CHAR(i_custno)
              );
            END IF;
        
            BEGIN
              SELECT 'Y'
              INTO   lv_return
              FROM   customers
              WHERE  custno = i_custno;
        
            EXCEPTION
              WHEN NO_DATA_FOUND THEN
                lv_return:='N';
            END;
        
            RETURN lv_return;
        
          END f_cust_exists;
        
        
        
          PROCEDURE p_cust_validation(i_custno       IN     NUMBER
                                     ,i_company_code IN     NUMBER
                                     ,i_cust_ref     IN     VARCHAR2
                                     ,o_exists          OUT VARCHAR2
                                     ,o_cust_ref        OUT VARCHAR2) IS
        
          BEGIN
        
              IF dbg.f_dbg_on THEN
                dbg.p
                (   'i_custno: '       || TO_CHAR(i_custno)
                  ||'i_company_code: ' || TO_CHAR(i_company_code)
                  ||'i_cust_ref: '     || i_cust_ref
                );
              END IF;
        
              BEGIN
                SELECT 'Y'
                      ,cust_ref
                INTO   o_exists
                      ,o_cust_ref
                FROM   customer_ref
                WHERE  custno = i_custno
                AND    company_code = i_company_code;
        
              EXCEPTION
              WHEN NO_DATA_FOUND THEN
                o_exists := 'N';
                o_cust_ref := NULL;
              END;
        
          END p_cust_validation;
        
        Capture1.PNG (11.84KiB)
        /Close Fold Strings = "END;" "END CASE" "END IF;" "END LOOP;"
        Capture2.PNG (12.56KiB)
        /Close Fold Strings = "END"
        UltraEdit version and OS info:
        UltraEdit 15.20.0.1017;Windows 7

        115
        Power UserPower User
        115

          Mar 15, 2016#4

          If you look at your close fold strings you have END; (end plus semicolon)

          but if you look at your code example you have END functionname; (end plus text plus semicolon) which will not match it.

          (EDIT)

          In your second post you noted problems when using just END as the sole close fold string.
          If you have an open fold string and a close fold string in the same line or one line after another, then no code folding will happen with that pair.
          If you have a close fold string and an open fold string in the same line, you end one fold and start another.

          You have the close fold string END and the open fold string IF on the same line. You as a human see "END IF" but the computer sees "END" and then "IF". You are closing one fold pair and starting another. This will mess up the pairs for the rest of your code.

          What you need to do for your close strings is go back to the "END IF" "END CASE" and so on but remove the semicolons from the strings.

          19
          Basic UserBasic User
          19

            Mar 15, 2016#5

            Hi Mick

            Thank you for your reply. I realised there would be probably be an issue with the END followed by the function name and this is why, in my original post, i did wonder if there is an answer to this. I tried your suggestion of removing the semi-colons from the close fold strings but this gave the same result as Capture2.PNG in my second post above.

            I'm definitely not an expert regarding this topic - hence this blog entry - but i do wonder if what i'm asking for is even possible, considering the variable nature of the function/procedure names.

            Thanks again.
            PG
            UltraEdit version and OS info:
            UltraEdit 15.20.0.1017;Windows 7

            6,681583
            Grand MasterGrand Master
            6,681583

              Mar 15, 2016#6

              Mick explained well why my initial idea does not work without modifying also the open fold strings.

              What works fine on provided code block (thanks) is using:

              Code: Select all

              /Open Fold Strings = "BEGIN" "CASE  " "IF " "LOOP "
              /Close Fold Strings = "END"
              The keyword END marks always the end of a block to fold like } in C/C++/C#/JS.

              The beginning of a block to fold is marked with
              • BEGIN ... body of function/procedure or another embedded block like { in C/C++/C#/JS or
              • CASE or
              • IF or
              • LOOP
              whereby after last three keywords there must be a space character and not a semicolon or something else.

              You can add additionally "CASEtab", "IFtab" and "LOOPtab" if a horizontal tab character occurs also sometimes in your PL/SQL files after those 3 keywords.

              Also you could add on both lines "EXCEPTION" to be able to fold from BEGIN to EXCEPTION and from EXCEPTION to END.

              It is not possible to fold from FUNCTION or PROCEDURE to corresponding END because the keyword BEGIN after FUNCTION or PROCEDURE defines beginning of body block of function/procedure.

              A code folding from FUNCTION or PROCEDURE line to END of function/procedure would require special PL/SQL language intellisense because it would be needed to ignore first BEGIN after a line with FUNCTION or PROCEDURE, but take into account all other BEGIN within body of a function/procedure.
              Best regards from an UC/UE/UES for Windows user from Austria

              19
              Basic UserBasic User
              19

                Mar 16, 2016#7

                Hi Mofi

                Thank you for your explanation. It's not quite what i was hoping for, but the BEGIN/END folding block is good enough, especially considering the slightly vague notion of what constitutes a block of code in pl/sql.

                Regards, PG.
                UltraEdit version and OS info:
                UltraEdit 15.20.0.1017;Windows 7