Tapatalk

Snippets with macro

Snippets with macro

10
Basic UserBasic User
10

    May 25, 2007#1

    Hello,

    I've made a macro that enclose the instructions if, for, while,...
    For each of them, I've created a template.
    Then, I created a macro :

    Code: Select all

    HexOff
    Key LEFT ARROW
    SelectWord 
    Find "if"
    Replace All SelectText "if"
    IfFound
    Template 0
    Else
    Find "case"
    Replace All SelectText "case"
    IfFound
    Template 1
    Else
    Find "for"
    Replace All SelectText "for"
    IfFound
    Template 2
    Else
    Find "while"
    Replace All SelectText "while"
    IfFound
    Template 3
    Else
    Find "function"
    Replace All SelectText "function"
    IfFound
    Template 4
    Else
    Find "procedure"
    Replace All SelectText "procedure"
    IfFound
    Template 5
    Else
    Template 6
    EndIf
    EndIf
    EndIf
    EndIf
    EndIf
    
    I have to write the instruction and execute the macro just after.
    It works when there is no tab character before the instruction. But if there is a TAB (or a whitespace), it doesn't indent the second line of the template. So it look like something like this :

    Code: Select all

          if ()
    endif
    
    Is there a way to align the second line with the first one ?
    I would rather prefer to keep the template (i.e not to write all the snippets in the macro). Is it possible ?

    Thank you in advance for your help.

    mathmax

    6,685587
    Grand MasterGrand Master
    6,685587

      May 27, 2007#2

      Yes, it is possible, if you change the macro code to this one:

      HexOff
      Key LEFT ARROW
      SelectWord
      Find "if"
      Replace All SelectText "if"
      IfFound
      Delete
      StartSelect
      Key HOME
      Template 0
      ExitMacro
      EndIf
      Find "case"
      Replace All SelectText "case"
      IfFound
      Delete
      StartSelect
      Key HOME
      Template 1
      ExitMacro
      EndIf
      Find "for"
      Replace All SelectText "for"
      IfFound
      Delete
      StartSelect
      Key HOME
      Template 2
      ExitMacro
      EndIf
      Find "while"
      Replace All SelectText "while"
      IfFound
      Delete
      StartSelect
      Key HOME
      Template 3
      ExitMacro
      EndIf
      Find "function"
      Replace All SelectText "function"
      IfFound
      Delete
      StartSelect
      Key HOME
      Template 4
      ExitMacro
      EndIf
      Find "procedure"
      Replace All SelectText "procedure"
      IfFound
      Delete
      StartSelect
      Key HOME
      Template 5
      Else
      Delete
      StartSelect
      Key HOME
      Template 6
      EndIf


      And if you have defined your templates as shown below for example for the if condition.

      [$replace$]if (^)
      [$replace$]endif



      How it works: The macro deletes the keyword after identifying it. So the current line should contain only the indenting spaces/tabs which are selected next by the macro. It is also possible that nothing is selected. Last the template is inserted with the selected spaces/tabs inserted at start of every line in the template because of special code [$replace$]. ^ marks the cursor position after inserting the template.

      With this method you have created templates with auto indent because the macro selects the indenting spaces/tabs before inserting the template.
      Best regards from an UC/UE/UES for Windows user from Austria

      10
      Basic UserBasic User
      10

        May 28, 2007#3

        Hi, thank you very much for the macro. It works fine. However, I still have a little problem. The macro doesn't work with instructions such as "do while" which are composed of several words. Is it possible to modify the macro so that it works with such instructions too ?

        Thank you for you help

        6,685587
        Grand MasterGrand Master
        6,685587

          May 29, 2007#4

          Replace at top of the macro

          Key LEFT ARROW
          SelectWord


          by

          Key HOME
          IfCharIs 32
          Key CTRL+RIGHT ARROW
          EndIf
          IfCharIs 9
          Key CTRL+RIGHT ARROW
          EndIf
          StartSelect
          Key END
          EndSelect


          Then you can also use

          Find "do while"
          Replace All SelectText "do while"
          IfFound
          Delete
          StartSelect
          Key HOME
          Template x
          ExitMacro
          EndIf


          I have not tested if it really works what I suggest here.
          Best regards from an UC/UE/UES for Windows user from Austria

          10
          Basic UserBasic User
          10

            May 30, 2007#5

            Thank you, it works almost but the word "do" is deleted when I execute the script. Do you know how to correct this ?

            6,685587
            Grand MasterGrand Master
            6,685587

              May 31, 2007#6

              You must have a template for do while loops which contains do while. You can't use the while template for do while loops.
              Best regards from an UC/UE/UES for Windows user from Austria

              10
              Basic UserBasic User
              10

                Jun 02, 2007#7

                sorry, that was my template that contained "while" instead of "do while". So it works perfectly. Thank you very much for your help.