Find Strings and Mark Region

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: 2446
Joined: Fri Aug 13, 2004 5:10 pm

Find Strings and Mark Region

Post by jussij » Fri Aug 16, 2013 4:21 am

Code: Select all

--
--        Name: Find Strings and Mark Region
--
--      Author: Jussi Jumppanen
--
--    Language: Lua Macro
--
-- Description: This simple Lua macro asks the user for two search strings
--              and then searches the current document looking for the two
--              string values. If it finds the two strings it marks the
--              region between the two strings.

function key_macro()
    -- macro only works for documents
    local document = is_document()

    if (document == 0) then
        message("This macro only works for document files.");
        beep();
        return;
    end

    -- the default command
    local nill = ""

    -- ask for a user for a command line
    input1, input2 = user_input("Start Text:", nill, "End Text:", nill, "Input the Start and End Text")

    -- check for user input
    if string.len(input1) > 0 and string.len(input2) > 0 then
        screen_update_disable()

        -- save the cursor details
        cursor_save()

        -- save the current search options
        search_options_save()

        -- set the search options
        set_search_option("UseCase"   , 0)
        set_search_option("WholeWord" , 0)
        set_search_option("RegExpress", 0)

        set_find_text(input1)

        if SearchNext() == 1 then
            -- save the starting location
            line_begin   = get_line_pos()
            cursor_begin = get_cursor_pos()

            set_find_text(input2)

            if SearchNext() == 1 then
                -- save the end location
                line_end   = get_line_pos()
                cursor_end = get_cursor_pos()

                -- ignore the saved cursor
                cursor_ignore()

                -- move to start of text
                set_line_pos(line_begin, cursor_begin)

                -- turn on marking
                MarkBlockSet()

                -- move to end of text
                set_line_pos(line_end, cursor_end)

                return
            else
                -- restore the saved cursor
                cursor_restore()
            end
        else
            -- restore the saved cursor
            cursor_restore()
        end

        -- restore the previous search options
        search_options_save()

        screen_update_enable()
        screen_update()
    else
        message("Operation cancelled by user.")
    end
end

key_macro() -- run the macro

Post Reply
kuchnie warszawa opinie

Who is online

Users browsing this forum: No registered users and 1 guest