Of coarse you can makes changes for your own language.
Tabs will be inserted as spaces.
1st tab stop at position 8
2nd tab stop at postions 12
After position 12 it will look at lines above where the next word will begin. If no word can be found it will use 4 spaces.
When a selection has been made the selected lines will be indented in 2 possible ways:
When the line before the selected area starts at a higher position than the first line of the selected area, the lines will indented to the position of the line before the selected line.
When not it will be indented 3 positions higher that the line before the selected area (it will be indented backward when the position of the selected area is already more than 3).
Only lines which have colomn 1-11 empty will be indented. So comment lines or paragraph names will be untouched.
Code: Select all
function coboltab_macro()
screen_update_disable()
local int bottom = 0
local int pos = get_cursor_pos()
local marked = is_marked()
if marked == 1 then
local int found = 0
local int b = 0
-- get the marked text details
top = get_marked_top()
bottom = get_marked_bottom()
MarkHide()
cursor_save()
set_line_pos(top)
local string msg = ""
repeat
MoveLineUp()
MoveLineHome()
MoveWordNext()
b = get_cursor_pos()
until (b >= 12 or get_line_pos() == 1)
set_line_pos(top - 1)
repeat
MoveLineDown()
MoveLineHome()
MoveWordNext()
until (get_cursor_pos() >= 12)
pos = get_cursor_pos()
local int i = 0
if (pos < b) then
i = b - pos
else
i = b - pos + 3
end -- if
b = i
local string ident = ""
while (i > 0) do
ident = ident.." "
i = i - 1
end -- while
while (top <= bottom) do
set_line_pos(top)
if (get_char_at(top,7) == 32 and get_char_at(top,8) == 32) then
MoveLineHome()
if (i < 0) then
local int r = i
while (r < 0) do
MarkDeleteEx()
r = r + 1
end -- while
else
print(ident)
MoveLineEnd()
MoveLineLeft()
if (get_char_at() == 46) then
MarkDeleteEx()
end -- if
end -- if
end -- if
top = top + 1
end -- while
cursor_restore()
i = get_cursor_pos() + b
set_cursor_pos(i)
else
local int b = 0
local int line = get_line_pos()
if (pos < 12) then
if pos < 8 then
b = 8
else
b = 12
end -- if
else
if (get_char_at() == 32) then
MoveWordNext()
pos = get_cursor_pos()
end -- if
while (get_line_pos() > 1 and b == 0) do
MoveLineUp()
if (get_char_at() ~= 0) then
while (get_char_at() ~= 32 and get_char_at() ~= 0) do
MoveLineRight()
end -- while
-- while (get_char_at() == 32) do
-- MoveLineRight()
-- end -- while
MoveWordNext()
if (get_char_at() ~= 0) then
b = get_cursor_pos()
else
set_cursor_pos(pos)
end -- if
end -- if
end -- while
set_line_pos(line,pos)
if (b <= pos) then
b = pos + 4
end -- if
end -- if
repeat
print(" ")
pos = pos + 1
until (pos >= b)
end -- if
screen_update_enable()
screen_update()
end
coboltab_macro() -- run the macro