diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/buff-ini.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/buff-ini.mkiv | 355 |
1 files changed, 95 insertions, 260 deletions
diff --git a/Master/texmf-dist/tex/context/base/buff-ini.mkiv b/Master/texmf-dist/tex/context/base/buff-ini.mkiv index 86b0fa3c530..7bd382fe2e9 100644 --- a/Master/texmf-dist/tex/context/base/buff-ini.mkiv +++ b/Master/texmf-dist/tex/context/base/buff-ini.mkiv @@ -1,6 +1,6 @@ %D \module -%D [ file=buff-ini, % was core-buf, % blocks are moved to core-blk -%D version=2000.01.05, +%D [ file=buff-ini, +%D version=2011.11.22, % previous big effort 2000.01.05, %D title=\CONTEXT\ Buffer Macros, %D subtitle=Buffers, %D author=Hans Hagen, @@ -15,72 +15,32 @@ \registerctxluafile{buff-ini}{1.001} -% todo: -% -% \startluacode -% local locations = { } -% function document.set_number(name) -% locations[name] = { -% line = status.linenumber, -% file = status.filename -% } -% end -% function document.add_number(name) -% local b, l = buffers.raw(name), locations[name] -% if b and l then -% for i=1,#b do -% b[i] = string.gsub(b[i],"# line: <number>","# line: " .. l.line + 2) -% end -% end -% end -% \stopluacode -% -% \starttext -% -% \ctxlua{document.set_number("oeps")} -% \startbuffer[oeps] -% # line: <number> -% -% test -% test -% \stopbuffer -% \ctxlua{document.add_number("oeps")} -% -% \typebuffer[oeps] -% -% \stoptext - -\ifdefined\doinitializeverbatim \else% temp hack - \def\doinitializeverbatim{\tttf} -\fi - \unprotect -\chardef\buffernestmode\plusone % 0: not nested, 1: startbuffer nested, 2: all buffers nested +% number is messy and not needed as we store the number anyway +% we can get rid of \c!number -\newif\ifsegmentatebuffer -\newif\ifemptybufferline +\newcount\nofdefinedbuffers -\def\currentbuffer{\jobname} +\let\currentbuffer\empty -\def\setcurrentbuffer#1% - {\doifelsenothing{#1}{\edef\currentbuffer{\jobname}}{\edef\currentbuffer{#1}}} +\def\doifelsebuffer#1% + {\ctxcommand{doifelsebuffer("#1")}} \def\resetbuffer {\dosingleempty\doresetbuffer} \def\doresetbuffer[#1]% - {\begingroup - \setcurrentbuffer{#1}% - \ctxlua{buffers.erase("\currentbuffer")}% - \endgroup} + {\ctxcommand{erasebuffer("#1")}} -\def\dostartbuffer +\unexpanded\def\dostartdefinedbuffer {\bgroup - \obeylines % nodig, anders gaat 't fout als direct \starttable (bv) + \obeylines \doquadrupleempty\dodostartbuffer} -\def\dodostartbuffer[#1][#2][#3][#4]% upward compatible +\let\dostartbuffer\dostartdefinedbuffer % used in some modules + +\def\dodostartbuffer[#1][#2][#3][#4]% [category] [name] [start] [stop] {\iffourthargument \def\next{\dododostartbuffer{#1}{#2}{#3}{#4}}% \else @@ -88,63 +48,43 @@ \fi \next} -\def\dododostartbuffer#1#2#3#4% - {%\showmessage\m!systems{15}{#2}% - \doifelsevalue{\??bu#1\c!paragraph}\v!yes - {\segmentatebuffertrue} % todo in mkiv - {\doifnumberelse{\getvalue{\??bu#1\c!paragraph}}\segmentatebuffertrue\segmentatebufferfalse}% - \doifvalue{\??bu#1\c!local}\v!yes - {\chardef\buffernestmode\plustwo}% permit nesting - \setcurrentbuffer{#2}% - \doifelsenothing{#4} - {\normalexpanded{\noexpand\setbuffercapsules{\e!start\v!buffer}{\e!stop\v!buffer}}% - \letvalue\bufferstop\relax} - %{\@EA\setbuffercapsules\@EA{\csname#3\@EA\endcsname\@EA}\@EA{\csname#4\endcsname}}% if we strip later - {\setbuffercapsules{#3}{#4}}% - \normalexpanded{\noexpand\dodowithbuffer - {\currentbuffer} - {\bufferstart} - {\bufferstop} - {\donothing} - {\egroup - \noexpand\getvalue{\bufferstop}}}} - -\letvalue{\e!start\v!buffer}\dostartbuffer - -\let\endbuffer\undefined % to please the dep parser +\def\dododostartbuffer#1#2#3#4% \donothing needed ! + {\normalexpanded{\dodowithbuffer{#2}{#3}{#4}{\donothing}{\egroup\noexpand\getvalue{#4}}}} + +\setvalue{\e!start\v!buffer}% + {\bgroup + \obeylines + \dosingleempty\redostartbuffer} + +\def\redostartbuffer[#1]% + {\dododostartbuffer{}{#1}{\e!start\v!buffer}{\e!stop\v!buffer}} \def\dowithbuffer#1#2#3% name, startsequence, stopsequence, before, after - {\setbuffercapsules{#2}{#3}% - \normalexpanded{\noexpand\dodowithbuffer{#1}{\bufferstart}{\bufferstop}}} + {\normalexpanded{\dodowithbuffer{#1}{#2}{#3}}} -\long\def\dodowithbuffer#1#2#3#4#5% name, startsequence, stopsequence, before, after +\unexpanded\long\def\dodowithbuffer#1#2#3#4#5% name, startsequence, stopsequence, before, after {#4% \bgroup + \ctxcommand{erasebuffer("#1")}% \setcatcodetable \vrbcatcodes - \catcode`\\=12 - \ctxlua{buffers.erase("#1")}% \long\def\nododowithbuffer {\egroup #5}% \long\def\dododowithbuffer##1#3% is detokenize needed? TEST - {\ctxlua - {buffers.grab("#1","#2","#3",\!!bs\detokenize{##1}\!!es)} - \dododowithbuffer - \nododowithbuffer}% + {\ctxcommand{grabbuffer("#1","#2","#3",\!!bs\detokenize{##1}\!!es)} % space ? + \dododowithbuffer + \nododowithbuffer}% \dododowithbuffer} -\def\setbuffercapsules#1#2% \scantextokens not needed (had a reason at some point) - {\edef\bufferstart{#1}\edef\bufferstart{\scantextokens\expandafter{\bufferstart}}% - \edef\bufferstop {#2}\edef\bufferstop {\scantextokens\expandafter{\bufferstop }}} - \def\setbuffer {\dosingleempty\dosetbuffer} +\let\endbuffer\relax + \long\def\dosetbuffer[#1]#2\endbuffer % seldom used so we just pass #2 - {\begingroup - \setcurrentbuffer{#1}% - \ctxlua{buffers.set("\currentbuffer", \!!bs\detokenize{#2}\!!es)}% - \endgroup} + {\ctxcommand{assignbuffer("#1", \!!bs\detokenize{#2}\!!es)}} + +\def\namedbufferparameter#1#2{\csname\??bu#1#2\endcsname} \unexpanded\def\setupbuffer {\dodoubleempty\dosetupbuffer} @@ -156,188 +96,65 @@ \getparameters[\??bu][#1]% \fi} -\def\dodefinebuffer[#1][#2]% - {\iffirstargument % else problems - \doglobal\increment\nofdefinedbuffers - \letvalue{\??bu#1\c!number }\nofdefinedbuffers - \letvalue{\??bu#1\c!paragraph}\v!no - \setuevalue{\e!start#1}{\noexpand\dostartbuffer[#1][def-\nofdefinedbuffers][\e!start#1][\e!stop#1]}% maybe also relax stop - \setuevalue{\e!get #1}{\noexpand\dogetbuffer [#1][def-\nofdefinedbuffers]}% - \setuevalue{\e!type #1}{\noexpand\dotypebuffer [#1][def-\nofdefinedbuffers]}% - \getparameters[\??bu#1][#2]% - \fi} +\newtoks\everydefinebuffer \unexpanded\def\definebuffer {\dodoubleempty\dodefinebuffer} -\def\thebuffernumber#1% - {\csname\??bu#1\c!number\endcsname} - -\unexpanded\def\getbuffer - {\dodoubleempty\dogetbuffer} - -\def\dogetbuffer[#1][#2]% - {\ifsecondargument - \dodogetbuffer[#1][#2]% - \else - \dodogetbuffer[][#1]% - \fi} - -\def\dogetbufferasis{\ctxlua{buffers.get("\currentbuffer")}} - -\def\dodogetbuffer[#1][#2]% - {\getvalue{\??bu#1\c!before}% - \dobuffer{16}{#2}\dogetbufferasis - \getvalue{\??bu#1\c!after}} - -\unexpanded\def\typebuffer - {\dodoubleempty\dotypebuffer} - -\def\doprocessbufferverbatim - {\doinitializeverbatim - \ctxlua{buffers.type("\currentbuffer","\typingparameter\c!strip")}} - -\def\doprocessbufferlinesverbatim#1#2#3% - {#2% - % todo, set up numbers - \doinitializeverbatim - \ctxlua{buffers.type("\currentbuffer","\typingparameter\c!strip")} - #3} - -\def\doifelsebuffer#1% - {\ctxlua{buffers.doifelsebuffer("#1")}} - -\def\dodotypebuffer#1#2#3% see dodotypefile - {\doifelsebuffer{#3} - {\dosometyping{#1}{#2}{#3}\doprocessbufferverbatim\doprocessbufferlinesverbatim} - {\reporttypingerror{#3}}} - -\def\dotypefilebuffer{\dodotypebuffer{\v!file}{}{\currentbuffer}}% - -\def\dotypebuffer[#1][#2]% +\def\dodefinebuffer[#1][#2]% {\iffirstargument - \dobuffer{17}{#1}\dotypefilebuffer + \global\advance\nofdefinedbuffers\plusone + \setevalue{\??bu#1\c!number}{\number\nofdefinedbuffers}% + \def\currentbuffer{#1}% + \getparameters[\??bu#1][#2]% + \the\everydefinebuffer \else - \dobuffer{17}{#2}\dotypefilebuffer + % fatal error \fi} -\def\dobuffer#1#2#3% - {\doifelsenothing{#2} - {\dodobuffer#3\jobname} - {\processcommalist[#2]{\dodobuffer#3}}} - -\def\dodobuffer#1#2% command name - {\pushmacro\currentbuffer - \edef\currentbuffer{\ifcsname\??bu#2\c!number\endcsname def-\csname\??bu#2\c!number\endcsname\else#2\fi}% - #1% - \popmacro\currentbuffer} +\def\thebuffernumber #1{\csname\??bu#1\c!number\endcsname} +\def\thedefinedbuffer#1{def-\csname\??bu#1\c!number\endcsname} -\def\processTEXbuffer{\getbuffer} % handy +\appendtoks + \setuevalue{\e!start\currentbuffer}% + {\noexpand\dostartdefinedbuffer + [\currentbuffer]% + [def-\number\nofdefinedbuffers]% + [\e!start\currentbuffer]% + [\e!stop\currentbuffer]}% + \setuevalue{\e!get\currentbuffer}% + {\noexpand\dogetdefinedbuffer + [\currentbuffer]% + [def-\number\nofdefinedbuffers]}% +\to \everydefinebuffer -% extras: +\def\doprocessbufferlist#1#2% + {\doifelsenothing{#1} + {\dododogetbuffer\empty} + {\processcommalist[#1]#2}} -\def\inspectbuffer - {\dosingleempty\doinspectbuffer} +\unexpanded\def\getbuffer % no [settings yet] + {\dosingleempty\dogetbuffer} -\def\doinspectbuffer[#1]% - {\setcurrentbuffer{#1}% - \ctxlua{buffers.inspect("\currentbuffer")}} - -% seldom used, only in a few projects that demanded more speed - -\let\usememorybuffers\relax -\let\usefilebuffers \relax - -% this features is soldom used (complex examns where we need to fetch -% special parts of a text -% -% this is not yet supported in mkiv (relatively easy to do but there -% we don't have the par tags but need to grab 'm +\unexpanded\def\dogetbuffer[#1]% [name] + {\namedbufferparameter\empty\c!before + \doprocessbufferlist{#1}\dododogetbuffer + \namedbufferparameter\empty\c!after} -\def\skippedbufferparagraphs{0} +\def\dogetdefinedbuffer[#1][#2]% + {\namedbufferparameter{#1}\c!before + \dododogetbuffer{#2}% + \namedbufferparameter{#1}\c!after} -\let\startbufferparagraph\relax -\let\stopbufferparagraph \par % \relax +\def\dododogetbuffer#1% + {\ctxcommand{getbuffer("#1")}} -\newcount\currentbufferparagraph +\definebuffer[\v!hiding] \setupbuffer[\v!hiding][\c!before=,\c!after=] -\def\getbufferparagraphs - {\dodoubleempty\dogetbufferparagraphs} - -\def\dosetbufferoffset#1% - {\doifnumberelse{\getvalue{\??bu#1\c!paragraph}} - {\currentbufferparagraph-\getvalue{\??bu#1\c!paragraph}} - {\currentbufferparagraph \zerocount}% - \relax} - -\def\dogetbufferparagraphs[#1][#2]% - {\iffirstargument - \ifsecondargument - \dosetbufferoffset{#1}% - \doifelse{#2}\v!all - {\unexpanded\def\startbufferparagraph{\normalbufferparagraph{#1}}} - {\unexpanded\def\startbufferparagraph{\filterbufferparagraph{#1}{#2}}}% - \unexpanded\def\stopbufferparagraph{\dostopbufferparagraph{#1}}% - \def\next{\getparagraphedbuffer[#1]}% - \else - \dosetbufferoffset\empty - \unexpanded\def\startbufferparagraph{\filterbufferparagraph{}{#1}}% - \unexpanded\def\stopbufferparagraph{\dostopbufferparagraph{}}% - \def\next{\getparagraphedbuffer[]}% - \fi - \else - \dosetbufferoffset\empty - \unexpanded\def\startbufferparagraph{\normalbufferparagraph{}}% - \unexpanded\def\stopbufferparagraph{\dostopbufferparagraph{}}% - \def\next{\getparagraphedbuffer[]}% - \fi - \next} - -\def\dotypeparagraphbuffer{\ctxlua{buffers.get("\currentbuffer")}} - -\def\getparagraphedbuffer[#1]% - {\dobuffer{16}{#1}\dotypeparagraphbuffer} - -\def\dostopbufferparagraph#1% - {\getvalue{\??bu#1\c!after}\par} - -\def\dostartbufferparagraph#1% - {\par\getvalue{\??bu#1\c!before}} - -\def\normalbufferparagraph - {\advance\currentbufferparagraph \plusone - \ifnum\currentbufferparagraph>\zerocount - \expandafter\dostartbufferparagraph - \else - \expandafter\gobbleoneargument - \fi} - -\def\filterbufferparagraph#1#2% - {\advance\currentbufferparagraph \plusone - \ifcase\currentbufferparagraph - \@EA\gobblebufferparagraph - \else - \doifinsetelse{\the\currentbufferparagraph}{#2} - {\@EA\dostartbufferparagraph} - {\@EA\fakebufferparagraph}% - \fi - {#1}} - -\long\def\gobblebufferparagraph#1#2\stopbufferparagraph - {} - -\def\fakebufferparagraph#1% - {\bgroup - \unexpanded\def\stopbufferparagraph{\dostopbufferparagraph{#1}\egroup\egroup}% - \setbox\scratchbox\vbox\bgroup\dostartbufferparagraph{#1}} - -% definitions - -\definebuffer[\v!hiding] \setupbuffer[\v!hiding][\c!local=\v!yes] +\let\processTEXbuffer\getbuffer % handy synonym \setupbuffer - [\c!paragraph=\v!no, - \c!before=, + [\c!before=, \c!after=] % only mkiv: @@ -350,6 +167,24 @@ \unexpanded\def\savebuffer{\dodoubleempty\dosavebuffer} -\def\dosavebuffer[#1][#2]{\ctxlua{commands.savebuffer("#1","#2")}} +\def\dosavebuffer[#1][#2]{\ctxcommand{savebuffer("#1","#2")}} + +%D Experimental: no expansion of commands in buffer! + +% \startbuffer[what] +% tex.print("WHAT") +% \stopbuffer +% \startbuffer +% tex.print("JOBNAME") +% \stopbuffer +% +% \ctxluabuffer[what] \ctxluabuffer + +\def\ctxluabuffer {\dosingleempty\doctxluabuffer} +\def\mkvibuffer {\dosingleempty\domkvibuffer} +\def\mkvibufferraw{\dosingleempty\domkvibufferraw} + +\def\doctxluabuffer [#1]{\ctxcommand{getbufferctxlua("#1")}} +\def\domkvibuffer [#1]{\ctxcommand{getbuffermkvi("#1")}} \protect \endinput |