Mark Text Between Two Fold Points

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

Mark Text Between Two Fold Points

Post by jussij »

As the name suggests this macro will mark the text between two fold points. To use the macro place the cursor somewhere between the two folds points and run the macro.

Code: Select all

--
--        Name: Mark Folded Region
--
--      Author: Jussi Jumppanen
--
--    Language: Lua Macro
--
-- Description: This macro will mark the region between two fold points. To
--              use the macro place the cursor somewhere in between the fold
--              points and run the macro.
--

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

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

    screen_update_disable()
    cursor_save()

    if FoldingParentFindPrevious() == 1 then
        local y1 = get_line_pos()
        local x1 = get_cursor_pos()

        cursor_restore()
        if FoldingParentFindNext() == 1 then
            MoveLineEnd()
            local y2 = get_line_pos()
            local x2 = get_cursor_pos()

            -- values taken from Zeuus help file
            local MARK_LINE  = 1
            local MARK_BLOCK = 2

            -- use block mode to mark the region
            set_marked_area(MARK_BLOCK, y1, x1, y2, x2)

            -- uncomment to use line mode to mark the region
            --set_marked_area(MARK_LINE, y1, x1, y2, x2)
            return
        end
    else
        cursor_restore()
    end
    screen_update_enable()
    screen_update()

    message("No fold points found.")
end

key_macro() -- run the macro
Post Reply