Page 1 of 1

Prompted Slide-In/Out Scripts

Posted: Sat Dec 21, 2013 3:53 am
by aphor
Macros to replace Prompted Slide-in/Slide-out from CodeWright. comment_range() and uncomment_range() do the heavy lifting, these just set the column and range along with prompting the user for the slide text.

Prompted Slide-in

Code: Select all

--        Name: PromptedSlideIn
-- Description: Prefix select block with user provided text
dofile ("AS_NotDoc.LUA")  -- #include file
dofile ("commentText.LUA")  -- #include file

function key_bind()
    -- macro only works for writable documents so do a check
    if (NotDocument() == 1) then
        message("Document is read-only!")
        return
    end

    -- macro only works for marked documents
    if (is_marked() == 0)  then
        message("No text selected!")
        return
    end

    local top   = get_marked_top()
    local range = get_marked_bottom() - top + 1
    local col   = get_marked_left()

    -- ask for a user for slide text
    local slideText = user_input("Slide Text:", "")

    -- disable screen updates
    screen_update_disable()

    -- save the current cursor
    cursor_save()

    -- move to the fist line of the commented text
    set_line_pos(top)

    -- get the first line of text
    comment_range(range, slideText, nil, col)

    -- restore original cursor
    cursor_restore()

    -- restore screen updates
    screen_update_enable()
end

key_bind() -- run the macro
Prompted Slide-Out

Code: Select all

--        Name: PromptedSlideOut
-- Description: Strip user provided text from select block.
dofile ("AS_NotDoc.LUA")  -- #include file
dofile ("commentText.LUA")  -- #include file

function key_bind()
    -- macro only works for writable documents so do a check
    if (NotDocument() == 1) then
        message("Document is read-only!")
        return
    end

    -- macro only works for marked documents
    if (is_marked() == 0)  then
        message("No text selected!")
        return
    end

    local top   = get_marked_top()
    local range = get_marked_bottom() - top + 1
    local col   = get_marked_left()

    -- ask for a user for slide text
    local slideText = user_input("Slide Text:", "")

    -- disable screen updates
    screen_update_disable()

    -- save the current cursor
    cursor_save()

    -- move to the fist line of the commented text
    set_line_pos(top)

    -- get the first line of text
    uncomment_range(range, slideText, nil, col)

    -- restore original cursor
    cursor_restore()

    -- restore screen updates
    screen_update_enable()
end

key_bind() -- run the macro