Intelligent Code Insertion Macro

Intelligent Code Insertion Macro

Phantom

    Jun 29, 2005#1

    I'd like to write a macro to be bound to the enter key, to do something like:

    * If the current line contains the token 'def' (at beginning of line or with leading whitespace)
    ** Insert two newlines and 'end' followed by a newline (with 'end' aligned with 'def')
    ** Put the insertion point on the inserted blank line, and insert spaces to align with 'def' and then insert 4 more spaces
    * If the current line does not contain the token 'def'
    ** Insert a newline

    I think you can see where I'm going with this. I'm trying to make UE support Ruby as well as jEdit can. In jEdit, with the Ruby plug-in, if I type:

    Code: Select all

        def foo[enter]
    
    I get

    Code: Select all

        def foo[enter]
            _
        end
    
    with the cursor positioned at the underscore. If the answer is RTFM, please point me at the right section of the FM, because I can't find the macro capabilities documented anywhere!

    Phantom
    Phantom

      Jun 30, 2005#2

      OK. I've got the macro (see below). Now how do I bind it to the ENTER key?

      Code: Select all

      Key HOME
      IfCharIs "d"
        Key RIGHT ARROW
        IfCharIs "e"
          Key RIGHT ARROW
          IfCharIs "f"
            Key RIGHT ARROW
            IfCharIs 32
              Key END
              InsertLine
              "end"
              InsertLine
              Key UP ARROW
              Key UP ARROW
              Key END
      "
      	"
            Else
                InsertLine
            EndIf
          Else
            Key END
            InsertLine
          EndIf
        Else
          Key END
          InsertLine
        EndIf
      Else
        Key END
        InsertLine
      EndIf
      
      

      46
      Basic UserBasic User
      46

        Jun 30, 2005#3

        Hi kleinfelter,

        Menu Macro -> Edit Macro -> Modify Macro -> Shortcut.

        I've done some "structures completion" for VHDL, and I suggest you do not replace the Enter key binding, but instead use something like Ctrl-Enter or Shift-Enter (the short delay implied by the macro execution will quickly be annoying :wink: ). If you want an example of how I've made, just let me know. But no miracle, the Ue's macro language unfortunately don't implement facilities for word testing.
        Never forget: "Above the clouds, The sky is blue and the sun shine"