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
screen_update_disable()
-- 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
MarkHide()
-- insert the trailing quoted
set_line_pos(bottom, right)
print("\"")
-- insert the leading quoted
set_line_pos(top, left)
print("\"")
-- adjust the end of the marked region
if top == bottom then
right = right + 2
else
right = right + 1
end
-- apply the new marked region
set_marked_area(mode, top, left, bottom, right)
-- restore screen updates
screen_update_enable()
-- processing complete
processed = true
end
end
if processed == false then
-- let the default handle the quote char
keyboard_default("\"")
end
end
key_macro() -- run the macro