Quote Marked Area

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
Site Admin
Posts: 2547
Joined: Fri Aug 13, 2004 5:10 pm

Quote Marked Area

Post by jussij »

The macro below is designed to be bound to the quote (") character using the Options, Editor Options menu, Keyboard Mapping panel.

The macro will wrap any marked region of text in quotes.

Code: Select all

--        Name: Add Quote to Marked Area
--      Author: Jussi Jumppanen
--    Language: Lua Macro
-- Description: This macro is designed to be bound to the quote character
--              and it will wrap the marked area in quotes. If no marked
--              area is defined it just passes the event to the default
--              keybaord handler.
function key_macro()

  local processed = false

  if is_document() == 1 and is_read_only() == 0 then
    if is_marked() == 1 then
        -- disable screen updates

        -- get the marked text details
        top    = get_marked_top()
        left   = get_marked_left()
        bottom = get_marked_bottom()
        right  = get_marked_right()
        mode   = get_marked_mode()

        -- remnove the marked area

        -- insert the trailing quoted
        set_line_pos(bottom, right)

        -- insert the leading quoted
        set_line_pos(top, left)

        -- adjust the end of the marked region
        if top == bottom then
            right = right + 2
            right = right + 1

        -- apply the new marked region
        set_marked_area(mode, top, left, bottom, right)

        -- restore screen updates

        -- processing complete
        processed = true

  if processed == false then
    -- let the default handle the quote char

key_macro() -- run the macro
Post Reply