Template like Macro

This forum allows you to share scripts with other Zeus users. Please do not post bug reports, feature requests or questions to this forum, but rather use it exclusively for posting scripts or for the discussion of scripts that have been posted.
Post Reply
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Template like Macro

Post by jussij »

A simple Lua macro that wraps a console print line statement around the the current word or marked area around.

For example this:

Code: Select all

    "Hello World"
will become this:

Code: Select all

    System.out.println("Hello World");

Code: Select all

-- Simple Lua Macro
--
-- Take the current word or marked area and wrap it in a print
-- statement.
--
-- For example highlight "Hello World" run the macro and the text
-- will be convert into this:
--
--   System.out.println("Hello World")
--
-- This macro can be bound to any key combination or to the menu.

function key_macro()
    screen_update_disable()

    local word = ""

    if is_marked() then
        -- get the marked area
        word = macro_tag("$M")

        -- delete the marked text
        MarkDelete()
    else
        -- get the current word or marked area
        word = macro_tag("$WordEx")

        if string.len(word) > 0 then
            -- delete the current word
            WordDelete()
        end
    end

    if string.len(word) > 0 then
        -- write out the print line call
        print("System.out.println(" .. word .. ");")
    else
        message("No marked text was found and the cursor is not over a word!")
    end

    screen_update_enable()
    screen_update()
end

key_macro() -- run the macro
Post Reply