diff options
Diffstat (limited to 'tex/context/base/buff-ver.lua')
-rw-r--r-- | tex/context/base/buff-ver.lua | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/tex/context/base/buff-ver.lua b/tex/context/base/buff-ver.lua index 772008e39..e327a59dd 100644 --- a/tex/context/base/buff-ver.lua +++ b/tex/context/base/buff-ver.lua @@ -10,16 +10,16 @@ if not modules then modules = { } end modules ['buff-ver'] = { -- supposed to use different names for their own variants. -- -- todo: skip=auto --- --- todo: update to match context scite lexing -local type, next, rawset, rawget, setmetatable, getmetatable, tonumber = type, next, rawset, rawget, setmetatable, getmetatable, tonumber +local type, next, rawset, rawget, setmetatable, getmetatable = type, next, rawset, rawget, setmetatable, getmetatable local format, lower, upper,match, find, sub = string.format, string.lower, string.upper, string.match, string.find, string.sub local splitlines = string.splitlines local concat = table.concat local C, P, R, S, V, Carg, Cc, Cs = lpeg.C, lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.Carg, lpeg.Cc, lpeg.Cs local patterns, lpegmatch, is_lpeg = lpeg.patterns, lpeg.match, lpeg.is_lpeg +local context, commands = context, commands + local trace_visualize = false trackers.register("buffers.visualize", function(v) trace_visualize = v end) local report_visualizers = logs.reporter("buffers","visualizers") @@ -29,9 +29,6 @@ visualizers = visualizers or { } local specifications = allocate() visualizers.specifications = specifications -local context = context -local commands = commands - local tabtospace = utilities.strings.tabtospace local variables = interfaces.variables local settings_to_array = utilities.parsers.settings_to_array @@ -41,8 +38,6 @@ local addsuffix = file.addsuffix local v_auto = variables.auto local v_yes = variables.yes -local v_last = variables.last -local v_all = variables.all -- beware, all macros have an argument: @@ -573,7 +568,7 @@ local function realign(lines,strip) -- "yes", <number> if strip == v_yes then n = math.huge for i=1, #lines do - local spaces = find(lines[i],"%S") -- can be lpeg + local spaces = find(lines[i],"%S") if not spaces then -- empty line elseif spaces == 0 then @@ -597,13 +592,11 @@ local function realign(lines,strip) -- "yes", <number> return lines end -local onlyspaces = S(" \t\f\n\r")^0 * P(-1) - local function getstrip(lines,first,last) local first, last = first or 1, last or #lines for i=first,last do local li = lines[i] - if #li == 0 or lpegmatch(onlyspaces,li) then + if #li == 0 or find(li,"^%s*$") then first = first + 1 else break @@ -611,7 +604,7 @@ local function getstrip(lines,first,last) end for i=last,first,-1 do local li = lines[i] - if #li == 0 or lpegmatch(onlyspaces,li) then + if #li == 0 or find(li,"^%s*$") then last = last - 1 else break @@ -737,21 +730,14 @@ end -- parser so we use lpeg. -- -- [[\text ]] [[\text{}]] [[\text \text ]] [[\text \\ \text ]] --- --- needed in e.g. tabulate (manuals) -local compact_all = Cs((P("\\") * ((1-S("\\ "))^1) * (P(" ")/"") * (P(-1) + S("[{")) + 1)^0) -local compact_last = Cs((P(" ")^1 * P(-1)/"" + 1)^0) +----- strip = Cs((P(" ")^1 * P(-1)/"" + 1)^0) +local strip = Cs((P("\\") * ((1-S("\\ "))^1) * (P(" ")/"") + 1)^0) -- function commands.typestring(settings) local content = settings.data if content and content ~= "" then - local compact = settings.compact - if compact == v_all then - content = lpegmatch(compact_all,content) - elseif compact == v_last then - content = lpegmatch(compact_last,content) - end + content = #content > 1 and lpegmatch(strip,content) or content -- can be an option, but needed in e.g. tabulate -- content = decodecomment(content) -- content = dotabs(content,settings) visualize(content,checkedsettings(settings,"inline")) |