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.
Find below four very nice Lua scripts written by Petar Turkovic
I edited Petar's original posting by splitting the scripts into four individual post and adding a few examples to make them easier to understand
I also made a few minor changes to the scripts (i.e. search for the JAJ comments) to make the scritps run correctly without the need for the Brief column paste mode editor option.
The f_FillDnIns.LUA takes a marked area and takes the contents of the first line of the marked area and inserts it into all the other lines defined by the marked area.
So for example take the following text and mark the first three columns of all these lines:
-- ========================================================================
-- PROJECT : A5: Lua Macro
-- PROGRAM : f_FillDnIns.LUA Fill Down Marked Area - Insert
-- PROJECTOR : Turkovic Petar
-- PROGRAMER : Turkovic Petar
-- VERIFICATION : Jussi Jumppanen
-- == Standard: ===========================================================
-- 07.07.09 A5.50.1.1.2
-- == Description: ========================================================
-- This a simple Lua macro will fill down first row in the marked area.
-- Insert, shift text right
-- ========================================================================
------ Version_5 ----------------------------------------------------------
function key_macro()
---------------------------------------------------------------------------
-- macro only works for read/write documents.
if (is_read_only() == 1) or (is_document() == 0) then
message("This macro can only be used with a writable document.")
beep()
return
end
-- macro only works for marked documents
if is_marked() == 0 then
message("This macro needs a column marked area.")
beep()
return
end
-- get the marked text details
local l_top = get_marked_top()
local l_left = get_marked_left()
local l_bottom = get_marked_bottom()
local l_right = get_marked_right()
if l_top == l_bottom then
message("This macro needs at least 2 lines in marked area.")
beep()
return
end
if l_left == l_right then
message("This macro needs at least 1 column in marked area.")
beep()
return
end
-- disable screen updates
screen_update_disable()
cursor_save()
MarkHide()
-- copy first row
set_line_pos(l_top)
set_cursor_pos(l_left)
MarkColumnToggle() -- start marking
set_cursor_pos(l_right)
MarkCopyEx() -- copy marked area to clipboard
-- fill marked area
for i = 1, l_bottom - l_top, 1 do
-- JAJ position the cursor and don't rely on brief paste mode
set_line_pos(l_top + i)
set_cursor_pos(l_left)
MarkPasteEx()
end
-- mark area
set_line_pos(l_top)
set_cursor_pos(l_left)
MarkColumnToggle() -- start marking
set_line_pos(l_bottom)
set_cursor_pos(l_right)
cursor_restore()
-- restore screen updates
screen_update_enable()
return
end
key_macro() -- run the macro
-- ========================================================================
Last edited by jussij on Thu Jul 09, 2009 1:20 am, edited 3 times in total.
The f_FillDnOver.LUA takes a marked area and takes the contents of the first line of the marked area and overwites the text into all the other lines defined by the marked area.
So for example take the following text and mark the first three columns of all these lines:
-- ========================================================================
-- PROJECT : A5: Lua Macro
-- PROGRAM : f_FillDnOver.LUA Fill Down Marked Area - Over
-- PROJECTOR : Turkovic Petar
-- PROGRAMER : Turkovic Petar
-- VERIFICATION : Jussi Jumppanen
-- == Standard: ===========================================================
-- 07.07.09 A5.50.1.1.2
-- == Description: ========================================================
-- This a simple Lua macro will fill down first row in the marked area.
-- Fill over marked text
-- ========================================================================
------ Version_5 ----------------------------------------------------------
function key_macro()
---------------------------------------------------------------------------
if (is_read_only() == 1) or (is_document() == 0) then
message("This macro can only be used with a writable document.")
beep()
return
end
-- macro only works for marked documents
if is_marked() == 0 then
message("This macro needs a column marked area.")
beep()
return
end
-- get the marked text details
local l_top = get_marked_top()
local l_left = get_marked_left()
local l_bottom = get_marked_bottom()
local l_right = get_marked_right()
if l_top == l_bottom then
message("This macro needs at least 2 lines in marked area.")
beep()
return
end
if l_left == l_right then
message("This macro needs at least 1 column in marked area.")
beep()
return
end
-- disable screen updates
screen_update_disable()
cursor_save()
MarkHide()
-- copy first row
set_line_pos(l_top)
set_cursor_pos(l_left)
MarkColumnToggle() -- start marking
set_cursor_pos(l_right)
MarkCopyEx() -- copy marked area to clipboard
-- delete marked text
set_line_pos(l_top + 1)
set_cursor_pos(l_left)
MarkColumnToggle() -- start marking
set_line_pos(l_bottom)
set_cursor_pos(l_right)
MarkDelete()
-- fill marked area
for i = 1, l_bottom - l_top, 1 do
-- JAJ position the cursor and don't rely on brief paste mode
set_line_pos(l_top + i)
set_cursor_pos(l_left)
MarkPasteEx()
end
-- mark area
set_line_pos(l_top)
set_cursor_pos(l_left)
MarkColumnToggle() -- start marking
set_line_pos(l_bottom)
set_cursor_pos(l_right)
cursor_restore()
-- restore screen updates
screen_update_enable()
return
end
key_macro() -- run the macro
-- =========================================================================
Last edited by jussij on Thu Jul 09, 2009 1:17 am, edited 3 times in total.
The f_FillRightIns.LUA takes a marked area and takes left most character and insert it into the contents of each of the lines contained in the marked area. It uses the with of the marked area to determine how many times the first character need to be inserted.
So for example take the following text and mark the first four columns of all these lines:
-- =========================================================================
-- PROJECT : A5: Lua Macro
-- PROGRAM : f_FillRightIns.LUA Fill Right Marked Area - Insert
-- PROJECTOR : Turkovic Petar
-- PROGRAMER : Turkovic Petar
-- VERIFICATION : Jussi Jumppanen
-- == Standard: ============================================================
-- 07.07.09 A5.50.1.1.2
-- == Description: =========================================================
-- This a simple Lua macro will fill right first column in the marked area.
-- Insert, shift marked text right
-- =========================================================================
------ Version_5 -----------------------------------------------------------
function key_macro()
----------------------------------------------------------------------------
if (is_read_only() == 1) or (is_document() == 0) then
message("This macro can only be used with a writable document.")
beep()
return
end
-- macro only works for marked documents
if is_marked() == 0 then
message("This macro needs a column marked area.")
beep()
return
end
-- get the marked text details
local l_top = get_marked_top()
local l_left = get_marked_left()
local l_bottom = get_marked_bottom()
local l_right = get_marked_right()
-- JAJ changed 2 to be 1
if l_right <= l_left + 1 then
message("This macro needs at least 2 column in marked area.")
beep()
return
end
-- disable screen updates
screen_update_disable()
cursor_save()
MarkHide()
-- copy first column
set_line_pos(l_top)
set_cursor_pos(l_left)
MarkColumnToggle() -- start marking
set_line_pos(l_bottom)
set_cursor_pos(l_left + 1)
MarkCopyEx() -- copy marked area to clipboard
-- fill marked area
for i = 1, l_right - l_left - 1, 1 do
set_line_pos(l_top)
set_cursor_pos(l_left + 1)
MarkPasteEx()
end
-- mark area
set_line_pos(l_top)
set_cursor_pos(l_left)
MarkColumnToggle() -- start marking
set_line_pos(l_bottom)
set_cursor_pos(l_right)
cursor_restore()
-- restore screen updates
screen_update_enable()
return
end
key_macro() -- run the macro
-- =========================================================================
Last edited by jussij on Thu Jul 09, 2009 1:22 am, edited 3 times in total.
The f_FillRightOver.LUA takes a marked area and takes left most character and overwrites it into the contents of each of the lines contained in the marked area. It uses the width of the marked area to determine how many times the first character need to be inserted.
So for example take the following text and mark the first four columns of all these lines:
-- =========================================================================
-- PROJECT : A5: Lua Macro
-- PROGRAM : f_FillRightOver.LUA Fill Right Marked Area - Over
-- PROJECTOR : Turkovic Petar
-- PROGRAMER : Turkovic Petar
-- VERIFICATION : Jussi Jumppanen
-- == Standard: ============================================================
-- 07.07.09 A5.50.1.1.2
-- == Description: =========================================================
-- This a simple Lua macro will fill right first column in the marked area.
-- Fill over marked text
-- =========================================================================
------ Version_5 -----------------------------------------------------------
function key_macro()
----------------------------------------------------------------------------
if (is_read_only() == 1) or (is_document() == 0) then
message("This macro can only be used with a writable document.")
beep()
return
end
-- macro only works for marked documents
if is_marked() == 0 then
message("This macro needs a column marked area.")
beep()
return
end
-- get the marked text details
local l_top = get_marked_top()
local l_left = get_marked_left()
local l_bottom = get_marked_bottom()
local l_right = get_marked_right()
-- JAJ changed 2 to be 1
if l_right <= l_left + 1 then
message("This macro needs at least 2 column in marked area.")
beep()
return
end
-- disable screen updates
screen_update_disable()
cursor_save()
MarkHide()
-- copy first column
set_line_pos(l_top)
set_cursor_pos(l_left)
MarkColumnToggle() -- start marking
set_line_pos(l_bottom)
set_cursor_pos(l_left + 1)
MarkCopyEx() -- copy marked area to clipboard
-- delete marked text
set_line_pos(l_top)
set_cursor_pos(l_left + 1)
MarkColumnToggle() -- start marking
set_line_pos(l_bottom)
set_cursor_pos(l_right)
MarkDelete()
-- fill marked area
for i = 1, l_right - l_left - 1, 1 do
set_line_pos(l_top)
set_cursor_pos(l_left + 1)
MarkPasteEx()
end
-- mark area
set_line_pos(l_top)
set_cursor_pos(l_left)
MarkColumnToggle() -- start marking
set_line_pos(l_bottom)
set_cursor_pos(l_right)
cursor_restore()
-- restore screen updates
screen_update_enable()
return
end
key_macro() -- run the macro
-- =========================================================================
Last edited by jussij on Thu Jul 09, 2009 1:23 am, edited 1 time in total.
When I start learning Lua I read examples like this.
If that example have lines like ones which I delete, with no functionality but that lines not generate bug in execute, I was confused much better.
I was not see why this lines are there, I was know so litle about lua.
In that case I read that example over and over to try find why that lines must be there.
Please insert new code over old ones.
Edited by jussi: I have updated these macros with your new versions. Nice work
The f_FillDnLineIns.LUA takes a marked area and takes the entire contents of the first line of the marked area and inserts multiple copies of that line into the document. The number of copies of the line that are inserted is determined by the number of lines of the original marked area.
So for example take the following text and mark the first three columns of all these lines:
-- =========================================================================
-- PROJECT : A5: Lua Macro
-- PROGRAM : f_FillDnLineIns.LUA Fill Down Line - Insert
-- PROJECTOR : Turkovic Petar
-- PROGRAMER : Turkovic Petar
-- VERIFICATION :
-- == Standard: ============================================================
-- 08.07.09 19:47 A5.50.1.1.2
-- == Description: =========================================================
-- This a simple Lua macro will fill down first line in the marked area.
-- Lines will be inserted
-- =========================================================================
------ Version_5 -----------------------------------------------------------
function key_macro()
----------------------------------------------------------------------------
if (is_read_only() == 1) or (is_document() == 0) then
message("This macro can only be used with a writable document.")
beep()
return
end
-- macro only works for marked documents
if is_marked() == 0 then
message("This macro needs a column marked area.")
beep()
return
end
-- get the marked text details
local l_top = get_marked_top()
local l_bottom = get_marked_bottom()
local l_line
-- disable screen updates
screen_update_disable()
MarkHide()
set_line_pos(l_top) -- cursor in first line
l_line = get_line_text() -- get first line text
for i = 1, l_bottom - l_top, 1 do
MoveDocumentEndEx() -- Cursor to end of line
print("\n") -- New line
MoveDocumentStartEx() -- Cursor to start of line
print(l_line)
end
set_line_pos(l_bottom)
set_cursor_pos(1)
MarkLineToggle() -- start marking
set_line_pos(l_top)
-- restore screen updates
screen_update_enable()
return
end
key_macro() -- run the macro
-- =========================================================================