summaryrefslogtreecommitdiff
path: root/context
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2021-10-11 00:26:56 +0200
committerContext Git Mirror Bot <phg@phi-gamma.net>2021-10-11 00:26:56 +0200
commitb2db36adbd89b2dba9591da5fc13b4eba57d581e (patch)
treefa1dd5b5b89dc4e56cf3aaf05d45e9b078f51d22 /context
parent778f381ba6a448ab00d67994a412dd4226d43238 (diff)
downloadcontext-b2db36adbd89b2dba9591da5fc13b4eba57d581e.tar.gz
2021-10-10 23:42:00
Diffstat (limited to 'context')
-rw-r--r--context/data/scite/context/lexers/scite-context-lexer-tex.lua123
-rw-r--r--context/data/scite/context/scite-ctx.lua28
2 files changed, 112 insertions, 39 deletions
diff --git a/context/data/scite/context/lexers/scite-context-lexer-tex.lua b/context/data/scite/context/lexers/scite-context-lexer-tex.lua
index a4aa83aa0..b1367f27d 100644
--- a/context/data/scite/context/lexers/scite-context-lexer-tex.lua
+++ b/context/data/scite/context/lexers/scite-context-lexer-tex.lua
@@ -9,7 +9,8 @@ local info = {
local string, table, lpeg = string, table, lpeg
local P, R, S, V, C, Cmt, Cp, Cc, Ct = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.C, lpeg.Cmt, lpeg.Cp, lpeg.Cc, lpeg.Ct
local type, next = type, next
-local find, match, lower, upper = string.find, string.match, string.lower, string.upper
+local concat = table.concat
+local find, match, lower, upper, gsub = string.find, string.match, string.lower, string.upper, string.gsub
local lexers = require("scite-context-lexer")
@@ -33,6 +34,8 @@ do -- todo: only once, store in global
-- commands helpers primitives
+ local collected = { }
+
local definitions = lexers.loaddefinitions("scite-context-data-interfaces")
if definitions then
@@ -65,7 +68,7 @@ do -- todo: only once, store in global
end
end
table.sort(used)
- report("context user interfaces '%s' supported",table.concat(used," "))
+ report("context user interfaces '%s' supported",concat(used," "))
end
local definitions = lexers.loaddefinitions("scite-context-data-context")
@@ -103,8 +106,8 @@ do -- todo: only once, store in global
add(definitions.tex,true)
add(definitions.etex,true)
add(definitions.pdftex,true)
- add(definitions.aleph,true)
- add(definitions.omega,true)
+ -- add(definitions.aleph,true)
+ -- add(definitions.omega,true)
add(definitions.luatex,true)
add(definitions.xetex,true)
end
@@ -169,14 +172,14 @@ local p_rest = any
local p_preamble = knownpreamble
local p_comment = commentline
------ p_command = backslash * knowncommand
+local p_command = backslash * knowncommand
----- p_constant = backslash * exactmatch(constants)
----- p_helper = backslash * exactmatch(helpers)
----- p_primitive = backslash * exactmatch(primitives)
local p_csdone = #(1-cstoken) + P(-1)
-local p_command = backslash * lexers.helpers.utfchartabletopattern(currentcommands) * p_csdone
+----- p_command = backslash * lexers.helpers.utfchartabletopattern(currentcommands) * p_csdone
local p_constant = backslash * lexers.helpers.utfchartabletopattern(constants) * p_csdone
local p_helper = backslash * lexers.helpers.utfchartabletopattern(helpers) * p_csdone
local p_primitive = backslash * lexers.helpers.utfchartabletopattern(primitives) * p_csdone
@@ -209,40 +212,41 @@ local p_word = C(iwordpattern) * Cp() / function(s,p) return sty
-- 2 : 10 sec
--
-- the problem is that quite some style subtables get generated so collapsing ranges helps
+-- although in the new scite approach this is less an issue (no lua tables)
-local option = 1
-
-if option == 1 then
-
- p_comment = p_comment^1
- p_grouping = p_grouping^1
- p_special = p_special^1
- p_extra = p_extra^1
-
- p_command = p_command^1
- p_constant = p_constant^1
- p_helper = p_helper^1
- p_primitive = p_primitive^1
- p_ifprimitive = p_ifprimitive^1
- p_reserved = p_reserved^1
-
-elseif option == 2 then
-
- local included = space^0
-
- p_comment = (p_comment * included)^1
- p_grouping = (p_grouping * included)^1
- p_special = (p_special * included)^1
- p_extra = (p_extra * included)^1
-
- p_command = (p_command * included)^1
- p_constant = (p_constant * included)^1
- p_helper = (p_helper * included)^1
- p_primitive = (p_primitive * included)^1
- p_ifprimitive = (p_ifprimitive * included)^1
- p_reserved = (p_reserved * included)^1
+local option = 0 -- otherwise we get e.g. \btx... and \xml... in commands colors ...
-end
+-- if option == 1 then
+--
+-- p_comment = p_comment^1
+-- p_grouping = p_grouping^1
+-- p_special = p_special^1
+-- p_extra = p_extra^1
+--
+-- p_command = p_command^1
+-- p_constant = p_constant^1
+-- p_helper = p_helper^1
+-- p_primitive = p_primitive^1
+-- p_ifprimitive = p_ifprimitive^1
+-- p_reserved = p_reserved^1
+--
+-- elseif option == 2 then
+--
+-- local included = space^0
+--
+-- p_comment = (p_comment * included)^1
+-- p_grouping = (p_grouping * included)^1
+-- p_special = (p_special * included)^1
+-- p_extra = (p_extra * included)^1
+
+-- p_command = (p_command * included)^1
+-- p_constant = (p_constant * included)^1
+-- p_helper = (p_helper * included)^1
+-- p_primitive = (p_primitive * included)^1
+-- p_ifprimitive = (p_ifprimitive * included)^1
+-- p_reserved = (p_reserved * included)^1
+--
+-- end
local p_invisible = invisibles^1
@@ -493,4 +497,47 @@ contextlexer.folding = {
},
}
+do
+
+ local lastcurrent = nil
+ local allcommands = { }
+
+ function contextlexer.completion(str)
+ if currentcommands then
+ if lastcurrent ~= currentcommands then
+ allcommands = { }
+ for k, v in next, currentcommands do
+ allcommands[#allcommands+1] = "\\" .. k
+ end
+ for k, v in next, helpers do
+ allcommands[#allcommands+1] = "\\" .. k
+ end
+ for k, v in next, primitives do
+ allcommands[#allcommands+1] = "\\" .. k
+ end
+ -- for k, v in next, constants do
+ -- allcommands[#constants+1] = "\\" .. k
+ -- end
+ lastcurrent = currentcommands
+ table.sort(allcommands)
+ end
+ if find(str,"^\\") then
+ local str = "^" .. str
+ local list = { }
+ local n = 0
+ for i=1,#allcommands do
+ local c = allcommands[i]
+ if find(c,str) then
+ n = n + 1 ; list[n] = c
+ end
+ end
+ if n > 0 then
+ return list and concat(list," ")
+ end
+ end
+ end
+ end
+
+end
+
return contextlexer
diff --git a/context/data/scite/context/scite-ctx.lua b/context/data/scite/context/scite-ctx.lua
index 73ef06719..4bde33d2b 100644
--- a/context/data/scite/context/scite-ctx.lua
+++ b/context/data/scite/context/scite-ctx.lua
@@ -415,8 +415,9 @@ do
print("\n- recognized first lines:\n")
print("xml <?xml version='1.0' language='..'")
print("tex % language=..")
- print("")
+ print(" ")
print("(lexing is currently being upgraded / improved / made more native to scite)")
+ print(" ")
end
@@ -1797,4 +1798,29 @@ do
check_output_pane()
end
+ function OnChar()
+ if not editor:AutoCActive() then
+ local syntax = loadedlexers[props.Language]
+ if syntax and syntax.completion then
+ local stop = editor.CurrentPos
+ local start = editor:WordStartPosition(stop,true)
+ local length = stop - start
+ if length >= 2 then
+ local snippet = editor:textrange(start,stop)
+ local list = syntax.completion(snippet)
+ if list then
+ editor.AutoCMaxHeight = 30
+ editor.AutoCSeparator = 32
+ editor:AutoCShow(length,list)
+ end
+ end
+ end
+ end
+ end
+
end
+
+-- function OnKey(a,b,c)
+-- print("key",a,b,c)
+-- end
+