Skif-off left a comment (geany/geany-plugins#1560)

Maybe something like
```lua
-- bookmarks-save.lua (cross-platform)
-- 2026.06.07
--[[
https://github.com/geany/geany-plugins/issues/1560
]]

local sD = geany.appinfo().configdir
local sBF = sD .. geany.dirsep .. "bookmarks.txt"

local sCF = geany.filename()
if sCF == nil then
  geany.message("There is no open document or the current document is 
untitled.")
  return
end

local function GetBookmarks()
  local sR, n1, n2
  -- SCI_MARKERGET
  if geany.scintilla(2046, 0, 1) ~= 0 then
    sR = ";0"
  else
    sR = ""
  end
  n2 = 0
  while true do
    -- SCI_MARKERNEXT
    n1 = geany.scintilla(2047, n2 + 1, 0x2)
    if n1 == -1 then break end
    sR = sR .. ";" .. tostring(n1)
    n2 = n1
  end
  return string.sub(sR, 2, -1)
end

local aBase = {}

local h, e, sT, iC
local bB = geany.stat(sBF)
if bB ~= nil then
  h, e = io.open(sBF, "rb")
  if h == nil then
    geany.message("Error: " .. e)
    return
  end
  sT = h:read("*a")
  h:close()
  iC = 1
  for l in string.gmatch(sT, "[^\n]+") do
    aBase[iC] = l
    iC = iC + 1
  end
end

local bD, bR = false, false

local sB = GetBookmarks()

if sB == "" then bR = true end

if #aBase == 0 then
  if bR == false then
    aBase[1] = sCF .. "=" .. sB
  end
else
  for i = 1, #aBase do
    iC = string.find(aBase[i], "=", 1, true)
    if string.sub(aBase[i], 1, iC - 1) == sCF then
      if bR == true then
        table.remove(aBase, i)
      else
        aBase[i] = sCF .. "=" .. sB
      end
      bD = true
    end
  end
  if bD == false then
    if bR == false then
      aBase[#aBase + 1] = sCF .. "=" .. sB
    end
  end
end

local sM
if bB == nil then sM = "wb" else sM = "w+b" end
if #aBase == 0 then
  os.remove(sBF)
else
  h = io.open(sBF, sM)
  h:write(table.concat(aBase, "\n"))
  h:close()
end
```
```lua
-- bookmarks-load.lua (cross-platform)
-- 2026.06.07
--[[
https://github.com/geany/geany-plugins/issues/1560
]]

local sD = geany.appinfo().configdir
local sBF = sD .. geany.dirsep .. "bookmarks.txt"

local sCF = geany.filename()
if sCF == nil then
  geany.message("There is no open document or the current document is 
untitled.")
  return
end

local aBase = {}

local h, e, sT, iC
local bB = geany.stat(sBF)
if bB == nil then
  geany.message("The list of files with bookmarks not found.")
  return
else
  h, e = io.open(sBF, "rb")
  if h == nil then
    geany.message("Error: " .. e)
    return
  end
  sT = h:read("*a")
  h:close()
  iC = 1
  for l in string.gmatch(sT, "[^\n]+") do
    aBase[iC] = l
    iC = iC + 1
  end
end

local bD = false
for i = 1, #aBase do
  iC = string.find(aBase[i], "=", 1, true)
  if string.sub(aBase[i], 1, iC - 1) == sCF then
    sT = string.sub(aBase[i], iC + 1, -1)
    bD = true
    break
  end
end

if bD == false then
  geany.message("Bookmarks not found.")
  return
else
  -- SCI_MARKERADD
  for l in string.gmatch(sT, "%d+") do
    geany.scintilla(2043, tonumber(l), 1)
  end
end
```
```lua
-- bookmarks-delete.lua (cross-platform)
-- 2026.06.07
--[[
https://github.com/geany/geany-plugins/issues/1560
]]

local sD = geany.appinfo().configdir
local sBF = sD .. geany.dirsep .. "bookmarks.txt"

local sCF = geany.filename()
if sCF == nil then
  geany.message("There is no open document or the current document is 
untitled.")
  return
end

local aBase = {}

local h, e, sT, iC
-- SCI_MARKERGET
if geany.scintilla(2046, 0, 1) ~= 0 then
  -- SCI_MARKERDELETE
  geany.scintilla(2044, 0, 1)
end
while true do
  -- SCI_MARKERNEXT
  iC = geany.scintilla(2047, 0, 0x2)
  if iC == -1 then break end
  -- SCI_MARKERDELETE
  geany.scintilla(2044, iC, 1)
end

local bB = geany.stat(sBF)
if bB == nil then
  return
else
  h, e = io.open(sBF, "rb")
  if h == nil then
    geany.message("Error: " .. e)
    return
  end
  sT = h:read("*a")
  h:close()
  iC = 1
  for l in string.gmatch(sT, "[^\n]+") do
    aBase[iC] = l
    iC = iC + 1
  end
end

if #aBase == 0 then return end
local bM = false
for i = 1, #aBase do
  iC = string.find(aBase[i], "=", 1, true)
  if string.sub(aBase[i], 1, iC - 1) == sCF then
    table.remove(aBase, i)
    bM = true
    break
  end
end

if #aBase == 0 then
  os.remove(sBF)
else
  if bM == false then return end
  h = io.open(sBF, "w+b")
  h:write(table.concat(aBase, "\n"))
  h:close()
end
```
Script names in the first lines.
In theory, cross-platform scripts.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/issues/1560#issuecomment-4668196824
You are receiving this because you are subscribed to this thread.

Message ID: <geany/geany-plugins/issues/1560/[email protected]>

Reply via email to