summaryrefslogtreecommitdiff
path: root/context/data/scite/scite-ctx.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2013-01-14 00:20:22 +0200
committerMarius <mariausol@gmail.com>2013-01-14 00:20:22 +0200
commitfe55ae49d8deddeb8f02557e3902c847804b0086 (patch)
treee7d92e04f7acaf2773c23ea081c4d2fe0dc0a167 /context/data/scite/scite-ctx.lua
parentd38d94fe9542984e38b9839eb2383656328b9da9 (diff)
downloadcontext-fe55ae49d8deddeb8f02557e3902c847804b0086.tar.gz
beta 2013.01.13 23:10
Diffstat (limited to 'context/data/scite/scite-ctx.lua')
-rw-r--r--context/data/scite/scite-ctx.lua46
1 files changed, 37 insertions, 9 deletions
diff --git a/context/data/scite/scite-ctx.lua b/context/data/scite/scite-ctx.lua
index be3718043..546cac411 100644
--- a/context/data/scite/scite-ctx.lua
+++ b/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"
@@ -190,7 +190,7 @@ function extend_to_end() -- editor:LineEndExtend() does not work
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
@@ -246,7 +246,7 @@ do
print("\n- ctx.wraptext.length is set to " .. props['ctx.wraptext.length'])
if props['ctx.helpinfo'] ~= '' then
print("\n- key bindings:\n")
- print((gsub(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'")
@@ -379,7 +379,7 @@ function sort_text()
endposition = extend_to_end()
local selection = gsub(editor:GetSelText(), "%s*$", '')
- list = grab(selection,"[^\n\r]+")
+ local list = grab(selection,"[^\n\r]+")
alphasort(list, startcolumn)
local replacement = concat(list, "\n")
@@ -465,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)
@@ -478,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
@@ -578,7 +578,7 @@ function check_text() -- obsolete, replaced by lexer
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
@@ -647,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 = {}