advice2020 left a comment (geany/geany-plugins#1463)

DELETE (NO DIALOG)
```
-- (cross-platform)
-- 2026.06.06
--[[
https://github.com/geany/geany-plugins/issues/1463
Line character limit = Delete
Line character limit = 10
No Dialog Version
]]

local function StringSplit(sdata, sdelim)
  local ares = {}
  local n1, n2, n3, c = 1, 1, 1, 1
  while true do
    n1, n2 = string.find(sdata, sdelim, n3, true)
    if n1 ~= nil then
      ares[c] = string.sub(sdata, n3, n1 - 1)
      c = c + 1
    else
      ares[c] = string.sub(sdata, n3, -1)
      break
    end
    n3 = n2 + 1
  end
  return ares
end

local function GetTableUTF8Char(s)
  local l = string.len(s)
  local i, j = 1, 1
  local t = {}
  local n
  -- rfc3629
  while true do
    if i > l then break end
    n = string.byte(s, i)
    if (n >= 0) and (n <= 127) then
      t[j] = string.sub(s, i, i)
      i = i + 1
    elseif (n >= 194) and (n <= 223) then
      t[j] = string.sub(s, i, i + 1)
      i = i + 2
    elseif (n >= 224) and (n <= 239) then
      t[j] = string.sub(s, i, i + 2)
      i = i + 3
    elseif (n >= 240) and (n <= 244) then
      t[j] = string.sub(s, i, i + 3)
      i = i + 4
    end
    j = j + 1
  end
  return t
end

local iNum = 10 --Change to desired character value to delete
local aEOL = {"\r\n", "\r", "\n"}
local iEOL = geany.scintilla("SCI_GETEOLMODE")
local sEOL = aEOL[iEOL + 1]

local bFullText = false
local sText = geany.selection()
if sText == nil then
  geany.message("Fail.")
  return
elseif sText == "" then
  sText = geany.text()
  bFullText = true
end

local aTmp
local aText = StringSplit(sText, sEOL)
for i = 1, #aText do
  aTmp = GetTableUTF8Char(aText[i])
  if #aTmp > iNum then
    aText[i] = table.concat(aTmp, "", 1, iNum)
  end
end
local sRes = table.concat(aText, sEOL)
if bFullText == true then
  geany.text(sRes)
else
  geany.selection(sRes)
end
```

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

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

Reply via email to