diff options
author | Mojca Miklavec <mojca.miklavec@gmail.com> | 2012-05-14 17:38:55 +0000 |
---|---|---|
committer | Mojca Miklavec <mojca.miklavec@gmail.com> | 2012-05-14 17:38:55 +0000 |
commit | 15995e10bfc68edf79970c4ea4fbb6678566c46e (patch) | |
tree | 2de7ca2a83f2d37ef043ad7429a5cb945bb79ddb /Master/texmf-dist/tex/context/base/strc-mar.lua | |
parent | c9a39f716f1e5ec820ed3aab2c9aef25c5a9d730 (diff) |
ConTeXt 2012.05.14 16:00
git-svn-id: svn://tug.org/texlive/trunk@26371 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-mar.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/strc-mar.lua | 123 |
1 files changed, 98 insertions, 25 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-mar.lua b/Master/texmf-dist/tex/context/base/strc-mar.lua index 5bb40fa94e3..66ec047394d 100644 --- a/Master/texmf-dist/tex/context/base/strc-mar.lua +++ b/Master/texmf-dist/tex/context/base/strc-mar.lua @@ -7,10 +7,12 @@ if not modules then modules = { } end modules ['strc-mar'] = { } -- todo: cleanup stack (structures.marks.reset(v_all) also does the job) +-- todo: only commands.* print to tex, native marks return values local insert, concat = table.insert, table.concat local tostring, next, rawget = tostring, next, rawget local lpegmatch = lpeg.match +local match = string.match local allocate = utilities.storage.allocate local setmetatableindex = table.setmetatableindex @@ -45,6 +47,7 @@ local v_current = variables.current local v_default = variables.default local v_page = variables.page local v_all = variables.all +local v_keep = variables.keep local v_nocheck_suffix = ":" .. variables.nocheck @@ -130,21 +133,33 @@ local classes = { } setmetatableindex(classes, function(t,k) local s = settings_to_array(k) t[k] = s return s end) -function marks.synchronize(class,n) +local lasts = { } + +function marks.synchronize(class,n,option) local box = texbox[n] if box then local first, last = sweep(box.list,0,0) - local classlist = classes[class] - for i=1,#classlist do - local class = classlist[i] - local range = ranges[class] - if not range then - range = { } - ranges[class] = range - end - range.first, range.last = first, last + if option == v_keep and first == 0 and last == 0 then if trace_marks_get or trace_marks_set then - report_marks("synchronize: class=%s, first=%s, last=%s",class,range.first,range.last) + report_marks("synchronize: class=%s, box=%s, retaining",class,n) + end + -- todo: check if still valid firts/last in range + first = lasts[class] or 0 + last = first + else + lasts[class] = last + local classlist = classes[class] + for i=1,#classlist do + local class = classlist[i] + local range = ranges[class] + if not range then + range = { } + ranges[class] = range + end + range.first, range.last = first, last + if trace_marks_get or trace_marks_set then + report_marks("synchronize: class=%s, first=%s, last=%s",class,range.first,range.last) + end end end elseif trace_marks_get or trace_marks_set then @@ -180,7 +195,7 @@ function marks.define(name,settings) settings = settings or { } data[name] = settings local parent = settings.parent - if parent == nil or parent == "" then + if parent == nil or parent == "" or parent == name then settings.parent = false else local dp = data[parent] @@ -274,7 +289,7 @@ function marks.set(name,value) report_marks("set: parent=%s, child=%s, index=%s, value=%s",parent,child,topofstack,value) end end - tex.setattribute("global",a_marks,topofstack) + texsetattribute("global",a_marks,topofstack) end end @@ -479,6 +494,15 @@ local function doresolve(name,rangename,swap,df,dl,strict) return value, index, found end +-- previous : last before sync +-- next : first after sync + +-- top : first in sync +-- bottom : last in sync + +-- first : first not top in sync +-- last : last not bottom in sync + methods[v_previous] = function(name,range) return doresolve(name,range,false,-1,0,true ) end -- strict methods[v_top] = function(name,range) return doresolve(name,range,false, 0,0,true ) end -- strict methods[v_bottom] = function(name,range) return doresolve(name,range,true , 0,0,true ) end -- strict @@ -489,27 +513,66 @@ methods[v_top_nocheck] = function(name,range) return doresolve(name,range,f methods[v_bottom_nocheck] = function(name,range) return doresolve(name,range,true , 0,0,false) end methods[v_next_nocheck] = function(name,range) return doresolve(name,range,true , 0,1,false) end -local function resolve(name,range,f_swap,l_swap,step,strict) -- we can have an offset - local f_value, f_index, f_found = doresolve(name,range,f_swap,0,0,strict) - local l_value, l_index, l_found = doresolve(name,range,l_swap,0,0,strict) +local function do_first(name,range,check) + if trace_marks_get then + report_marks("resolve: name=%s, range=%s, resolve first",name,range) + end + local f_value, f_index, f_found = doresolve(name,range,false,0,0,check) + if trace_marks_get then + report_marks("resolve: name=%s, range=%s, resolve last",name,range) + end + local l_value, l_index, l_found = doresolve(name,range,true ,0,0,check) if f_found and l_found and l_index > f_index then local name = parentname(name) - for i=f_index,l_index,step do + for i=f_index,l_index,1 do local si = stack[i] local sn = si[name] if sn and sn ~= false and sn ~= true and sn ~= "" and sn ~= f_value then + if trace_marks_get then + report_marks("resolve: name=%s, range=%s, index=%s, value=%s",name,range,i,sn) + end return sn, i, si end end end + if trace_marks_get then + report_marks("resolve: name=%s, range=%s, using first",name,range) + end return f_value, f_index, f_found end -methods[v_first ] = function(name,range) return resolve(name,range,false,true, 1,true ) end -- strict -methods[v_last ] = function(name,range) return resolve(name,range,true,false,-1,true ) end -- strict +local function do_last(name,range,check) + if trace_marks_get then + report_marks("resolve: name=%s, range=%s, resolve first",name,range) + end + local f_value, f_index, f_found = doresolve(name,range,false,0,0,check) + if trace_marks_get then + report_marks("resolve: name=%s, range=%s, resolve last",name,range) + end + local l_value, l_index, l_found = doresolve(name,range,true ,0,0,check) + if f_found and l_found and l_index > f_index then + local name = parentname(name) + for i=l_index,f_index,-1 do + local si = stack[i] + local sn = si[name] + if sn and sn ~= false and sn ~= true and sn ~= "" and sn ~= l_value then + if trace_marks_get then + report_marks("resolve: name=%s, range=%s, index=%s, value=%s",name,range,i,sn) + end + return sn, i, si + end + end + end + if trace_marks_get then + report_marks("resolve: name=%s, range=%s, using last",name,range) + end + return l_value, l_index, l_found +end -methods[v_first_nocheck] = function(name,range) return resolve(name,range,false,true, 1,false) end -methods[v_last_nocheck ] = function(name,range) return resolve(name,range,true,false,-1,false) end +methods[v_first ] = function(name,range) return do_first(name,range,true ) end +methods[v_last ] = function(name,range) return do_last (name,range,true ) end +methods[v_first_nocheck] = function(name,range) return do_first(name,range,false) end +methods[v_last_nocheck ] = function(name,range) return do_last (name,range,false) end methods[v_current] = function(name,range) -- range is ignored here local top = stack[topofstack] @@ -592,15 +655,25 @@ function marks.fetchonemark (name,range,method) fetchonemark (name,range,method) function marks.fetchtwomarks(name,range) fetchtwomarks(name,range ) end function marks.fetchallmarks(name,range) fetchallmarks(name,range ) end --- here we have a few helpers +-- here we have a few helpers .. will become commands.* function marks.title(tag,n) - lists.savedtitle(tag,n,"marking") + local listindex = match(n,"^li::(.-)$") + if listindex then + commands.savedlisttitle(tag,listindex,"marking") + else + context(n) + end end function marks.number(tag,n) -- no spec - -- no prefix (as it is the prefix) - lists.savednumber(tag,n) + local listindex = match(n,"^li::(.-)$") + if listindex then + commands.savedlistnumber(tag,listindex) + else + -- no prefix (as it is the prefix) + context(n) + end end -- interface |