page-pst.mkiv /size: 3370 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=page-mis,
3%D        version=2008.11.17, % was part of page-flt.tex / 2000.10.20
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Postponing,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Page Macros / Postponing}
15
16\registerctxluafile{page-pst}{}
17
18\unprotect
19
20% postponing
21
22\newevery\everytopofpage\relax
23
24\appendtoks
25    \the\everytopofpage
26\to \everystarttext
27
28\appendtoks
29    \global\everytopofpage\emptytoks
30\to \everystoptext
31
32% \startpostponing [pagenumber] [+pageoffset]
33%
34% \startpostponing[2]
35%   PAGE 2 \blank
36% \stoppostponing
37%
38% \startpostponing[+1]
39%   PAGE +1 \blank
40% \stoppostponing
41%
42% \startpostponing[+2]
43%   PAGE +2 \blank
44% \stoppostponing
45%
46% \starttext \dorecurse{4}{\input tufte \page} \stoptext
47
48%D There is no real need to use \LUA\ here but the bookkeeping
49%D is somewhat easier and we also can erase buffers easier when
50%D we keep a local cache, especially as we can flush per page.
51
52%newif      \ifinpostponing                    % prevents nesting
53
54\newcount      \c_page_postponed_blocks_next_page % set at the lua end
55\newconditional\c_page_postponed_busy
56
57\unexpanded\setvalue{\e!start\v!postponing}%
58  {\bgroup
59   \obeylines
60   \doifelsenextoptional{\egroup\page_postponed_blocks_start}{\egroup\page_postponed_blocks_start[0]}}
61
62\unexpanded\setvalue{\e!stop\v!postponing}%
63  {\clf_registerpostponedblock{\currentpostponedpage}\relax}
64
65\def\page_postponed_blocks_start[#1]%
66  {\edef\currentpostponedpage{#1}%
67   \grabbufferdatadirect{postponedblock}{\e!start\v!postponing}{\e!stop\v!postponing}}
68
69% officially we should flush again after a flush as there can be new future pages
70% but that will be looked into when we run into it
71
72\c_page_postponed_mode\plusone
73
74\unexpanded\def\page_postponed_blocks_flush_indeed
75  {\begingroup
76   \setsystemmode\v!postponing
77   \settrue\c_page_postponed_busy
78   \ifnum\c_page_postponed_mode=\plusone
79     \savepagecontent
80   \fi
81   \pagetotal\zeropoint        % here? still needed? (was after flush pagefloats)
82   \the\everytopofpage\relax
83  %\flushrestfloats
84   \page_floats_flush_page_floats
85   \setnormalcatcodes                 % postponing in verbatim
86   \uncatcodespacetokens              % postponing in startlines
87   \restoreglobalbodyfont             % otherwise problems inside split verbatim
88   \clf_flushpostponedblocks
89     % page {123}
90   \relax
91   \page_otr_command_flush_floats     % new but potential dangerous, maybe we need a classification
92   \ifnum\c_page_postponed_mode=\plusone
93     \flushpagecontent
94   \fi
95   \endgroup}                         % of blocks: with and without flush
96
97\unexpanded\def\page_postponed_blocks_flush
98  {\ifconditional\c_page_postponed_busy
99     % probably a nested flush
100   \else\ifnum\c_page_postponed_blocks_next_page=\zerocount
101     % nothing in cache
102   \else\ifnum\c_page_postponed_blocks_next_page<\zerocount
103     % generic cache
104     \page_postponed_blocks_flush_indeed
105   \else\ifnum\c_page_postponed_blocks_next_page>\realpageno
106     % future content
107   \else
108     % pending content
109     \page_postponed_blocks_flush_indeed
110   \fi\fi\fi\fi}
111
112\protect \endinput
113