Column Align Macro

Column Align Macro

5
NewbieNewbie
5

    Oct 04, 2005#1

    Hi folks.

    After searching this forum and not finding anwers, I'd thought I ask the experts before I write my own macro to do this.

    What I would like is some way to vertically align, seperated with spaces, text elements and operators. So this:

    Code: Select all

    variable = "Some kind of string"
    var2 = 12800
    var3 = var 4 = 0
    
    after higlighting the lines and executing a macro would produce this:

    Code: Select all

    variable = "Some kind of string"
    var2     = 12800
    var3     = var4                  = 0
    
    Anybody have some macro code that does this? MultiEdit32 does this just great and I might end up converting that source into something that will work with UE, but it doesn't hurt to ask first.

    Thanks.

    206
    MasterMaster
    206

      Oct 05, 2005#2

      Look at Column > Convert to Fixed Column


      Separator character set as =

      Scan and Convert
      Software For Metalworking
      http://closetolerancesoftware.com

      5
      NewbieNewbie
      5

        Oct 06, 2005#3

        Close enough for jazz. I'll play around with it more.

        Thank you.

        344
        MasterMaster
        344

          Oct 06, 2005#4

          The problem is that these column actions have no macro-command.
          I think you won't find a satisfying solution for this.
          Anyway, mrainey's hint helps if having many columns to adjust.
          In my example, a "=" sign was standing at each end of the line, I had to delete these manually by column-marking.
          Any idea how to avoid those = at the end ?

          example:

          a = 1
          intb = 123

          a = 1=
          intB = 123=

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

          5
          NewbieNewbie
          5

            Oct 07, 2005#5

            I've played around with this some. At first I thought I wasn't using it right. After experimenting with it for hours, the closest I can come is nearly what Bego writes. And no Bego, I didn't find a way to avoid the ='s at the end of the lines.

            Maybe this weekend I'll work on writing a macro to do it properly.

            It kind of surprises me that UltraEdit doesn't have this built in or macro that the user can install. Gotta start somewhere I guess. :)

            206
            MasterMaster
            206

              Oct 07, 2005#6

              Something like this macro should help to clean up your file:

              Code: Select all

              InsertMode
              ColumnModeOff
              HexOff
              UnixReOn
              Top
              Find RegExp " *=$"
              Replace All ""
              Top
              Find RegExp " *=$"
              Replace All ""
              Software For Metalworking
              http://closetolerancesoftware.com

              344
              MasterMaster
              344

                Oct 08, 2005#7

                Hi guys,

                Those workaround do well. Thanx.
                But I think we found out (once more) that UE deserves a real macro-programming language with real variables etc. :(
                Please force this in your improvement-suggestions to IDM.

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

                11
                Basic UserBasic User
                11

                  Oct 08, 2005#8

                  I played around a little too and came up with the macros listed below. they execute painfully slow IF you have a source-file with many functions in it and the function-list is on. UE isn't very quick at building this list.

                  Anyways, give it a try.


                  1. SDUE_Align: prompts for the alignment-chars to be used (can be a string, e.g. ":=" )

                  Code: Select all

                  InsertMode
                  ColumnModeOff
                  HexOff
                  UnixReOff
                  Clipboard 6
                  ClearClipboard
                  Clipboard 7
                  ClearClipboard
                  Clipboard 8
                  ClearClipboard
                  Clipboard 9
                  ClearClipboard
                  PlayMacro 1 "SDUE_SelBlkCompl"
                  Clipboard 9
                  Cut 
                  PlayMacro 1 "SDUE_Pos1"
                  GetString "Alignment character(s)"
                  "
                  "
                  Key UP ARROW
                  Key HOME
                  IfColNumGt 1
                  Key HOME
                  EndIf
                  Clipboard 8
                  StartSelect
                  Key END
                  PlayMacro 1 "SDUE_QuoteRegExp"
                  Key HOME
                  IfColNumGt 1
                  Key HOME
                  EndIf
                  Clipboard 8
                  StartSelect
                  Key END
                  Copy 
                  NewFile
                  Clipboard 9
                  Paste 
                  Clipboard 8
                  Find RegExp "^p"
                  Replace All "^c^p"
                  Find RegExp "%*^c"
                  Replace All "^c"
                  Find RegExp "^c^p"
                  Replace All "^p"
                  SelectAll
                  Clipboard 7
                  Cut 
                  Clipboard 9
                  Paste 
                  Clipboard 8
                  Find RegExp "^c?++^p"
                  Replace All "^p"
                  Find RegExp "%^c^t"
                  Replace All "^c "
                  TrimTrailingSpaces
                  SelectAll
                  Clipboard 6
                  Cut 
                  ColumnModeOn
                  Paste 
                  Find "^p"
                  Replace All " ^p"
                  Top
                  Key END
                  Clipboard 7
                  Paste 
                  ColumnModeOff
                  SelectAll
                  TrimTrailingSpaces
                  SelectAll
                  Clipboard 5
                  Copy 
                  CloseFile NoSave
                  DeleteLine
                  "
                  
                  "
                  Key UP ARROW
                  Key UP ARROW
                  Paste [code]
                  Clipboard 0
                  

                  Sub-Macros called by the above:

                  SDUE_SelBlkCompl - completes a selection to cover full-lines

                  Code: Select all

                  Clipboard 9
                  IfSel
                  Cut 
                  "
                  "
                  Key UP ARROW
                  PlayMacro 1 "SDUE_Pos1"
                  StartSelect
                  Key END
                  Key RIGHT ARROW
                  Find "^p"
                  Replace All SelectText "^c"
                  Key LEFT ARROW
                  Key END
                  Key RIGHT ARROW
                  Else
                  SelectLine 
                  EndIf
                  Clipboard 0
                  
                  SDUE_QuoteRegExp - quotes UE-style regexp-chars; required to align on characters like the asterisk.

                  Code: Select all

                  InsertMode
                  ColumnModeOff
                  HexOff
                  UnixReOff
                  IfSel
                  Cut 
                  NewFile
                  Paste 
                  Find RegExp "^([%$?*+^^^[^]]^)"
                  Replace All "^^^^^1"
                  SelectAll
                  Copy 
                  CloseFile NoSave
                  Paste 
                  EndIf
                  
                  SDUE_Pos1 - reliably position on column 1 regardless of setting for Home-key

                  Code: Select all

                  Key HOME
                  IfColNumGt 1
                  Key HOME
                  EndIf
                  

                  344
                  MasterMaster
                  344

                    Oct 10, 2005#9

                    Hi DarkTurok

                    OK, I got it. You use the "trick" that pasting in column-mode creates trailing spaces, so the longest "leftside" string determins
                    the place where to put the "=" and the rest.
                    --> Thats enough for me :-)

                    Anyway, this solution still stays a bit limited.
                    Things like comments (lines without a "=" sign) do infuence the "="-position.

                    Code: Select all

                    int MyBigLeftValue = 1;
                    //here we go with a fat comment
                    int myNotSoBigVaule = 2;
                    ends up like this:

                    Code: Select all

                    int MyBigLeftValue              = 1;
                    //here we go with a fat comment
                    int myNotSoBigVaule             = 2;
                    Also, in the current version, you have to mark the following line too, or the last line will not work properly.
                    Reason: replace ^p wont work in last line; there is no ^p.


                    So replace the SDUE_Align code like this:

                    Code: Select all

                    . . .
                    "
                    "
                    Clipboard 8
                    Find RegExp "^c?++^p"
                    Replace All "^p"
                    Find RegExp "%^c^t"
                    Replace All "^c "
                    Bottom
                    Key BACKSPACE
                    TrimTrailingSpaces
                    SelectAll
                    . . .

                    if you do not like the promt dialog and you always want to align for e.g. "=",
                    replace:

                    Code: Select all

                    GetString "Alignment character(s)"
                    "
                    "
                    with:

                    Code: Select all

                    "=
                    "
                    Thanx, Alex
                    Normally using all newest english version incl. each hotfix. Win 10 64 bit

                    11
                    Basic UserBasic User
                    11

                      Oct 11, 2005#10

                      Thanks for the comments and the improvements.

                      I was aware of the "line without alignment-character" issue. It's no big deal for the purposes I use the macro most often for, that is aligning assignment blocks and variable declarations - you rarely find thes at the very end of a file anyways :)