diff options
author | Marius <mariausol@gmail.com> | 2012-10-19 01:20:13 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2012-10-19 01:20:13 +0300 |
commit | 69d2352af4b60929b37fc49f3bdb263977016244 (patch) | |
tree | db5eb11398e345dfa23b4c4500fb93575d2afb7c /tex/context/base/strc-not.lua | |
parent | c18f7cbe51449a611ea1819fedd9a4ff18529b7d (diff) | |
download | context-69d2352af4b60929b37fc49f3bdb263977016244.tar.gz |
stable 2012.05.30 11:26
Diffstat (limited to 'tex/context/base/strc-not.lua')
-rw-r--r-- | tex/context/base/strc-not.lua | 180 |
1 files changed, 67 insertions, 113 deletions
diff --git a/tex/context/base/strc-not.lua b/tex/context/base/strc-not.lua index d71b371ab..6a3f3bfad 100644 --- a/tex/context/base/strc-not.lua +++ b/tex/context/base/strc-not.lua @@ -13,19 +13,18 @@ local texcount = tex.count local trace_notes = false trackers.register("structures.notes", function(v) trace_notes = v end) local trace_references = false trackers.register("structures.notes.references", function(v) trace_references = v end) -local report_notes = logs.reporter("structure","notes") +local report_notes = logs.reporter("structure","notes") -local structures = structures -local helpers = structures.helpers -local lists = structures.lists -local sections = structures.sections -local counters = structures.counters -local notes = structures.notes -local references = structures.references -local counterspecials = counters.specials +local structures = structures +local helpers = structures.helpers +local lists = structures.lists +local sections = structures.sections +local counters = structures.counters +local notes = structures.notes +local references = structures.references -notes.states = notes.states or { } -lists.enhancers = lists.enhancers or { } +notes.states = notes.states or { } +lists.enhancers = lists.enhancers or { } storage.register("structures/notes/states", notes.states, "structures.notes.states") @@ -34,18 +33,10 @@ local notedata = { } local variables = interfaces.variables local context = context -local commands = commands -- state: store, insert, postpone -local function store(tag,n) - -- somewhat weird but this is a cheap hook spot - if not counterspecials[tag] then - counterspecials[tag] = function(tag) - context.doresetlinenotecompression(tag) -- maybe flag that controls it - end - end - -- +function notes.store(tag,n) local nd = notedata[tag] if not nd then nd = { } @@ -62,13 +53,7 @@ local function store(tag,n) end state.start = state.start or nnd end - return #nd -end - -notes.store = store - -function commands.storenote(tag,n) - context(store(tag,n)) + context(#nd) end local function get(tag,n) -- tricky ... only works when defined @@ -99,59 +84,16 @@ notes.getn = getn -- we could make a special enhancer -local function listindex(tag,n) +function notes.listindex(tag,n) local ndt = notedata[tag] return ndt and ndt[n] end -notes.listindex = listindex - -function commands.notelistindex(tag,n) - context(listindex(tag,n)) -end - -local function setstate(tag,newkind) - local state = notestates[tag] - if trace_notes then - report_notes("setting state of '%s' from %s to %s",tag,(state and state.kind) or "unset",newkind) - end - if not state then - state = { - kind = newkind - } - notestates[tag] = state - elseif newkind == "insert" then - if not state.start then - state.kind = newkind - end - else - state.kind = newkind - end - -- state.start can already be set and will be set when an entry is added or flushed - return state -end - -local function getstate(tag) - local state = notestates[tag] - return state and state.kind or "unknown" -end - -notes.setstate = setstate -notes.getstate = getstate - -commands.setnotestate = setstate - -function commands.getnotestate(tag) - context(getstate(tag)) -end - function notes.define(tag,kind,number) - local state = setstate(tag,kind) + local state = notes.setstate(tag,kind) state.number = number end -commands.definenote = notes.define - function notes.save(tag,newkind) local state = notestates[tag] if state and not state.saved then @@ -179,10 +121,33 @@ function notes.restore(tag,forcedstate) end end -commands.savenote = notes.save -commands.restorenote = notes.restore +function notes.setstate(tag,newkind) + local state = notestates[tag] + if trace_notes then + report_notes("setting state of '%s' from %s to %s",tag,(state and state.kind) or "unset",newkind) + end + if not state then + state = { + kind = newkind + } + notestates[tag] = state + elseif newkind == "insert" then + if not state.start then + state.kind = newkind + end + else + state.kind = newkind + end + -- state.start can already be set and will be set when an entry is added or flushed + return state +end + +function notes.getstate(tag) + local state = notestates[tag] + context(state and state.kind or "unknown") +end -local function hascontent(tag) +function notes.doifcontent(tag) local ok = notestates[tag] if ok then if ok.kind == "insert" then @@ -195,21 +160,17 @@ local function hascontent(tag) ok = ok.start end end - return ok and true or false -end - -notes.hascontent = hascontent - -function commands.doifnotecontent(tag) - commands.doif(hascontent(tag)) + commands.doif(ok) end local function internal(tag,n) local nd = get(tag,n) if nd then +-- inspect(nd) local r = nd.references if r then local i = r.internal +-- return i and lists.internals[i] return i and references.internals[i] -- dependency on references end end @@ -225,7 +186,7 @@ end notes.internal = internal notes.ordered = ordered -local function onsamepageasprevious(tag) +function notes.doifonsamepageasprevious(tag) local same = false local n = getn(tag,n) local current, previous = get(tag,n), get(tag,n-1) @@ -233,13 +194,7 @@ local function onsamepageasprevious(tag) local cr, pr = current.references, previous.references same = cr and pr and cr.realpage == pr.realpage end - return same and true or false -end - -notes.doifonsamepageasprevious = onsamepageasprevious - -function commands.doifnoteonsamepageasprevious(tag) - commands.doifelse(onsamepageasprevious(tag)) + commands.doifelse(same) end function notes.checkpagechange(tag) -- called before increment ! @@ -267,15 +222,13 @@ function notes.postpone() end for tag, state in next, notestates do if state.kind ~= "store" then - setstate(tag,"postpone") + notes.setstate(tag,"postpone") end end end -commands.postponenotes = notes.postpone - function notes.setsymbolpage(tag,n,l) - local l = l or listindex(tag,n) + local l = l or notes.listindex(tag,n) if l then local p = texcount.realpageno if trace_notes or trace_references then @@ -292,32 +245,41 @@ function notes.setsymbolpage(tag,n,l) end end -commands.setnotesymbolpage = notes.setsymbolpage +-- function notes.getsymbolpage(tag,n) +-- local nd = get(tag,n) +-- local p = nd and nd.references.symbolpage or 0 +-- if trace_notes or trace_references then +-- report_notes("page number of note symbol %s of '%s' is %s",n,tag,p) +-- end +-- context(p) +-- end -local function getsymbolpage(tag,n) +function notes.getsymbolpage(tag,n) local li = internal(tag,n) li = li and li.references li = li and (li.symbolpage or li.realpage) or 0 if trace_notes or trace_references then report_notes("page number of note symbol %s of '%s' is %s",n,tag,li) end - return li + context(li) end -local function getnumberpage(tag,n) +function notes.getnumberpage(tag,n) local li = internal(tag,n) li = li and li.references li = li and li.realpage or 0 if trace_notes or trace_references then report_notes("page number of note number %s of '%s' is %s",n,tag,li) end - return li + context(li) end -local function getdeltapage(tag,n) +function notes.deltapage(tag,n) -- 0:unknown 1:textbefore, 2:textafter, 3:samepage local what = 0 - -- references.internals[lists.tobesaved[nd].internal] + +-- references.internals[lists.tobesaved[nd].internal] + local li = internal(tag,n) if li then local references = li.references @@ -339,18 +301,10 @@ local function getdeltapage(tag,n) -- nesting in a vbox end end - return what + context(what) end -notes.getsymbolpage = getsymbolpage -notes.getnumberpage = getnumberpage -notes.getdeltapage = getdeltapage - -function commands.notesymbolpage(tag,n) context(getsymbolpage(tag,n)) end -function commands.notenumberpage(tag,n) context(getnumberpage(tag,n)) end -function commands.notedeltapage (tag,n) context(getdeltapage (tag,n)) end - -function commands.flushnotes(tag,whatkind,how) -- store and postpone +function notes.flush(tag,whatkind,how) -- store and postpone local state = notestates[tag] local kind = state.kind if kind == whatkind then @@ -406,12 +360,12 @@ function commands.flushnotes(tag,whatkind,how) -- store and postpone end end -function commands.flushpostponednotes() +function notes.flushpostponed() if trace_notes then report_notes("flushing all postponed notes") end for tag, _ in next, notestates do - commands.flushnotes(tag,"postpone") + notes.flush(tag,"postpone") end end |