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

ENTER NEXT LINE (NO DIALOG)
```lua
-- (cross-platform)
-- 2026.06.06
--[[
https://github.com/geany/geany-plugins/issues/1463
Line character limit = Enter next line
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 enter next line
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, sTmp, iC, bR
local aRes = {}
local aText = StringSplit(sText, sEOL)
for i = 1, #aText do
  aTmp = GetTableUTF8Char(aText[i])
  if #aTmp > iNum then
    iC = 0
    while true do
      bR, sTmp = pcall(table.concat, aTmp, "", iC + 1, iC + iNum)
      if bR == false then
        if aTmp[iC + 1] ~= nil then
          sTmp = table.concat(aTmp, "", iC + 1, #aTmp)
          table.insert(aRes, sTmp)
        else
          break
        end
      else
        table.insert(aRes, sTmp)
      end
      iC = iC + iNum
    end
  else
    table.insert(aRes, aText[i])
  end
end
local sRes = table.concat(aRes, 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-4640833852
You are receiving this because you are subscribed to this thread.

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

Reply via email to