Page 1 of 1

Mark Text Between Two Fold Points

Posted: Fri Aug 08, 2014 5:13 am
by jussij
As the name suggests this macro will mark the text between two fold points.

Code: Select all

-- 
--        Name: Mark Folded Region 
-- 
--      Author: Jussi Jumppanen 
-- 
--    Language: Lua Macro 
-- 
-- Description: This macro will mark the region between two fold points. 
-- 

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() 
            
            local MARK_BLOCK  = 2 

            set_marked_area(MARK_BLOCK, 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