From a7dd0093b962777a8944812d5a56e6c5f972b8b1 Mon Sep 17 00:00:00 2001
From: Hans Hagen We overload both the
When you (temporarily) want to install a callback function, and after a @@ -23,20 +24,112 @@ while wants to revert to the original one, you can use the following two functions.
--ldx]]-- +local trace_callbacks = false trackers.register("system.callbacks", function(v) trace_callbacks = v end) + +local register_callback, find_callback = callback.register, callback.find +local frozen, stack = { }, { } + +local function frozenmessage(what,name) + logs.report("callbacks","not %s frozen '%s' (%s)",what,name,frozen[name]) +end + +function callbacks.report() + local list = callback.list() + for name, func in table.sortedpairs(list) do + local str = frozen[name] + func = (func and "set") or "nop" + if str then + logs.report("callbacks","%s: %s -> %s",func,name,str) + else + logs.report("callbacks","%s: %s",func,name) + end + end +end + +function callbacks.table() + context.starttabulate { "|l|l|p|" } + for name, func in table.sortedpairs(callback.list()) do + context.NC() + context.type((func and "set") or "nop") + context.NC() + context.type(name) + context.NC() + context(frozen[name] or "") + context.NC() + context.NR() + end + context.stoptabulate() +end + +function callbacks.freeze(name,freeze) + freeze = type(freeze) == "string" and freeze +--~ print(name) + if find(name,"%*") then + local pattern = name -- string.simpleesc(name) + local list = callback.list() + for name, func in pairs(list) do + if find(name,pattern) then + frozen[name] = freeze or frozen[name] or "frozen" + end + end + else + frozen[name] = freeze or frozen[name] or "frozen" + end +end + +function callbacks.register(name,func,freeze) + if frozen[name] then + if trace_callbacks then + frozenmessage("registering",name) + end + elseif freeze then + frozen[name] = (type(freeze) == "string" and freeze) or "registered" + register_callback(name,func) + else + register_callback(name,func) + end +end + +function callback.register(name,func) -- original + if not frozen[name] then + register_callback(name,func) + elseif trace_callbacks then + frozenmessage("registering",name) + end +end + function callbacks.push(name, func) - if not callbacks.stack[name] then - callbacks.stack[name] = { } + if not frozen[name] then + local sn = stack[name] + if not sn then + sn = { } + stack[name] = sn + end + insert(sn,find_callback(name)) + register_callback(name, func) + elseif trace_callbacks then + frozenmessage("pushing",name) end - table.insert(callbacks.stack[name],callback.find(name)) - callback.register(name, func) end function callbacks.pop(name) --- this fails: callback.register(name, table.remove(callbacks.stack[name])) - local func = table.remove(callbacks.stack[name]) - callback.register(name, func) + if frozen[name] then + -- do nothing + elseif #stack == 0 then + -- some error + else + -- this fails: register_callback(name, remove(stack[name])) + local func = remove(stack[name]) + register_callback(name, func) + end end +--~ -- somehow crashes later on +--~ +--~ callbacks.freeze("find_.*_file","finding file") +--~ callbacks.freeze("read_.*_file","reading file") +--~ callbacks.freeze("open_.*_file","opening file") + --[[ldx--The simple case is to remove the callback:
diff --git a/tex/context/base/luat-cnf.lua b/tex/context/base/luat-cnf.lua index ae132e4e6..e45aceb79 100644 --- a/tex/context/base/luat-cnf.lua +++ b/tex/context/base/luat-cnf.lua @@ -43,18 +43,18 @@ end local stub = [[ -- checking -storage = storage or {} -luatex = luatex or {} - --- as soon as possible - -luatex.starttime = os.gettimeofday() +storage = storage or { } +luatex = luatex or { } -- we provide our own file handling texconfig.kpse_init = false texconfig.shell_escape = 't' +-- as soon as possible + +luatex.starttime = os.gettimeofday() + -- this will happen after the format is loaded function texconfig.init() diff --git a/tex/context/base/luat-dum.lua b/tex/context/base/luat-dum.lua index ceda2d923..19e95e2b1 100644 --- a/tex/context/base/luat-dum.lua +++ b/tex/context/base/luat-dum.lua @@ -42,6 +42,9 @@ tasks = { appendaction = dummyfunction, prependaction = dummyfunction, } +callbacks = { + register = function(n,f) return callback.register(n,f) end, +} -- we need to cheat a bit here diff --git a/tex/context/base/luat-fio.lua b/tex/context/base/luat-fio.lua index 334297f03..0209fc243 100644 --- a/tex/context/base/luat-fio.lua +++ b/tex/context/base/luat-fio.lua @@ -42,7 +42,7 @@ if not resolvers.instance then callback.register('find_map_file' , function(name) return resolvers.findbinfile(name,"map") end) callback.register('find_ocp_file' , function(name) return resolvers.findbinfile(name,"ocp") end) callback.register('find_opentype_file' , function(name) return resolvers.findbinfile(name,"otf") end) - callback.register('find_output_file' , function(name) return name end) + callback.register('find_output_file' , function(name) return name end) callback.register('find_pk_file' , function(name) return resolvers.findbinfile(name,"pk") end) callback.register('find_sfd_file' , function(name) return resolvers.findbinfile(name,"sfd") end) callback.register('find_truetype_file' , function(name) return resolvers.findbinfile(name,"ttf") end) diff --git a/tex/context/base/luat-run.lua b/tex/context/base/luat-run.lua index 44126f526..f2072f74a 100644 --- a/tex/context/base/luat-run.lua +++ b/tex/context/base/luat-run.lua @@ -61,9 +61,9 @@ end -- this can be done later -callback.register('start_run', main.start) -callback.register('stop_run', main.stop) -callback.register('report_output_pages', main.report_output_pages) -callback.register('report_output_log' , main.report_output_log) -callback.register('start_page_number' , main.start_shipout_page) -callback.register('stop_page_number' , main.stop_shipout_page) +callbacks.register('start_run', main.start, "actions performed at the beginning of a run") +callbacks.register('stop_run', main.stop, "actions performed at the end of a run") +callbacks.register('report_output_pages', main.report_output_pages, "actions performed when reporting pages") +callbacks.register('report_output_log' , main.report_output_log, "actions performed when reporting log file") +callbacks.register('start_page_number' , main.start_shipout_page, "actions performed at the beginning of a shipout") +callbacks.register('stop_page_number' , main.stop_shipout_page, "actions performed at the end of a shipout") diff --git a/tex/context/base/math-noa.lua b/tex/context/base/math-noa.lua index b226444a4..cca1812d2 100644 --- a/tex/context/base/math-noa.lua +++ b/tex/context/base/math-noa.lua @@ -358,7 +358,7 @@ function nodes.processors.mlist_to_hlist(head,style,penalties) return head, done end -callback.register('mlist_to_hlist',nodes.processors.mlist_to_hlist) +callbacks.register('mlist_to_hlist',nodes.processors.mlist_to_hlist,"preprocessing math list") -- tracing diff --git a/tex/context/base/node-pro.lua b/tex/context/base/node-pro.lua index 8b2e92ff2..b294b850f 100644 --- a/tex/context/base/node-pro.lua +++ b/tex/context/base/node-pro.lua @@ -108,8 +108,8 @@ function nodes.processors.hpack_filter(head,groupcode) return true end -callback.register('pre_linebreak_filter', nodes.processors.pre_linebreak_filter) -callback.register('hpack_filter' , nodes.processors.hpack_filter) +callbacks.register('pre_linebreak_filter', nodes.processors.pre_linebreak_filter,"all kind of horizontal manipulations (before par break)") +callbacks.register('hpack_filter' , nodes.processors.hpack_filter,"all kind of horizontal manipulations") local actions = tasks.actions("finalizers",2) -- head, where, boolean @@ -142,7 +142,7 @@ function nodes.processors.post_linebreak_filter(head,groupcode) --~ return true end -callback.register('post_linebreak_filter', nodes.processors.post_linebreak_filter) +callbacks.register('post_linebreak_filter', nodes.processors.post_linebreak_filter,"all kind of horizontal manipulations (after par break)") statistics.register("h-node processing time", function() if statistics.elapsedindeed(nodes) then diff --git a/tex/context/base/node-tex.lua b/tex/context/base/node-tex.lua index c5781ab5a..a6eef3269 100644 --- a/tex/context/base/node-tex.lua +++ b/tex/context/base/node-tex.lua @@ -34,6 +34,6 @@ function kernel.kerning(head) return head, done end -callback.register('hyphenate' , false) -callback.register('ligaturing', false) -callback.register('kerning' , false) +callbacks.register('hyphenate' , false, "normal hyphenation routine, called elsewhere") +callbacks.register('ligaturing', false, "normal ligaturing routine, called elsewhere") +callbacks.register('kerning' , false, "normal kerning routine, called elsewhere") diff --git a/tex/context/base/page-lin.mkiv b/tex/context/base/page-lin.mkiv index 8c7144a48..2e3703eae 100644 --- a/tex/context/base/page-lin.mkiv +++ b/tex/context/base/page-lin.mkiv @@ -476,8 +476,7 @@ \ctxlua{ nodes.lines.scratchbox = \number\linenumberscratchbox ; - % callback.register('vpack_filter', nodes.lines.flowed.apply) - callback.register('post_linebreak_filter', nodes.lines.flowed.apply) + -- register nodes.lines.flowed.apply in post_linebreak_filter actions } \fi diff --git a/tex/context/base/scrn-hlp.mkiv b/tex/context/base/scrn-hlp.mkiv index c9fcbd29a..4eaa340ca 100644 --- a/tex/context/base/scrn-hlp.mkiv +++ b/tex/context/base/scrn-hlp.mkiv @@ -38,6 +38,9 @@ \newcounter \nofhelpdataentries \newconditional \somehelpdatadefined +\let\getpagehelpdata \relax +\let\synchronizepagehelpdata\relax + \appendtoks \getpagehelpdata \to \beforeeverypage \appendtoks \synchronizepagehelpdata \to \aftereverypage @@ -46,43 +49,48 @@ \let\pagehelpdata\empty \def\dontresetpagedata - {\let\synchronizepagehelpdata\relax} + {\let\synchronizepagehelpdataindeed\relax} \def\resetpagehelpdata {\iflocation - \let\synchronizepagehelpdata\resetpagehelpdata + \let\synchronizepagehelpdataindeed\resetpagehelpdata \global\let\pagehelpdata\empty \resetreference[HideHelp]% \fi} -\let\synchronizepagehelpdata\resetpagehelpdata +\let\synchronizepagehelpdataindeed\resetpagehelpdata \resetreference[HideHelp] -\def\getpagehelpdata +\def\getpagehelpdataindeed {\iflocation\ifcase\nofhelpdataentries\else - \let\pagehelpdata\empty - \ifconditional\somehelpdatadefined - \definetwopasslist{hlp:\realfolio}% - \doloop - {\gettwopassdata{hlp:\realfolio}% - \iftwopassdatafound - \addtocommalist\twopassdata\pagehelpdata - \else - \exitloop - \fi}% - \fi - \ifx\pagehelpdata\empty \else - \useJSscripts[fld]% - \definereference[HideHelp][JS(Hide_Fields)]% for the moment - \fi + \dogetpagehelpdataindeed \fi\fi} +\def\dogetpagehelpdataindeed + {\let\pagehelpdata\empty + \ifconditional\somehelpdatadefined + \definetwopasslist{hlp:\realfolio}% + \doloop + {\gettwopassdata{hlp:\realfolio}% + \iftwopassdatafound + \addtocommalist\twopassdata\pagehelpdata + \else + \exitloop + \fi}% + \fi + \ifx\pagehelpdata\empty \else + \useJSscripts[fld]% + \definereference[HideHelp][JS(Hide_Fields)]% for the moment + \fi} + \def\setpagehelpdata[#1]% {\iflocation\expanded{\dosetpagehelpdata{#1}}\fi} \def\dosetpagehelpdata#1% {\doglobal\increment\nofhelpdataentries + \global\let\getpagehelpdata\getpagehelpdataindeed + \global\let\synchronizepagehelpdata\synchronizepagehelpdataindeed \savetwopassdata{hlp:\realfolio}{\nofhelpdataentries}{#1}} \setvalue{\e!start\v!helptext}[#1]% diff --git a/tex/context/base/spac-hor.mkiv b/tex/context/base/spac-hor.mkiv index fca5624ec..a6754937b 100644 --- a/tex/context/base/spac-hor.mkiv +++ b/tex/context/base/spac-hor.mkiv @@ -812,12 +812,12 @@ \installspacehandler \v!on {\obeyspaces - \def\obeyedspace{\mathortext\normalspace{\dontleavehmode{\tt\controlspace}}}% + \unexpanded\def\obeyedspace{\mathortext\normalspace{\dontleavehmode{\tt\controlspace}}}% \let\ =\obeyedspace} \installspacehandler \v!yes {\obeyspaces - \def\obeyedspace{\mathortext\normalspace{\dontleavehmode\normalspace}}% + \unexpanded\def\obeyedspace{\mathortext\normalspace{\dontleavehmode\normalspace}}% \let\ =\obeyedspace} \installspacehandler \v!off % == default @@ -827,10 +827,14 @@ \installspacehandler \v!fixed {\obeyspaces - \def\obeyedspace{\mathortext\normalspace{\dontleavehmode\fixedspace}}% + \unexpanded\def\obeyedspace{\mathortext\normalspace{\dontleavehmode\fixedspace}}% \let\ =\obeyedspace} \def\activatespacehandler#1% {\executeifdefined{\??sr#1}{\activatespacehandler\v!off}} +\appendtoks + \normalspaces % to be sure +\to \everybeforeoutput + \protect \endinput diff --git a/tex/context/base/spac-ver.lua b/tex/context/base/spac-ver.lua index 735ebbdde..3bfc84a19 100644 --- a/tex/context/base/spac-ver.lua +++ b/tex/context/base/spac-ver.lua @@ -1001,9 +1001,9 @@ local ignore = table.tohash { function nodes.handle_vbox_spacing(head,where) if head and not ignore[where] and head.next then ---~ starttiming(vspacing) + -- starttiming(vspacing) head = collapser(head,"vbox",where,trace_vbox_vspacing,false) ---~ stoptiming(vspacing) + -- stoptiming(vspacing) end return head end @@ -1011,27 +1011,12 @@ end function nodes.collapse_vbox(n) -- for boxes local list = texbox[n].list if list then ---~ starttiming(vspacing) + -- starttiming(vspacing) texbox[n].list = vpack_node(collapser(list,"snapper","vbox",trace_vbox_vspacing,true)) ---~ stoptiming(vspacing) + -- stoptiming(vspacing) end end --- these are experimental callback definitions that definitely will --- be moved elsewhere as part of a chain of vnode handling --- --- function vspacing.enable() --- callback.register('vpack_filter', nodes.handle_vbox_spacing) -- enabled per 2009/10/16 --- callback.register('buildpage_filter', nodes.handle_page_spacing) --- end --- --- function vspacing.disable() --- callback.register('vpack_filter', nil) --- callback.register('buildpage_filter', nil) --- end --- --- vspacing.enable() - -- we will split this module hence the locals local attribute = attributes.private('graphicvadjust') @@ -1127,8 +1112,8 @@ function nodes.builders.buildpage_filter(groupcode) return (done and head) or true end -callback.register('vpack_filter', nodes.builders.vpack_filter) -callback.register('buildpage_filter', nodes.builders.buildpage_filter) +callbacks.register('vpack_filter', nodes.builders.vpack_filter,"vertical spacing etc") +callbacks.register('buildpage_filter', nodes.builders.buildpage_filter,"vertical spacing etc (mvl)") statistics.register("v-node processing time", function() if statistics.elapsedindeed(builders) then diff --git a/tex/context/base/strc-def.mkiv b/tex/context/base/strc-def.mkiv index 7f1db7065..0ef59b300 100644 --- a/tex/context/base/strc-def.mkiv +++ b/tex/context/base/strc-def.mkiv @@ -120,7 +120,7 @@ \definestructureseparatorset [\v!appendix:\s!default] [] [.] \definestructureconversionset [\v!appendix:\s!default] [Romannumerals,Characters] [numbers] -\definestructureresetset [\v!appendix:\s!default] [] [0] +\definestructureresetset [\v!appendix:\s!default] [] [1] % why was this 0 % \definesectionblock diff --git a/tex/context/base/strc-reg.lua b/tex/context/base/strc-reg.lua index 95246bff7..60d00f8b2 100644 --- a/tex/context/base/strc-reg.lua +++ b/tex/context/base/strc-reg.lua @@ -295,8 +295,9 @@ function jobregisters.compare(a,b) for i=1,max do if result == 0 then result = compare(ea[i],eb[i]) + else + break end - return result end if result ~= 0 then return result @@ -495,6 +496,7 @@ function jobregisters.flush(data,options,prefixspec,pagespec) local kind = entry.metadata.kind if kind == 'entry' then texsprint(ctxcatcodes,"\\startregisterpages") +--~ collapse_ranges = true if collapse_singles or collapse_ranges then -- we collapse ranges and keep existing ranges as they are -- so we get prebuilt as well as built ranges diff --git a/tex/context/base/strc-reg.mkiv b/tex/context/base/strc-reg.mkiv index d807b2939..4fa29285a 100644 --- a/tex/context/base/strc-reg.mkiv +++ b/tex/context/base/strc-reg.mkiv @@ -476,7 +476,7 @@ \fi \setnextinternalreference % we could consider storing register entries in list - \ctxlua{ jobregisters.store { + \edef\temp{\ctxlua{ jobregisters.store { metadata = { kind = "see", name = "\currentregister", @@ -495,7 +495,7 @@ text = "\currentregisterseeword" }, } - }% + }}% \endgroup} %D Rendering: @@ -599,9 +599,9 @@ % test case for collapsing (experimental, for Steffen Wolfrum) % % \starttext -% \placeregister[index][collapse=no] \blank[2*big] -% \placeregister[index][collapse=yes] \blank[2*big] -% \placeregister[index][collapse=akk] \page +% \placeregister[index][compress=no] \blank[2*big] +% \placeregister[index][compress=yes] \blank[2*big] +% \placeregister[index][compress=all] \page % \dorecurse{10}{test 1:!\index{test} test \page} % \dorecurse{5} {test 2:\recurselevel \page} % \dorecurse{10}{test 3:!\index{test} test \page} diff --git a/tex/context/base/strc-sec.mkiv b/tex/context/base/strc-sec.mkiv index ec7d97e6d..f583ef849 100644 --- a/tex/context/base/strc-sec.mkiv +++ b/tex/context/base/strc-sec.mkiv @@ -557,11 +557,13 @@ \newconditional\ignorehandlepagebreak \def\dostructureheadspacingbeforeyes - {\docheckstructureheadbefore\dohandlestructureheadpagebreak + {\docheckstructureheadbefore + \dohandlestructureheadpagebreak \structureheadparameter\c!inbetween} \def\dostructureheadspacingbeforenop - {\docheckstructureheadbefore\docheckstructureheadlayout + {\docheckstructureheadbefore + \docheckstructureheadlayout \structureheadparameter\c!inbetween} % \def\emptystructureheadcorrection @@ -635,7 +637,7 @@ \setfalse\ignorehandlepagebreak \else \ifnum\lastpenalty>\zerocount - \global\pagebreakdisabledtrue +% \global\pagebreakdisabledtrue \fi % beware, these numbers are not yet know here \doifelse{\structureheadparameter\c!continue}\v!yes @@ -648,11 +650,11 @@ \doifnot{\structureheadparameter\c!aligntitle}\v!float\flushsidefloats \structureheadparameter\c!before \relax - \ifpagebreakdisabled - \global\pagebreakdisabledfalse - \else +% \ifpagebreakdisabled +% \global\pagebreakdisabledfalse +% \else \dopreventbreakafterstructureheadauto - \fi +% \fi \doif{\structureheadparameter\c!aligntitle}\v!float\indent \global\precedingstructurelevel\currentstructureheadlevel \fi} diff --git a/tex/context/base/task-ini.lua b/tex/context/base/task-ini.lua index 816fb83df..c98d76aeb 100644 --- a/tex/context/base/task-ini.lua +++ b/tex/context/base/task-ini.lua @@ -86,3 +86,7 @@ tasks.disableaction("shipouts", "nodes.add_references") tasks.disableaction("shipouts", "nodes.add_destinations") tasks.disableaction("pagebuilders", "nodes.migrate_outwards") + +callbacks.freeze("find_.*_file", "find file using resolver") +callbacks.freeze("read_.*_file", "read file at once") +callbacks.freeze("open_.*_file", "open file for reading") diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index d7b687b7c..c54df5f47 100644 --- a/tex/generic/context/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : c:/data/develop/context/texmf/tex/generic/context/luatex-fonts-merged.lua -- parent file : c:/data/develop/context/texmf/tex/generic/context/luatex-fonts.lua --- merge date : 02/15/10 22:19:32 +-- merge date : 02/17/10 14:29:47 do -- begin closure to overcome local limits and interference @@ -1975,6 +1975,9 @@ tasks = { appendaction = dummyfunction, prependaction = dummyfunction, } +callbacks = { + register = function(n,f) return callback.register(n,f) end, +} -- we need to cheat a bit here @@ -11640,8 +11643,8 @@ endWe overload both the