I've written some simple scripts for a slightly extended bookmark handling. Using the scripts it's possible to toggle a bookmark for each line and cycle through them. As a side effect of having to use the global string database for storing the bookmarks, the bookmarks will be persistent even after restarting Zeus.
It may not be the most rock solid solution for each and every case but for me it's working well so far.
Save the code using the suggested filenames and map bookmarks_toggle.lua lua to ctrl-f2 and bookmarks_next.lua to f2 to get the commond handling used in most IDEs.
Regards,
Michael
Code: Select all
--
-- file bookmarks.lua
--
function bookmarks_read( name )
name = name or "unknown"
local tb = {}
local s = get_global_string( name ) or ""
local numlines = get_line_count()
for bl in string.gfind( s, "%d+" ) do
bl = tonumber(bl)
if bl < numlines then
table.insert( tb, bl )
end
end
table.sort( tb )
return tb
end
function bookmarks_write( name, tab )
name = name or "unknown"
local s = ""
for idx, bl in pairs(tab) do
s = s..bl.." "
end
set_global_string( name, s )
end
function bookmarks_next()
local fname = get_file_name()
local tab = bookmarks_read( fname )
local line = get_line_pos()
local numlines = get_line_count()
for idx, bl in pairs(tab) do
if bl > line then
if bl < numlines then
set_line_pos( bl )
return
end
end
end
if tab[1] ~= nil then
set_line_pos( tab[1] )
end
end
function bookmarks_toggle()
local fname = get_file_name()
local tab = bookmarks_read( fname )
local line = get_line_pos()
local idxat = nil
for idx, bl in pairs(tab) do
if bl == line then
idxat = idx
end
end
if idxat ~= nil then
table.remove( tab, idxat)
else
table.insert( tab, line )
table.sort( tab )
end
bookmarks_write( fname, tab )
end
Code: Select all
-- file bookmarks_toggle.lua
dofile( "bookmarks.lua" )
bookmarks_toggle() -- run the macro
Code: Select all
-- file bookmarks_next.lua
dofile( "bookmarks.lua" )
bookmarks_next() -- run the macro