Tab expansion macros

Tab expansion macros

1
NewbieNewbie
1

    Jan 25, 2007#1

    It is a shame that for the moment UltraEdit does not support TAB keyword expansion. After testing it for a while i found the editor to be really good but lacking, in my view, this extremely important feature.

    After messing around with the configuration for a while, trying the auto completes, templates, etc, i found none of these features really didn't do what i wanted. Expand a keyword as soon as one presses the TAB key, leaving the cursor at the proper position for continuing your edit as fast as possible.

    so i started playing around with the macros and after much head banging and trial and error
    (mostly error) I wrote the set of macros attached to this post that do what I wanted.

    The perfect solution would be for UltraEdit to support this feature, by reading a text file with keywords and their expansions or something like that, but for the moment you can use this workaround.

    I don't know the limitations on the number of commands per macro, or if this is the best way to achieve the proposed goal, so if you find a way to improve this please be my guest, just let everybody else know about it.

    The macros assume that you have UltraEdit configured to automatically insert the closing Prentiss, or curly braces (Advanced->Configuration->IDE->InteliTips->Miscellaneous)
    And Smart Placement of "}" when placed automatically is also checked.

    After loading the macros assign the TabExpand macro to the TAB key. If you do this remember that the autocomplete feature will be disabled. You can always use a different key thought.

    The structure of the macros is simple:

    create a new macro for each tab keyword expansion you want. call it TE_<keyword>

    write the macro as follows

    InsertMode
    ColumnModeOff
    HexOff
    PerlReOn
    Find MatchWord Select "<keyword>"
    Replace SelectText "<expanded text>"
    IfFound
    PlayMacro 9 "TE_Left"
    EndIf

    replace <keyword> with the keyword you like and <expanded text> with the text that should be placed after the keyword is "expanded".

    After the IfFound command you can place more macro instruction, either to place the cursor properlly or insert more text.

    to activate the newly created macro modify the TabExpand macro and add the following code to it:

    PlayMacro 1 "TE_<keyword>"
    IfSel
    Else
    ExitMacro
    EndIf

    The IFSel is a hack in order for the macro to exit if there was any replacement done. meaning the keyword was expanded in the previous call to PlayMacro. This is not very beautiful but works. If you know of a better way to do this let me know...

    Please take a look at all the predefined macros in the file for more details on how to use the TabExpand "system"

    Since for some reason I cannot attach the Macro file to the forum you can download it from http://www.savefile.com/files/439911