How to auto complete "if...end if" ?

How to auto complete "if...end if" ?

2
NewbieNewbie
2

    Jul 29, 2005#1

    :( Whenever i type "if", can UE auto complete "end if" in a new line?
    How can i do with macro?
    thanks!

    46
    Basic UserBasic User
    46

      Jul 29, 2005#2

      Hi backrain,

      I had the same problem in the past and made a set of macros
      to auto-complete some VHDL structures (process, if, block, case).
      I can send you the code if you want.
      The macro trigg on "Shift-space" due to the time it takes to run.

      The main idea is to have a macro to detect which keyword is on
      the left of the cursor and, in case of recognition, automatically call
      a second macro to complete the structure.

      There is the code for the If completion:

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOn
      Key LEFT ARROW
      Key RIGHT ARROW
      "~@1#"
      Key HOME
      Key HOME
      StartSelect
      Key END
      Find RegExp "(--.*)~@1#"
      Replace All SelectText "\1~@1#"
      IfNotFound
        EndSelect
        Key HOME
        StartSelect
        Key END
        Find RegExp "if~@1#"
        Replace All SelectText "if (~@3#) then~@2#;"
        IfFound
          EndSelect
          Key HOME
          Find "~@2#"
          "
      end if"
          Find Up "~@3#"
          GetString "Condition :"
          Key END
          "
      "
        Else
          Key HOME
          Find "~@1#"
          Replace "Error in macro IfComp if not found"
        EndIf
      Else
        EndSelect
        Find "~@1#"
        Delete
        Key RIGHT ARROW
      EndIf
      


      The first part is to avoid completing a "if" in a comment (in VHDL line
      comments strats with "--"), you can easly adapt to your language or
      imply remove the first Find/Replace. All "~@...#" are used as position
      markers and shall be unique in the file.

      Good chance.
      Never forget: "Above the clouds, The sky is blue and the sun shine"

      2
      NewbieNewbie
      2

        Re: How to auto complete

        Jul 29, 2005#3

        Hi palou:

        Thank you for your help first!

        I am sorry that the "If completion" code do not work properly in my UE.

        I first edit a new marco named "if_complete", copy your code into it,
        modify this macro, set the hotkey "Shift-space", close the dialog window.

        Next, I open a new file, press Shift-space and it occoured an error "Search string not found", and also "~@1#" in the file.

        If I input "if", the macro do nothing too.

        I am really confused.

        Could you please mail me all your code?

        46
        Basic UserBasic User
        46

          Jul 29, 2005#4

          Hi Backrain,

          You have to active the "Continue if find and replace not found" for your
          macro, this avoid stoping with the message "string not found".

          This completion macro is intended to be called by the macro which
          detect keywords. There is an extract of the code:

          Code: Select all

          HexOff
          Key LEFT ARROW
          SelectWord 
          Find "if"
          Replace All SelectText "if"
          IfFound
          PlayMacro 1 "If_complete"
          Else
           ....do another search for key word
          EndIf
          
          For the full set of macros, I'll send it to you by e-mail in a few minutes.

          Regards from Switzerland.
          Never forget: "Above the clouds, The sky is blue and the sun shine"

          1
          NewbieNewbie
          1

            Mar 10, 2006#5

            If all you want to do is have a quick way of inserting "if", "else if", "switch" and other multi-line structures, then simply record a macro of yourself typing it once and save the macro. You can even place the insert point and the macro will remember it. Then all you do is keep the macro list open on the right and when you want to insert a snip, just double click on your macro! No muss, no fuss.

            It also has the advantage of not having to check what you've just typed and thereby saves processor cycles... very fast this way.

            1
            NewbieNewbie
            1

              Re: How to auto complete

              Jun 02, 2006#6

              Hi i was looking into that eariler, but palou said that the completion macro is intended to be called by the macro which detect keywords and he said email him to get the full set of macro, i send him a post no reply yet.

              can you show me how that detect keywords macro works? I can use that posted one only if i assign it to a hotkey.

              regards

              46
              Basic UserBasic User
              46

                Aug 10, 2006#7

                Hi robotmomo,

                I'm sorry I didn't notice your request :oops:

                Here is the code of the macro that look for keywords (don't expect
                magic, keywords are "hard coded"):

                Code: Select all

                //////////////////////////////////////
                // Macro Name: VHDLCompletion
                // This macro test for a VHDL keyword
                // and execute the right complete macro
                // if it found one.
                // This macro is intended to be called by
                // the "Space" macro, that means the char
                // at the left of the cursor position is
                // a space char (0x20).
                HexOff
                Key LEFT ARROW
                SelectWord
                Find "architecture"
                Replace SelectText All "architecture"
                IfFound
                  PlayMacro 1 "ArchitectureComp"
                Else
                  Find "block"
                  Replace SelectText All "block"
                  IfFound
                    PlayMacro 1 "BlockComp"
                  Else
                    Find "case"
                    Replace SelectText All "case"
                    IfFound
                      PlayMacro 1 "CaseComp"
                    Else
                      Find "else"
                      Replace SelectText All "else"
                      IfFound
                        PlayMacro 1 "ElseComp"
                      Else
                        Find "elsif"
                        Replace SelectText All "elsif"
                        IfFound
                          PlayMacro 1 "ElsifComp"
                        Else
                          Find "entity"
                          Replace SelectText All "entity"
                          IfFound
                            PlayMacro 1 "EntityComp"
                          Else
                            Find "if"
                            Replace SelectText All "if"
                            IfFound
                              PlayMacro 1 "IfComp"
                            Else
                              Find "process"
                              Replace SelectText All "process"
                              IfFound
                                PlayMacro 1 "ProcessComp"
                              Else
                                Key RIGHT ARROW
                                Key LEFT ARROW
                                IfCharIs 32
                                  Key RIGHT ARROW
                                EndIf
                              EndIf
                            EndIf
                          EndIf
                        EndIf
                      EndIf
                    EndIf
                  EndIf
                EndIf


                I wrote this macro long time ago and I'm not sure to remember how it
                works. I just remember you have to remove lines that start with // :wink:

                Regards from Switzerland.
                Never forget: "Above the clouds, The sky is blue and the sun shine"