summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/context/data/scite/scite-ctx.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/context/data/scite/scite-ctx.lua')
-rw-r--r--Master/texmf-dist/context/data/scite/scite-ctx.lua67
1 files changed, 49 insertions, 18 deletions
diff --git a/Master/texmf-dist/context/data/scite/scite-ctx.lua b/Master/texmf-dist/context/data/scite/scite-ctx.lua
index 3557994f383..546cac41197 100644
--- a/Master/texmf-dist/context/data/scite/scite-ctx.lua
+++ b/Master/texmf-dist/context/data/scite/scite-ctx.lua
@@ -70,7 +70,7 @@
props = props or { } -- setmetatable(props,{ __index = function(k,v) props[k] = "unknown" return "unknown" end } )
-local byte, lower, upper, gsub, sub, find, rep, match, gmatch = string.byte, string.lower, string.upper, string.gsub, string.sub, string.find, string.rep, string.match, string.gmatch
+local byte, lower, upper, gsub, sub, find, rep, match, gmatch, format = string.byte, string.lower, string.upper, string.gsub, string.sub, string.find, string.rep, string.match, string.gmatch, string.format
local sort, concat = table.sort, table.concat
local crlf = "\n"
@@ -80,7 +80,7 @@ function traceln(str)
io.flush()
end
-function string.grab(str,delimiter)
+local function grab(str,delimiter)
local list = { }
for snippet in gmatch(str,delimiter) do
list[#list+1] = snippet
@@ -88,15 +88,15 @@ function string.grab(str,delimiter)
return list
end
-function string.expand(str)
+local function expand(str)
return (gsub(str,"ENV%((%w+)%)", os.envvar))
end
-function string.strip(str)
+local function strip(str)
return (gsub(str,"^%s*(.-)%s*$", "%1"))
end
-function table.alphasort(list,i)
+local function alphasort(list,i)
if i and i > 0 then
local function alphacmp(a,b)
return lower(gsub(sub(a,i),'0',' ')) < lower(gsub(sub(b,i),'0',' '))
@@ -181,13 +181,16 @@ function extend_to_end() -- editor:LineEndExtend() does not work
while line == editor:LineFromPosition(selectionend+1) do
selectionend = selectionend + 1
editor:SetSel(selectionstart,selectionend)
+ if selectionend ~= editor.SelectionEnd then
+ break -- no progress
+ end
end
editor:SetSel(selectionstart,selectionend)
return selectionend
end
function getfiletype()
- local firstline = editor:GetLine(0)
+ local firstline = editor:GetLine(0) or ""
if editor.Lexer == SCLEX_TEX then
return 'tex'
elseif editor.Lexer == SCLEX_XML then
@@ -238,12 +241,12 @@ do
else
print("- 'ctxspellpath is not set")
end
- print("- ctx.spellcheck.wordpath expands to " .. string.expand(props['ctx.spellcheck.wordpath']))
+ print("- ctx.spellcheck.wordpath expands to " .. expand(props['ctx.spellcheck.wordpath']))
end
print("\n- ctx.wraptext.length is set to " .. props['ctx.wraptext.length'])
if props['ctx.helpinfo'] ~= '' then
print("\n- key bindings:\n")
- print((gsub(string.strip(props['ctx.helpinfo']),"%s*\|%s*","\n")))
+ print((gsub(strip(props['ctx.helpinfo']),"%s*|%s*","\n")))
end
print("\n- recognized first lines:\n")
print("xml <?xml version='1.0' language='nl'")
@@ -371,13 +374,13 @@ function sort_text()
local startcolumn = props['SelectionStartColumn'] - 1
local endcolumn = props['SelectionEndColumn'] - 1
+
startposition = extend_to_start()
endposition = extend_to_end()
local selection = gsub(editor:GetSelText(), "%s*$", '')
-
- list = string.grab(selection,"[^\n\r]+")
- table.alphasort(list, startcolumn)
+ local list = grab(selection,"[^\n\r]+")
+ alphasort(list, startcolumn)
local replacement = concat(list, "\n")
editor:GotoPos(startposition)
@@ -462,9 +465,9 @@ function quote_text()
end
local replacement = editor:GetSelText()
- replacement = gsub(replacement,"\`\`(.-)\'\'", leftquotation .. "%1" .. rightquotation)
+ replacement = gsub(replacement,"``(.-)\'\'", leftquotation .. "%1" .. rightquotation)
replacement = gsub(replacement,"\"(.-)\"", leftquotation .. "%1" .. rightquotation)
- replacement = gsub(replacement,"\`(.-)\'", leftquote .. "%1" .. rightquote )
+ replacement = gsub(replacement,"`(.-)`", leftquote .. "%1" .. rightquote )
replacement = gsub(replacement,"\'(.-)\'", leftquote .. "%1" .. rightquote )
editor:ReplaceSel(replacement)
@@ -475,9 +478,9 @@ function compound_text()
local filetype = getfiletype()
if filetype == 'xml' then
- editor:ReplaceSel(gsub(editor:GetSelText(),"(>[^<%-][^<%-]+)([-\/])(%w%w+)","%1<compound token='%2'/>%3"))
+ editor:ReplaceSel(gsub(editor:GetSelText(),"(>[^<%-][^<%-]+)([-/])(%w%w+)","%1<compound token='%2'/>%3"))
else
- editor:ReplaceSel(gsub(editor:GetSelText(),"([^\|])([-\/]+)([^\|])","%1|%2|%3"))
+ editor:ReplaceSel(gsub(editor:GetSelText(),"([^|])([-/]+)([^|])","%1|%2|%3"))
end
end
@@ -570,12 +573,12 @@ function check_text() -- obsolete, replaced by lexer
wordfile, worddone, wordlist = fname, 0, {}
for filename in gmatch(wordfile,"[^%,]+") do
if wordpath ~= '' then
- filename = string.expand(wordpath) .. '/' .. filename
+ filename = expand(wordpath) .. '/' .. filename
end
if io.exists(filename) then
traceln("loading " .. filename)
for line in io.lines(filename) do
- if not find(line,"^[\%\#\-]") then
+ if not find(line,"^[%#-]") then
str = gsub(line,"%s*$", '')
rawset(wordlist,str,true)
worddone = worddone + 1
@@ -644,6 +647,34 @@ function reset_text()
editor:SetStyling(editor.TextLength,INDIC_PLAIN)
end
+function add_text()
+
+ local startposition = editor.SelectionStart
+ local endposition = editor.SelectionEnd
+
+ if startposition == endposition then return end
+
+ local selection = gsub(editor:GetSelText(), "%s*$", '')
+
+ local n, sum = 0, 0
+ for s in gmatch(selection,"[%d%.%,]+") do
+ s = gsub(s,",",".")
+ local m = tonumber(s)
+ if m then
+ n = n + 1
+ sum = sum + m
+ traceln(format("%4i : %s",n,m))
+ end
+ end
+ if n > 0 then
+ traceln("")
+ traceln(format("sum : %s",sum))
+ else
+ traceln("no numbers selected")
+ end
+
+end
+
-- menu
local menuactions = {}
@@ -651,7 +682,7 @@ local menufunctions = {}
function UserListShow(menutrigger, menulist)
local menuentries = {}
- local list = string.grab(menulist,"[^%|]+")
+ local list = grab(menulist,"[^%|]+")
menuactions = {}
for i=1, #list do
if list[i] ~= '' then