Tapatalk

Macro that indents lines as the line before

Macro that indents lines as the line before

344
MasterMaster
344

    Jan 24, 2006#1

    Hi guys,

    Here is a macro that indents lines exactly the same as the line before and automatically jumps down one line.
    It is quite good if you have flattered-structures like this:

    Code: Select all

    if i < 1 then
       only2Spacesbefore = 3
     	 tabAndSpacesBeforeMe = 2
    	Just a tab before me !
    		2 tabs before me :-(
    end if
    
    to end 'em up like that:

    Code: Select all

    if i < 1 then
       only2Spacesbefore = 3
       Just a tab before me !
       2 tabs before me :-(
    end if
    
    Bind the macro to a key, e.g. alt-^

    Format the 1st line in the block as you like it (here: 3 spaces)
    Goto to the second line of the block and press alt-^ 3 times.
    You see that all lines in the block are indented with 3 spaces :-)

    One limit: It does NOT work correctly if the line before starts at column 1.
    (Maybe s.o. has a solution without a 2nd macro because of loop-nesting-problem)

    Maybe you like it, otherwise, ignore it.
    Improvements and comments are welcome.

    rds Bego :wink:

    Code: Select all

    InsertMode
    ColumnModeOff
    HexOff
    UnixReOn
    Clipboard 9
    ClearClipboard
    Key UP ARROW
    Key END
    IfColNumGt 1
    PlayMacro 1 "KEY_HOME"
    StartSelect
    Find RegExp "\S"
    Key LEFT ARROW
    EndSelect
    Copy 
    EndIf
    Key DOWN ARROW
    Key END
    IfColNumGt 1
    PlayMacro 1 "KEY_HOME"
    StartSelect
    Find RegExp "\S"
    Key LEFT ARROW
    EndSelect
    Paste 
    EndIf
    Key DOWN ARROW
    Clipboard 0
    
    The Macro KEY_HOME looks like this and ensures that - whatever settings in UE you set - the cursor surely is at the beginning of the line.
    A Key Home is enough, if your setting "always position Key Home at col 1" is set.

    Code: Select all

    Key HOME
    IfColNumGt 1
    Key HOME
    EndIf
    
    Normally using all newest english version incl. each hotfix. Win 10 64 bit

    6,685587
    Grand MasterGrand Master
    6,685587

      Jan 24, 2006#2

      Hello Bego!

      You wanted an improved version, here it is. It has no problems with column 1 (previous line can be also an empty line) and it should also work for all files indepedent of the line termination (DOS/Unix/MAC). It uses a complete different method without clipboard usage.

      The macro with an UltraEdit style regular expression:

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Key UP ARROW
      Key HOME
      IfColNumGt 1
      Key HOME
      EndIf
      Find RegExp "%^([ ^t]++^)^([~^r^n]++[^r^n]+^)[ ^t]++"
      Replace "^1^2^1"


      The same macro but with an Unix style regular expression:

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOn
      Key UP ARROW
      Key HOME
      IfColNumGt 1
      Key HOME
      EndIf
      Find RegExp "^(\s*)([^\r\n]*[\r\n]+)\s*"
      Replace "\1\2\1"
      Best regards from an UC/UE/UES for Windows user from Austria

      344
      MasterMaster
      344

        Jan 24, 2006#3

        Hi Mofi !!! :-)

        What shall I say. The chief-supporter himself made it once again.
        I took your solution .... I think it's just a BIT more clever ;-)

        Amazing what regexp's are good for .... :o

        rds Bego
        Normally using all newest english version incl. each hotfix. Win 10 64 bit