Search without losing the MarkBlock anchor

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
dougclind
Posts: 14
Joined: Fri May 29, 2009 3:09 am

Search without losing the MarkBlock anchor

Post by dougclind »

I'm trying to do something that should be simple but doesn't work. I need to make a macro where it sets an anchor and marks all the text up until it hits a specific character. That would be the "SearchNext()" character(s). But whenever you do SearchNext() it forgets about the Mark Block that you've set.

There's got to be a way to mark and then copy where the end of the copy text is some character. Can someone tell me how to do this?

Very irritating because I only need to write a macro every couple of years or so and then I have to research and relearn the freaking macro language every time!!! Very very aggravating.
jussij
Site Admin
Posts: 2461
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

I'm trying to do something that should be simple but doesn't work. I need to make a macro where it sets an anchor and marks all the text up until it hits a specific character.

The Lua code below does something like this.
That would be the "SearchNext()" character(s). But whenever you do SearchNext() it forgets about the Mark Block that you've set.
I think you have found a scripting bug. See the *** comment in the macro code below.

Let me know if this is not what you where after.
Very very aggravating.
That's what the forum is for ;)

Cheers Jussi

PS: This code was tested using the latest Zeus version.

Code: Select all

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

  if document > 0 then
    -- ask for a user to supply a search string
    local pattern = user_input("Search string:", "")

    if string.len(pattern) > 0 then

        local FORWARD = 0
        local REVERSE = 1
        local MARKED  = 2
        local ENTIRE  = 3
        local ALL     = 4

        -- save the current search and replace options
        search_options_save()

        -- setup the search
        set_find_text(pattern)
        set_search_option("Scope", FORWARD);
        set_search_option("UseCase", 0)
        set_search_option("WholeWord", 0)
        set_search_option("RegExpress", 0)

        -- save current location
        local cursor1 = get_cursor_pos()
        local line1   = get_line_pos()

        -- look for the text
        if SearchNext() then
            -- NOTE: **** not sure why this is needed but it is **** 
            MarkHide()

            -- save current location
            cursor2 = get_cursor_pos()
            line2   = get_line_pos()

            -- move to the original location
            set_line_pos(line1, cursor1)

            -- start block mark mode from the current location
            MarkBlockSet()

            -- move to the original location
            set_line_pos(line2, cursor2)

            message("Search Pattern found.")
        else
            message("Search Pattern: '" .. pattern .. "' not found.")
        end

        -- restore the original search details
        search_options_restore()
    else
      message("Operation cancelled by user!")
    end
  else
    message("This macro only works for document files!")
    beep()
  end
end

key_macro() -- run the macro
dougclind
Posts: 14
Joined: Fri May 29, 2009 3:09 am

Post by dougclind »

Thanks much Jussi! I used your code as a starting point to do what I needed and it does work.
Post Reply