Page 1 of 1

Align Text Macro

Posted: Fri Jan 30, 2009 4:43 am
by jussij
This script below will align code to a given vertical cursor location. specified.

For example assume you code looks like this where | is used to indicate the cursor location:

Code: Select all

        Some |            text
        that      is 
        all    over 
        the           place
Putting the cursor at the | location and running the macro four times gives you the nicely aligned code shown below:

Code: Select all

        Some text
        that is 
        all  over 
        the  place

Code: Select all

--
--        Name: Align  Macro
--
--      Author: Omer Kircher
--
--    Language: Lua Macro
--
-- Description: This function facilitates lining up columns of text. 
--
--              To use, load the macro (i.e. F9 key), position the cursor
--              and then run macro using the Macro Execute (i.e. F8 key)
--
--              Alternatively you can bind the macro to the keyboard.
--
--              Blank spaces between the cursor and the next word will 
--              be deleted.
--
--              The cursor is then moved to the next line ready for 
--              another operation.
--

function key_macro()
    screen_update_disable()

    -- look for a white space (32) ascii character
    if get_char_at() == 32 then
        -- remove the white space
        MarkColumnToggle()
        MoveWordNext()
        MarkDeleteEx()
    end

    -- position the cursor on the next line
    MoveLineDown()
    screen_update_enable()
    screen_update()
end

key_macro() -- run the macro