diff options
author | Taco Hoekwater <taco@elvenkind.com> | 2011-06-01 08:54:21 +0000 |
---|---|---|
committer | Taco Hoekwater <taco@elvenkind.com> | 2011-06-01 08:54:21 +0000 |
commit | d7ccb42582f85acf30568913610ccf4d602023fb (patch) | |
tree | 7292e3545a420676878e7451b68892d360c62cb6 /Master/texmf-dist/tex/context/base/buff-ver.mkiv | |
parent | 2d62a6fe9b80def59c392268022f1f9a2d6e358f (diff) |
commit context 2011.05.18
git-svn-id: svn://tug.org/texlive/trunk@22719 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/buff-ver.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/buff-ver.mkiv | 1334 |
1 files changed, 496 insertions, 838 deletions
diff --git a/Master/texmf-dist/tex/context/base/buff-ver.mkiv b/Master/texmf-dist/tex/context/base/buff-ver.mkiv index dacbdb7ac99..c8f07ddb4b9 100644 --- a/Master/texmf-dist/tex/context/base/buff-ver.mkiv +++ b/Master/texmf-dist/tex/context/base/buff-ver.mkiv @@ -13,157 +13,148 @@ \writestatus{loading}{ConTeXt Buffer Macros / Verbatim} -%D We can optimize esp the initializations a bit. +\registerctxluafile{buff-ver}{1.001} \unprotect -\ifdefined\startlinenumbering\else \let\startlinenumbering \relax \fi -\ifdefined\stoplinenumbering \else \let\stoplinenumbering \relax \fi -\ifdefined\setuplinenumbering\else \unexpanded\def\setuplinenumbering[#1]{} \fi - -% D \macros -% D {iflinepar} -% D -% D A careful reader will see that \type{\linepar} is reset. -% D This boolean can be used to determine if the current line is -% D the first line in a pseudo paragraph and this boolean is set -% D after each empty line. The \type{\relax} can be used to -% D determine the end of the line when one implements a scanner -% D routine. -% -% will become obsolete - -\newif\iflinepar +\definesystemattribute[verbatimline][public] -% \type{ <crlf> char} geeft bagger +\appendtoksonce \attribute\verbatimlineattribute \attributeunsetvalue \to \everyforgetall -%D We are going to embed the general verbatim support macros in -%D a proper environment. First we show the common setup -%D macro, so we know what features are supported. The options -%D are hooked into the support macros via the \type{\obey} -%D macros. +%D Initializations. -\newif\ifslantedtypeactivated -\newif\ifslantedtypepermitted +\newtoks\everyinitializeverbatim -\def\switchslantedtype - {\ifslantedtypepermitted - \ifslantedtypeactivated - \slantedtypeactivatedfalse\tttf - \else - \slantedtypeactivatedtrue\ttsl - \fi - \fi} +\appendtoks + \the\everyresettypesetting + \resetfontfeature + \resetcharacterspacing +\to \everyinitializeverbatim -\def\prettyidentifier {TEX} -\def\prettypalet {} - -\def\installprettytype - {\dodoubleargument\doinstallprettytype} - -\def\doinstallprettytype[#1][#2]% map #1 onto #2 - {\uppercasestring#1\to\asciia - \uppercasestring#2\to\asciib - \setevalue{\??ty\??ty\asciia}{\asciib}} - -\unexpanded\def\setupprettiesintype#1% - {\uppercasestring#1\to\ascii - \edef\prettyidentifier{\executeifdefined{\??ty\??ty\ascii}{TEX}}% - \begingroup - % we can move this to lua - % \lowercasestring \f!prettyprefix\prettyidentifier\to\filename - % \doonlyonce\filename{\ctxloadluafile\filename\empty}% - \ctxlua{buffers.loadvisualizer("\ascii")}% - \endgroup} - -\unexpanded\def\setupprettytype - {\processingverbatimtrue % will move - \ctxlua{buffers.visualizers.reset()}} - -\def\setverbatimspaceskip - {\setbox\scratchbox\hbox{x}% - \spaceskip\wd\scratchbox +\def\setverbatimspaceskip % to be checked: must happen after font switch + {\spaceskip\fontcharwd\font`x\relax \xspaceskip\spaceskip} -\let\obeycharacters\relax % tab mess can go +\unexpanded\def\specialcontrolspace{\hskip\zeropoint\fastcontrolspace\hskip\zeropoint} \setvalue{\??tp:\c!lines:\v!yes }{\obeybreakpoints} \setvalue{\??tp:\c!lines:\v!hyphenated}{\obeyhyphens} -%setvalue{\??tp:\c!empty:\v!yes }{\obeyemptylines} -%setvalue{\??tp:\c!empty:\v!all }{\obeyallemptylines} - -\setvalue{\??tp:\c!option:\v!none }{\let\obeycharacters\relax} -\setvalue{\??tp:\c!option:\empty }{\let\obeycharacters\relax} -\setvalue{\??tp:\c!option:\v!color }{\setupprettiesintype{\typingparameter\c!option}% - \let\obeycharacters\setupprettytype} -\setvalue{\??tp:\c!option:\v!normal }{\let\obeycharacters\setupgroupedtype} -\setvalue{\??tp:\c!option:\v!slanted }{\let\obeycharacters\setupslantedtype} -\setvalue{\??tp:\c!option:\s!unknown }{\setupprettiesintype{\typingparameter\c!option}% - \let\obeycharacters\setupprettytype} -%setvalue{\??tp:\c!option:\v!commands }{\def\obeycharacters{\setupcommandsintype}} - -\def\dosetverbatimfont - {\redoconvertfont\dosetfontattribute{\currenttypingclass\currenttyping}\c!style - \normalnoligatures\font} - -\unexpanded\def\setupcommonverbatim - {\let\prettyidentifier\s!default - % - \def\prettyidentifierfont{\typingparameter\c!icommand}% - \def\prettyvariablefont {\typingparameter\c!vcommand}% - \def\prettynaturalfont {\typingparameter\c!ccommand}% - % - \ignorehyphens % default - \getvalue{\??tp:\c!lines:\typingparameter\c!lines}% - \getvalue{\??tp:\c!empty:\typingparameter\c!empty}% - \getvalue{\??tp:\c!option:\ifcsname\??tp:\c!option:\typingparameter\c!option\endcsname\typingparameter\c!option\else\s!unknown\fi}% - \setupverbatimcolor} - -\newtoks \everyinitializeverbatim - -\def\ignorebeginofpretty [#1]{} -\def\ignoreendofpretty {} - -\def\doverbatimbop{\bgroup\beginofpretty} -\def\doverbatimeop{\endofpretty\egroup} -\def\doverbatimsop{\endofpretty\egroup\bgroup\beginofpretty} - -\let\noverbatimbop\ignorebeginofpretty -\let\noverbatimeop\ignoreendofpretty -\let\noverbatimsop\ignorebeginofpretty - -\def\doinitializeverbatim % todo: combine all in one call is faster - {\ctxlua{buffers.visualizers.reset()}% - \doifelse{\typingparameter\c!space}\v!on - {\let\obs\fastcontrolspace}% - {\let\obs\specialobeyedspace}% - \edef\askedverbatimtab{\typingparameter\c!tab}% - \doifelse\askedverbatimtab\v!no - {\ctxlua{buffers.settablength(1)}} - {\doifnumberelse{\askedverbatimtab} - {\ctxlua{buffers.settablength(\askedverbatimtab)}} - {\ctxlua{buffers.settablength()}}}% - \ctxlua{buffers.doifelsevisualizer("\prettyidentifier")} - {\ctxlua{buffers.setvisualizer("\prettyidentifier")}% - \let\bop\doverbatimbop - \let\eop\doverbatimeop - \let\sop\doverbatimsop}% - {\ctxlua{buffers.setvisualizer("\v!typing")}% or resetdefaultvisualizer - \let\bop\noverbatimbop - \let\eop\noverbatimeop - \let\sop\noverbatimsop}% +\setvalue{\??tp:\c!space:\v!on }{\let\obeyedspace\specialcontrolspace} +\setvalue{\??tp:\c!space:\v!stretch }{\let\obeyedspace\specialstretchedspace} +\setvalue{\??tp:\c!space:\v!normal }{} +\setvalue{\??tp:\c!space:\v!fixed }{\let\obeyedspace\specialfixedspace} + +\setvalue{\??tp:\c!blank:\v!standard }{\ctxparskip} +\setvalue{\??tp:\c!blank:\v!small }{\smallskipamount} +\setvalue{\??tp:\c!blank:\v!medium }{\medskipamount} +\setvalue{\??tp:\c!blank:\v!big }{\bigskipamount} +\setvalue{\??tp:\c!blank:\v!halfline }{.5\baselineskip} +\setvalue{\??tp:\c!blank:\v!line }{\baselineskip} +\setvalue{\??tp:\c!blank:\v!none }{\zeropoint} + +\def\secondstageinitializetype + {\let\obeyedspace\specialobeyedspace + \csname\??tp:\c!space:\typeparameter\c!space\endcsname \relax\the\everyinitializeverbatim\relax} +\def\secondstageinitializetyping + {\let\obeyedspace\specialobeyedspace + \csname\??tp:\c!space:\typingparameter\c!space\endcsname + \csname\??tp:\c!lines:\typingparameter\c!lines\endcsname + \relax\the\everyinitializeverbatim\relax} + +\def\firststageinitializetype + {\let\obeylines\ignorelines + \ignorehyphens % default + \dosettypeattributes\c!style\c!color + \setcatcodetable\vrbcatcodes} + +\let\doverbatimsetlinemargin\relax + +\def\dodoverbatimsetlinemargin + {\getpagestatus + \ifrightpage + \hskip\typingparameter\c!oddmargin\relax + \else + \hskip\typingparameter\c!evenmargin\relax + \fi} + +\def\docheckverbatimmargins + {\scratchskip\typingparameter\c!oddmargin\relax + \ifzeropt\scratchskip + \else + \let\doverbatimsetlinemargin\dodoverbatimsetlinemargin + \fi + \scratchskip\typingparameter\c!evenmargin\relax + \ifzeropt\scratchskip + \else + \let\doverbatimsetlinemargin\dodoverbatimsetlinemargin + \fi + \ifx\doverbatimsetlinemargin\relax + \doadaptleftskip{\typingparameter\c!margin}% + \fi} + +\def\firststageinitializetyping + {\switchtobodyfont[\typingparameter\c!bodyfont]% + \docheckverbatimmargins + \dosettypingattributes\c!style\c!color + \doifsomething{\typingparameter\c!align}{\setupalign[\typingparameter\c!align]}% + \ignorehyphens} % default + +%D \macros +%D {definetype,setuptype} +%D +%D Specific inline verbatim commands can be defined with the +%D following command. + +\installcommandhandler{\??ty}{type}{\??ty} + \appendtoks - \resetfontfeature - \resetcharacterspacing -\to \everyinitializeverbatim + \normalexpanded{\dodefinetype{\currenttype}}% +\to \everydefinetype -% BEWARE: the noligatures will globally change the verbatim font's behaviour +\unexpanded\def\dodefinetype#1% + {\setuvalue{#1}{\dotype{#1}}} + +\appendtoks + \doinitializevisualizer{\typeparameter\c!option}% +\to \everysetuptype + +%D \macros +%D {definetyping,setuptyping} +%D +%D For most users the standard \type{\start}||\type{\stop}||pair +%D will suffice, but for documentation purposes the next +%D definition command can be of use: +%D +%D \starttyping +%D \definetyping[extratyping][margin=3em] +%D +%D \startextratyping +%D these extra ones are indented by 1 em +%D \stopextratyping +%D \stoptyping +%D +%D The definitions default to the standard typing values. + +\installcommandhandler{\??tp}{typing}{\??tp} + +\appendtoks + \normalexpanded{\dodefinetyping{\currenttyping}}% +\to \everydefinetyping + +\unexpanded\def\dodefinetyping#1% + {\setvalue{\e!start#1}{\dostarttyping{#1}}% + \setvalue{\e!stop #1}{\dostoptyping {#1}}} + +\appendtoks + \doinitializevisualizer{\typingparameter\c!option}% we can check at the tex end +\to \everysetuptyping + +\def\doinitializevisualizer#1% + {\ifproductionrun\ctxlua{visualizers.load("#1")}\fi} -% test case: -% % \definetype[typeTEX][option=tex] % % \typeTEX|\example---oeps|. this---ligates---again. @@ -210,33 +201,9 @@ %D %D \typebuffer \start \getbuffer \stop -\unexpanded\def\setupcommandsintype - {\ctxlua{buffers.set_escape("\currenttyping",\!!bs\typingparameter\c!escape\!!es)}} - -\appendtoks - \setupcommandsintype -\to \everyinitializeverbatim - -\unexpanded\def\setupslantedtype - {\slantedtypepermittedtrue} - -\ifx\setupprettytype \undefined \let\setupprettytype \relax \fi -\ifx\setupslantedtype \undefined \let\setupslantedtype \relax \fi -\ifx\setupgroupedtype \undefined \let\setupgroupedtype \relax \fi -\ifx\normalnoligatures\undefined \let\normalnoligatures\gobbleoneargument \fi - -%D The verbatim commands have a rather long and turbulent -%D history. Most users of \CONTEXT\ probably will never use -%D some of the features, but I've kept in mind that when one is -%D writing a users manual, about everything can and undoubtly -%D will be subject to a verbatim treatment. -%D %D Verbatim command are very sensitive to argument processing, %D which is a direct result of the \CATCODES\ being fixed at -%D reading time. With our growing understanding of \TEX, -%D especially of the mechanism that can be used for looking -%D ahead and manipulating \CATCODES, the verbatim support -%D became more and more advanced and natural. +%D reading time. %D %D Typesetting inline verbatim can be accomplished by %D \type{\type}, which in this sentence was typeset by saying @@ -253,14 +220,11 @@ %D \type{<<} and \type{>>} as delimiters. This alternative can %D be used in situations where slanted typeseting is needed. -% todo: we can use \letter... here: - \def\lesscharacter {<} \def\morecharacter {>} - -\chardef\texescape = `\\ -\chardef\leftargument = `\{ -\chardef\rightargument = `\} +\let\texescape \textbackslash +\let\leftargument \textbraceleft +\let\rightargument \textbraceright %D \macros %D {type} @@ -268,17 +232,17 @@ %D We define \type{\type} as a protected command. This command %D has several invocations: grouped, wirt boundary characters, %D and with font switches. - -% \starttyping -% normal: \par \type{xx<<..xx..<<xx <<xx>> >>..>>xx} \par \type<<....>> \par \type<<..<<xx>>..>> \par -% normal: \par \type{xx<..xx..<xx <slanted> >..>xx} \par \type{<....>} \par \type{<..<xx>..>} -% \setuptype[option=slanted] -% slanted: \par \type{xx<<..sl..<<xx <<sl>> xx>>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<<sl>>..>> \par -% slanted: \par \type{xx<<..sl..<xx <sl> xx>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<sl>..>> \par -% \setuptype[option=none] -% none: \par \type{xx<<..xx..<<xx <<xx>> >>..>>xx} \par \type<<....>> \par \type<<..<<xx>>..>> \par -% \stoptyping - +%D +%D \starttyping +%D normal: \par \type{xx<<..xx..<<xx <<xx>> >>..>>xx} \par \type<<....>> \par \type<<..<<xx>>..>> \par +%D normal: \par \type{xx<..xx..<xx <slanted> >..>xx} \par \type{<....>} \par \type{<..<xx>..>} +%D \setuptype[option=slanted] +%D slanted: \par \type{xx<<..sl..<<xx <<sl>> xx>>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<<sl>>..>> \par +%D slanted: \par \type{xx<<..sl..<xx <sl> xx>..sl..>>xx} \par \type<<..xx..>> \par \type<<..<sl>..>> \par +%D \setuptype[option=none] +%D none: \par \type{xx<<..xx..<<xx <<xx>> >>..>>xx} \par \type<<....>> \par \type<<..<<xx>>..>> \par +%D \stoptyping +%D %D When writing the manual to \CONTEXT\ and documenting this %D source we needed to typeset \type{<<} and \type{>>}. Because %D we wanted to do this in the natural way, we've adapted the @@ -287,7 +251,7 @@ %D further and treats the lone \type{<<} and \type{>>} a bit %D different. The \type {\null} prevents ligatures, which %D unfortunately turn up in Lucida fonts. - +%D %D The following lines show what happens when we set %D \type {option=commands}. %D @@ -306,120 +270,110 @@ %D %D \typebuffer +% beware, the command is supposed to do something like +% \framed and not manipulate content i.e. it gets no +% argument but something b/egrouped instead +% +% so, if we only had left and right it woul dbe: +% +% \def\doleftoftype {\typeparameter\c!left\bgroup} % we need the grouping in order +% \def\dorightoftype{\egroup\typeparameter\c!right} % to get the normal font +% +% but with command: + +\def\doleftoftype {\typeparameter\c!left\typeparameter\c!command\bgroup} +\def\dorightoftype{\egroup\typeparameter\c!right} + \unexpanded\def\type{\dotype\empty} +\unexpanded\def\typ {\dotyp \empty} -\def\dotype#1% was \dotype - {\dontleavehmode \bgroup - % new, \strut enables leading space in \type { abc } at par start / begstrut - % else no hyphenation (replaced by \dontleavehmode which saves unboxing) - % \begstrut - \let\currenttypingclass\??ty - \edef\currenttyping{#1}% - \catcode`\<=\@@other - \catcode`\>=\@@other - \futurelet\next\dodotype} +\def\dotype#1% + {\dontleavehmode + \bgroup + \edef\currenttype{#1}% + \doifnextoptionalelse\redotype\dodotype} + +\def\redotype[#1]% + {\getparameters[\??ty\currenttype][#1]% + \dodotype} \def\dodotype + {\doleftoftype + \futurelet\next\dodotypeone} + +\def\dotyp#1% + {\dontleavehmode + \bgroup + \edef\currenttype{#1}% + \lettypeparameter\v!lines\v!hyphenated + \let\specialobeyedspace\specialstretchedspace + \doifnextoptionalelse\redotype\dodotype} + +\def\dodotypeone {\ifx\next\bgroup \@EA\dodotypeA \else - \@EA\dodotypeAD + \@EA\dodotypetwo \fi} -\def\dodotypeAD +\def\dodotypetwo + {\catcode`<=\othercatcode % old precaution + \catcode`>=\othercatcode % old precaution + \futurelet\next\dodotypethree} + +\def\dodotypethree {\if\next<% - \doifelse{\typingparameter\c!option}\v!none{\@EA\dodotypeB}{\@EA\dodotypeC}% + \@EA\dodotypeB \else - \@EA\dodotypeD + \@EA\dodotypeC \fi} \def\dodotypeA - {\initializetype % probably too much - \verbatimcolor - \dosetverbatimfont - \setcatcodetable \typcatcodesa - \dodotypeAA} - -\def\dodotypeAA#1% - {\doinitializeverbatim - \def\obs{\obeyedspace}% - \ctxlua{buffers.hooks.flush_inline(\!!bs\detokenize{#1}\!!es)}% - \egroup} + {\firststageinitializetype + \setcatcodetable\tpacatcodes + \dodotypenormal} \def\dodotypeB#1% - {\initializetype - \verbatimcolor - \dosetverbatimfont - \setcatcodetable \typcatcodesb - \dodotypeBB} - -\def\dodotypeBB#1% - {\doinitializeverbatim - \ctxlua{buffers.visualizers.flush_nested(\!!bs\detokenize{#1}\!!es,false)}% - \egroup - \gobbleoneargument} % grab last > + {\firststageinitializetype + \setcatcodetable\tpbcatcodes + \dodotypenested} \def\dodotypeC#1% - {\initializetype - \verbatimcolor - \dosetverbatimfont - \setcatcodetable \typcatcodesb - \dodotypeCC} - -\def\dodotypeCC#1% - {\doinitializeverbatim - \ifx\obeycharacters\setupprettytype % temp hack, we need a proper signal - \ctxlua{buffers.hooks.flush_inline([\!!bs\detokenize{#1}\!!es,true)}% - \else - \def\obs{\obeyedspace}% - \ctxlua{buffers.visualizers.flush_nested(\!!bs\detokenize{#1}\!!es,true)}% - \fi - \egroup - \gobbleoneargument} % grab last > + {\firststageinitializetype + \setcatcodetable\vrbcatcodes + \def\next##1#1{\dodotypenormal{##1}}% + \next} + +\def\dodotypenormal#1% + {\secondstageinitializetype + \dostarttagged\t!verbatim\currenttype + \ctxcommand{typestring { + data = \!!bs\detokenize{#1}\!!es, + tab = "\typeparameter\c!tab", + method = "\typeparameter\c!option", + nature = "inline", + }}% + \dostoptagged + \dorightoftype + \egroup} -\def\dodotypeD#1% - {\initializetype - \verbatimcolor - \dosetverbatimfont - \setcatcodetable \typcatcodesa - \def\dodotypeDD##1#1{\dodotypeAA{##1}}% - \dodotypeDD} - -\def\dodotypeDD#1% - {\doinitializeverbatim - \ctxlua{buffers.hooks.flush_inline(\!!bs\detokenize{#1}\!!es,true)}% +\def\dodotypenested#1% + {\secondstageinitializetype + \dostarttagged\t!verbatim\currenttype + \ctxcommand{typestring { + data = \!!bs\detokenize{#1}\!!es, + tab = "\typeparameter\c!tab", + method = "nested", % we force a special visualizer + option = "\typeparameter\c!option", % extra visualizer (maybe: nested,\typeparameter\c!option) + nature = "inline", + }}% + \dostoptagged + \dorightoftype \egroup \gobbleoneargument} % grab last > -%D The neccessary initializations are done by calling -%D \type{\initializetype} which in return calls for the support -%D macro \type{\setupinlineverbatim}. - -\def\initializetype - {\let\obeylines\ignorelines - \setupcommonverbatim - %\dosetverbatimfont - %\setverbatimspaceskip - %\setupcopyverbatim % not needed - \setcatcodetable\vrbcatcodes} - -%D \macros -%D {setuptype} -%D -%D Some characteristics of \type{\type} can be set up by: - -\unexpanded\def\setuptype - {\dodoubleempty\dosetuptype} - -\def\dosetuptype[#1][#2]% - {\ifsecondargument - \getparameters[\??ty#1][#2]% - \else - \getparameters[\??ty][#1]% - \fi} - %D \macros -%D {typ,obeyhyphens,obeybreakpoints} +%D {obeyhyphens,obeybreakpoints} %D %D Although it's not clear from the macros, one character %D trait of this macros, which are build on top of the support @@ -428,11 +382,13 @@ %D works all right, but a decent hyphenation support of %D \type{\tt} text will be implemented soon. -\def\specialobeyedspace {\hskip\interwordspace\relax} % better than spaceskip -\def\specialcontrolspace{\hskip\zeropoint\hbox{\normalcontrolspace}\hskip\zeropoint\relax} +\def\specialfixedspace {\kern\interwordspace\relax} +\def\specialobeyedspace {\hskip\interwordspace\relax} % better than spaceskip +\def\specialstretchedspace{\hskip.5\interwordspace\!!plus.125\interwordstretch\relax} % more but not less +\def\specialcontrolspace {\hskip\zeropoint\hbox{\normalcontrolspace}\hskip\zeropoint\relax} \def\obeyhyphens - {\let\obeyedspace \specialobeyedspace + {\let\obeyedspace \specialobeyedspace % maybe \specialstretchedspace \let\controlspace\specialcontrolspace \spaceskip.25em\relax} % hm a bit of stretch ! @@ -446,11 +402,6 @@ \let\controlspace\specialcontrolspace \spaceskip.5em\relax} -\unexpanded\def\typ - {\bgroup - \let\@@tylines\v!hyphenated - \futurelet\next\dodotype} - %D \macros %D {tex,arg,mat,dis} %D @@ -461,38 +412,11 @@ %D but we've decided not to use that slow and sometimes %D troublesome solution. Instead we stick to some 'old' %D \CONTEXT\ macros for typesetting typical \TEX\ characters. -%D -%D The next implementation is more clear but less versatile, -%D so we treated it for a beter one. -%D -%D \starttyping -%D \def\dospecialtype#1#2% -%D {\bgroup -%D \initializetype -%D \catcode`\{=\@@begingroup -%D \catcode`\}=\@@endgroup -%D \def\dospecialtype% -%D {\def\dospecialtype{#2\egroup}% -%D \bgroup -%D \aftergroup\dospecialtype -%D #1}% -%D \afterassignment\dospecialtype -%D \let\next=} -%D -%D \unexpanded\def\tex{\dospecialtype\texescape\relax} -%D \unexpanded\def\arg{\dospecialtype\leftargument\rightargument} -%D \unexpanded\def\mat{\dospecialtype\$\$} -%D \unexpanded\def\dis{\dospecialtype{\$\$}{\$\$}} -%D \stoptyping \def\setgroupedtype - {\let\currenttypingclass\??ty - \initializetype - \verbatimcolor - \dosetverbatimfont - %\setcatcodetable \typcatcodesa - \catcode`\{=\@@begingroup - \catcode`\}=\@@endgroup} + {\firststageinitializetype + \catcode\leftbraceasciicode \begingroupcatcode + \catcode\rightbraceasciicode\endgroupcatcode} \unexpanded\def\tex{\groupedcommand{\setgroupedtype\texescape}{\relax}} \unexpanded\def\arg{\groupedcommand{\setgroupedtype\leftargument}{\rightargument}} @@ -504,118 +428,17 @@ \let\normaltextmat\mat \let\normaltextdis\dis -\def\astype - {\groupedcommand\dorawtype\relax} - -\def\dorawtype - {\let\currenttypingclass\??ty - \normalverbatimcolor % \verbatimcolor - \dosetverbatimfont} - -%D \macros -%D {starttyping} -%D -%D Display verbatim is realized far more easy, which is mostly -%D due to the fact that we use \type{\stop...} as delimiter. -%D The implementation inherits some features, for instance the -%D support of linenumbering, which can best be studied in the -%D documented support module. - -\let\currenttyping \empty -\let\currenttypingclass\??ty % saveguard - -\def\typingparameter#1% - {\ifcsname\currenttypingclass\currenttyping#1\endcsname - \csname\currenttypingclass\currenttyping#1\endcsname - \else\ifcsname\currenttypingclass#1\endcsname - \csname\currenttypingclass#1\endcsname - \fi\fi} - -\def\settypingparameter#1#2% - {\setvalue{\currenttypingclass\currenttyping#1}{#2}} - -\def\setxtypingparameter#1#2% - {\setxvalue{\currenttypingclass\currenttyping#1}{#2}} - -\setvalue{\??tp:\c!blank:\v!standard}{\ctxparskip} -\setvalue{\??tp:\c!blank:\v!small }{\smallskipamount} -\setvalue{\??tp:\c!blank:\v!medium }{\medskipamount} -\setvalue{\??tp:\c!blank:\v!big }{\bigskipamount} -\setvalue{\??tp:\c!blank:\v!halfline}{.5\baselineskip} -\setvalue{\??tp:\c!blank:\v!line }{\baselineskip} -\setvalue{\??tp:\c!blank:\v!none }{\zeropoint} - -\def\doopenupverbatimlineindeed - {\getpagestatus - \ifrightpage - \hskip\typingparameter\c!oddmargin\relax - \else - \hskip\typingparameter\c!evenmargin\relax - \fi} - -\def\initializetyping - {%\donefalse - \switchtobodyfont[\typingparameter\c!bodyfont]% - \donefalse - \scratchskip\typingparameter\c!oddmargin\relax - \ifzeropt\scratchskip\else\donetrue\fi - \scratchskip\typingparameter\c!evenmargin\relax - \ifzeropt\scratchskip\else\donetrue\fi - \ifdone - \let\doopenupverbatimline\doopenupverbatimlineindeed - \else - \doadaptleftskip{\typingparameter\c!margin}% - \fi - % no symbolic blanks ! - \edef\!!stringa{\executeifdefined{\??bo\typingparameter\c!blank}{\typingparameter\c!blank}}% - \scratchskip\executeifdefined{\??tp:\c!blank:\!!stringa}\!!stringa\relax - \ifgridsnapping - % this will be adapted - \ifdim\scratchskip=.5\baselineskip\relax - \edef\verbatimbaselineskip{\the\scratchskip}% new - \else - \edef\verbatimbaselineskip{\the\baselineskip}% - \fi - \else - \edef\verbatimbaselineskip{\the\scratchskip}% - \fi -\doifsomething{\typingparameter\c!align}{\setupalign[\typingparameter\c!align]}% - \setupcommonverbatim} +\def\astype{\groupedcommand{\dosettypeattributes\c!style\c!color}{}} %D The basic display verbatim commands are defined in an %D indirect way. As we will see, they are a specific case of a %D more general mechanism. -\newif\ifoptimizeverbatim \optimizeverbatimtrue - -\let \beginofverbatimlines \relax -\let \endofverbatimlines \relax - -\def\doverbatimnobreak - {\ifoptimizeverbatim\penalty500 \fi} - -\def\doverbatimgoodbreak - {\ifoptimizeverbatim\penalty\linepenalty\fi} - -% \def\doflushverbatimline -% {\expandafter\dodoverbatimline\expandafter{\savedverbatimline}} -% \def\doverbatimbeginofline#1% linenumber (optional provided by mkiv / todo) -% {\dontleavehmode -% \strut -% \the\everyline} -% \def\doverbatimendofline -% {\par} -% \def\doverbatimemptyline -% {\strut -% \par} -% \let\handleverbatimline=\relax - -% we need this hack because otherwise verbatim skips -% the first line (everything after the initial command) +\let\beginofverbatimlines\relax +\let\endofverbatimlines \relax \def\dostarttyping#1% tricky non standard lookahead {\bgroup - \let\currenttypingclass\??tp \edef\currenttyping{#1}% \obeylines \futurelet\nexttoken\dodostarttyping} @@ -630,36 +453,40 @@ \def\nododostarttyping {\dododostarttyping[]} -\def\dotypefileverbatim - {\doinitializeverbatim - \beginofverbatimlines - \ctxlua{buffers.typefile("\readfilename","\typingparameter\c!strip","\typingparameter\c!range")}% - \endofverbatimlines} - -\def\dotypefilelinesverbatim#1#2% - {#1\dotypefileverbatim#2} +\def\dododostarttyping[#1]% + {\typingparameter\c!before + \startpacked[\v!blank] + \doifassignmentelse{#1} + {\setuptyping[\currenttyping][#1]} + {\doifinset\v!continue{#1}{\setuptyping[\currenttyping][\c!continue=\v!yes]}}% + \dosetuptypelinenumbering + \firststageinitializetyping + \normalexpanded{\dotypeblockverbatim{\e!start\currenttyping}{\e!stop\currenttyping}}} \unexpanded\def\dotypeblockverbatim#1#2% - {\dowithbuffer{_typing_}{#1}{#2} - {} - {\doinitializeverbatim - \beginofverbatimlines - \ctxlua{buffers.type("_typing_","\typingparameter\c!strip","\typingparameter\c!range")}% - \endofverbatimlines - \csname#2\endcsname}} + {\dowithbuffer{_typing_}{#1}{#2}{}{\dodotypeblockverbatim{#1}{#2}}} -\def\dododostarttyping[#1]% - {\typingparameter\c!before - \startpacked % includes \bgroup - \dosetuptypelinenumbering{#1}% - \initializetyping - \dosetverbatimfont - \startverbatimcolor - \normalexpanded{\dotypeblockverbatim{\e!start\currenttyping}{\e!stop\currenttyping}}} % was s!start +\def\dodotypeblockverbatim#1#2% + {\secondstageinitializetyping + \dostarttagged\t!verbatimblock\currenttyping + \beginofverbatimlines + \dostarttagged\t!verbatimlines\empty + \ctxcommand{typebuffer { + name = "_typing_", + strip = "\typingparameter\c!strip", + range = "\typingparameter\c!range", + tab = "\typingparameter\c!tab", + method = "\typingparameter\c!option", + escape = \!!bs\typingparameter\c!escape\!!es, + nature = "display", + }}% + \dostoptagged + \endofverbatimlines + \dostoptagged + \csname#2\endcsname} \def\dostoptyping#1% hm, currenttyping - {\stopverbatimcolor - \stoppacked % includes \egroup + {\stoppacked \typingparameter\c!after \normalexpanded{\egroup\checknextindentation[\typingparameter\c!indentnext]}% \dorechecknextindentation} @@ -700,8 +527,7 @@ %D %D \starttext %D -%D % \typefile[file][range={3,6}]{whatever.tex} -%D +%D % \typefile[file][range={3,6}] {whatever.tex} %D % \typefile[file][range={3,+2}]{whatever.tex} %D %D \typefile[file][range={label:start:one,label:stop:one}]{whatever.tex} @@ -710,128 +536,6 @@ %D \stoptyping %D \macros -%D {setuptyping} -%D -%D The setup of typing accepts two arguments. The optional -%D first one identifies the user defined ones. If only one -%D argument is given, the values apply to both the standard -%D command \type{\starttyping} and \type{\typefile}. - -\def\dosetuptyping[#1][#2]% - {\ifsecondargument - \getparameters[\??tp#1][#2]% - \else - \getparameters[\??tp][#1]% - \fi} - -\unexpanded\def\setuptyping - {\dodoubleempty\dosetuptyping} - -%D \macros -%D {definetype} -%D -%D Specific inline verbatim commands can be defined with the -%D following command. - -\unexpanded\def\definetype - {\dodoubleempty\dodefinetype} - -\def\dodefinetype[#1][#2]% - {\setuvalue{#1}{\dotype{#1}}% - \getparameters[\??ty#1][#2]} - -%D \macros -%D {definetyping} -%D -%D For most users the standard \type{\start}||\type{\stop}||pair -%D will suffice, but for documentation purposes the next -%D definition command can be of use: -%D -%D \starttyping -%D \definetyping[extratyping][margin=3em] -%D -%D \startextratyping -%D these extra ones are indented by 1 em -%D \stopextratyping -%D \stoptyping -%D -%D The definitions default to the standard typing values. - -% TODO: parent etc ! - -\def\presettyping[#1][#2]% brrr also use parent here - {\copyparameters[\??tp#1][\??tp][\c!color,\c!style]% - \getparameters [\??tp#1][#2]} - -\def\dodefinetyping[#1][#2]% - {\setvalue{\e!start#1}{\dostarttyping{#1}}% - \setvalue{\e!stop #1}{\dostoptyping {#1}}% - \presettyping[#1][#2]} - -\unexpanded\def\definetyping - {\dodoubleempty\dodefinetyping} - -%D We can use some core color commands. These are faster than -%D the standard color switching ones and work ok on a line by -%D line basis. -%D -%D \starttyping -%D \unexpanded\def\setupverbatimcolor% -%D {\edef\prettypalet{\prettyidentifier\typingparameter\c!palet}% -%D \def\beginofpretty[##1]{\startcolormode{\prettypalet:##1}}% -%D \def\endofpretty {\stopcolormode}} -%D \stoptyping -%D -%D Since we support a global color too, the folowing -%D definition is better: - -\def\normalbeginofpretty [#1]{\startcolor[\prettypalet:#1]}% -\def\normalendofpretty {\stopcolor} -\def\normalstartverbatimcolor{\startcolor[\typingparameter\c!color]}% -\def\normalstopverbatimcolor {\stopcolor} -\def\normalverbatimcolor {\getvalue{\typingparameter\c!color}}% command ! - -\unexpanded\def\setupnormalprettyverbatim - {\edef\prettypalet{\prettyidentifier\prettypalet}% - \let\beginofpretty \normalbeginofpretty - \let\endofpretty \normalendofpretty - \let\startverbatimcolor\normalstartverbatimcolor - \let\stopverbatimcolor \normalstopverbatimcolor - \let\verbatimcolor \normalverbatimcolor} - -\unexpanded\def\setupignoreprettyverbatim - {\let\prettypalet \empty - \let\beginofpretty \ignorebeginofpretty - \let\endofpretty \ignoreendofpretty - \let\startverbatimcolor\normalstartverbatimcolor - \let\stopverbatimcolor \normalstopverbatimcolor - \let\verbatimcolor \normalverbatimcolor} - -\unexpanded\def\setupverbatimcolor - {\edef\prettypalet{\typingparameter\c!palet}% - \ifx\prettypalet\empty - \setupignoreprettyverbatim - \else - \setupnormalprettyverbatim - \fi} - -\let\beginofpretty \ignorebeginofpretty -\let\endofpretty \ignoreendofpretty -\let\prettypalet \empty -\let\startverbatimcolor\relax -\let\stopverbatimcolor \relax -\let\verbatimcolor \relax - -%D \macros -%D {EveryPar, EveryLine, iflinepar} -%D -%D One of the features of these commands is the support of -%D \type{\EveryPar}, \type{\EveryLine} and \type{\iflinepar}. -%D In the documentation of the verbatim support module we give -%D some examples of line- and paragraph numbering using these -%D macros. - -%D \macros %D {typefile} %D %D Typesetting files verbatim (for the moment) only supports @@ -839,118 +543,95 @@ %D setup values are inherited from display verbatim. %D The implementation of \type{\typefile} is straightforward: -% new feature (not yet 100\% ok) -% -% \setuptyping[file][numbering=file] -% -% \typefile[start=2,nlines=3]{zapf} -% \typefile[start=continue,nlines=13]{zapf} -% \typefile{zapf} -% -% \setuptyping[file][numbering=line] -% -% \typefile[start=4,step=3]{zapf} -% \typefile{zapf} +% [category] [settings] {name} % for historic reasons, all filenames are {} \def\typefile {\dodoubleempty\dotypefile} \def\dotypefile[#1][#2]#3% - {\ifsecondargument - \dodotypefile[#1][#2]{#3}% + {\bgroup + \ifsecondargument + \setuptyping[#1][#2]% + \dododotypefile{#1}{#3}% \else\iffirstargument \doifassignmentelse{#1} - {\dodotypefile[\v!file][#1]{#3}} - {\dodotypefile[#1][]{#3}}% + {\setuptyping[\v!file][#1] + \dododotypefile\v!file{#3}} + {\dododotypefile{#1}{#3}}% \else - \dodotypefile[\v!file][]{#3}% - \fi\fi} - -\def\dosetuptypelinenumbering#1% fuzzy - {%\ifcsname\currenttypingclass\currenttyping\c!start\endcsname \else - % \setuptyping[\currenttyping][\c!start=1,\c!stop=,\c!step=1,\c!continue=\v!no,\c!nlines=]% - %\fi - \doifassignmentelse{#1}{\setuptyping[\currenttyping][#1]}\donothing - \doifelse{\typingparameter\c!numbering}\v!file - {% kind of special: filters lines ! - \setuplinenumbering[\currenttyping][\c!method=\v!file]% - \donetrue} - {\doifelse{\typingparameter\c!numbering}\v!line - {\doifinset\v!continue{#1}{\setuptyping[\currenttyping][\c!continue=\v!yes]}% fails: \settypingparameter\c!continue{\v!yes} - \donetrue} - {\donefalse}}% - \ifdone - \edef\beginofverbatimlines{\noexpand\startlinenumbering - [\currenttyping]% - [\c!continue=\typingparameter\c!continue, - \c!method=\v!type, - \c!start=\typingparameter\c!start, - \c!stop=\typingparameter\c!stop, % ? - \c!step=\typingparameter\c!step]% - }% - \def\endofverbatimlines{\stoplinenumbering}% - \fi} - -\def\reporttypingerror#1% temp hack - {\blank - \dontleavehmode\hbox\bgroup - \expanded{\defconvertedargument\noexpand\ascii{#1}}% - \tttf[\makemessage\m!verbatims1\ascii]% - \showmessage\m!verbatims1\ascii - \egroup - \blank} - -\def\dosometyping#1#2#3#4#5% - {\bgroup - \let\currenttypingclass\??tp - \edef\currenttyping{#1}% - \typingparameter\c!before - \startpacked % includes \bgroup - \dosetuptypelinenumbering{#2}% - \doifinset{\typingparameter\c!option}{\v!commands,\v!slanted,\v!normal} - {\setuptyping[#1][\c!option=\v!none]}% - \doif{\typingparameter\c!option}\v!color - {\expandafter\aftersplitstring#3\at.\to\prettyidentifier - \settypingparameter\c!option{\prettyidentifier}}% - \initializetyping - \dosetverbatimfont - \startverbatimcolor - \scratchcounter - \ifcsname\currenttypingclass#3\v!global\c!start\endcsname - \numexpr\csname\currenttypingclass#3\v!global\c!start\endcsname+\plusone\relax - \else - \plusone - \fi - \setxvalue{\currenttypingclass#3\v!global\c!start}{\the\scratchcounter}% no direct setxvalue as it defines beforehand - \doifelsenothing{\typingparameter\c!start} - {#4} - {\doif{\typingparameter\c!start}\v!continue - {\setevalue{\currenttypingclass#1\c!start}% - {\getvalue{\currenttypingclass#3\v!global\c!start}}}% - \doifelsenothing{\typingparameter\c!stop} - {\doifelsenothing{\typingparameter\c!nlines} - {#4} - {\setxvalue{\currenttypingclass#3\v!global\c!start}% - {\the\numexpr\typingparameter\c!start+\typingparameter\c!nlines+\minusone\relax}% - #5{\typingparameter\c!start}{\getvalue{\currenttypingclass#3\v!global\c!start}}}}% - {#5{\typingparameter\c!start}{\typingparameter\c!stop}}}% - \stopverbatimcolor - \stoppacked - \typingparameter\c!after + \dododotypefile\v!file{#3}% + \fi\fi \egroup} +\def\dododotypefile#1#2% + {\doifelsetypingfile{#2} + {\dodododotypefile{#1}\readfilename} + {\showmessage\m!verbatims1{#2}}} + \def\doifelsetypingfile#1% sets \readfilename (we will make this proper mkiv i.e. less messy) {\doiflocfileelse{#1} {\firstoftwoarguments} {\doifinputfileelse{#1} -% {\def\readfilename{\pathplusfile\filepath{#1}}\firstoftwoarguments} % messy, looks wrong too {\def\readfilename{#1}\firstoftwoarguments} % messy, looks wrong too {\secondoftwoarguments}}} -\def\dodotypefile[#1][#2]#3% - {\doifelsetypingfile{#3} - {\dosometyping{#1}{#2}{#3}\dotypefileverbatim\dotypefilelinesverbatim} - {\reporttypingerror{#3}}} +\def\dodododotypefile#1#2% category name + {\edef\currenttyping{#1}% + \typingparameter\c!before + \startpacked[\v!blank] + \dosetuptypelinenumbering + \firststageinitializetyping + \secondstageinitializetyping + \dostarttagged\t!verbatimblock\currenttyping + \beginofverbatimlines + \dostarttagged\t!verbatimlines\empty + \ctxcommand{typefile { + name = "#2", + strip = "\typingparameter\c!strip", + range = "\typingparameter\c!range", + regime = "\currentregime", + tab = "\typingparameter\c!tab", + method = "\typingparameter\c!option", + nature = "display", + }}% + \dostoptagged + \endofverbatimlines + \dostoptagged + \stoppacked + \typingparameter\c!after} + +%D Line numbering: + +\newconditional\verbatimnumberinglines + +\def\beginofverbatimlinenumbering + {\startlinenumbering + [\currenttyping]% + [\c!continue=\typingparameter\c!continue, + \c!method=\v!type, + \c!start=\typingparameter\c!start, + \c!stop=\typingparameter\c!stop, % ? + \c!step=\typingparameter\c!step]} + +\def\endofverbatimlinenumbering + {\stoplinenumbering} + +\def\dosetuptypelinenumbering + {\ifdefined\startlinenumbering + \edef\currenttypingnumbering{\typingparameter\c!numbering}% + \ifx\currenttypingnumbering\v!file + \setuplinenumbering[\currenttyping][\c!method=\v!file]% + \settrue\verbatimnumberinglines + \else\ifx\currenttypingnumbering\v!line + \settrue\verbatimnumberinglines + \else + \setfalse\verbatimnumberinglines + \fi\fi + \ifconditional\verbatimnumberinglines + \let\beginofverbatimlines\beginofverbatimlinenumbering + \let\endofverbatimlines \endofverbatimlinenumbering + \fi + \fi} %D \macros %D {filename} @@ -965,9 +646,12 @@ \unexpanded\def\filename#1{{\tttf\hyphenatedfilename{#1}}} -%D And a bonus macro: +%D \macros +%D {verbatim} +%d +%D And a bonus macro, an unexpanded detokenize: -\def\verbatim#1{\defconvertedargument\ascii{#1}\ascii} +\unexpanded\def\verbatim#1{\detokenize{#1}} %D The setups for display verbatim and file verbatim are %D shared. One can adapt the extra defined typing environments, @@ -977,217 +661,191 @@ \setuptyping [ \c!before=\blank, \c!after=\blank, - \c!bodyfont=, - \c!color=, + %\c!bodyfont=, + %\c!color=, \c!space=\v!off, \c!page=\v!no, - \c!tab=\s!ascii, + \c!tab=\v!yes, % what is this: \s!ascii ? \c!option=\v!none, - \c!palet=colorpretty, \c!text=\v!no, \c!style=\tttf, - \c!icommand=\ttsl, - \c!vcommand=, - \c!ccommand=\tttf, \c!indentnext=\v!yes, \c!margin=\!!zeropoint, \c!evenmargin=\!!zeropoint, \c!oddmargin=\!!zeropoint, \c!blank=\v!line, - \c!escape=, % yes | no | START,STOP BTEX,ETEX + %\c!escape=, % yes | no | {START,STOP} | default when yes: {BTEX,ETEX} \c!numbering=\v!no, - \c!lines=, - \c!range=, - \c!empty=, + %\c!lines=, + %\c!range=, \c!start=1, - \c!stop=, + %\c!stop=, \c!step=1, - \c!continue=, - \c!strip=\v!no, % auto or number - \c!nlines=] + %\c!continue=, + \c!strip=\v!no] %auto or number \definetyping[\v!typing] -\presettyping[\v!file][] - -% \setuptyping % not needed -% [\v!file] -% [\c!start=1, -% \c!stop=, -% \c!step=1, -% \c!continue=, -% \c!nlines=] +\setuptyping[\v!file] [\s!parent=\??tp\v!typing] % we don't want \start..\stop overload +\setuptyping[\v!buffer][\s!parent=\??tp\v!file] % we don't want \start..\stop overload %D The setups for inline verbatim default to: \setuptype [ \c!space=\v!off, - \c!color=, + %\c!color=, \c!style=\tt\tf, % \tttf gives problems with {\tx \type...} + %\c!option=\v!normal, \c!page=\v!no, - \c!tab=\v!yes, - \c!palet=colorpretty, - \c!option=\v!normal] - -%D Beware: only a few are currently (re)implemented in \MKIV. - -\definetyping[RAW] [\c!option=RAW] -\definetyping[MP] [\c!option=MP] % done -\definetyping[PL] [\c!option=PL] -\definetyping[PM] [\c!option=PL] -\definetyping[JS] [\c!option=JS] -\definetyping[JV] [\c!option=JV] -\definetyping[SQL] [\c!option=SQL] -\definetyping[TEX] [\c!option=TEX] % done -\definetyping[PAS] [\c!option=PAS] -\definetyping[PASCAL][\c!option=PAS] -\definetyping[MOD] [\c!option=PAS] -\definetyping[MODULA][\c!option=PAS] -\definetyping[DELPHI][\c!option=PAS] -\definetyping[EIFFEL][\c!option=EIF] -\definetyping[XML] [\c!option=XML] -\definetyping[LUA] [\c!option=LUA] % done - -\installprettytype [RAW] [RAW] - -\installprettytype [TEX] [TEX] - -\installprettytype [PERL] [PL] -\installprettytype [PL] [PL] -\installprettytype [PM] [PL] - -\installprettytype [METAPOST] [MP] -\installprettytype [METAFONT] [MP] -\installprettytype [MP] [MP] -\installprettytype [MF] [MP] - -\installprettytype [JAVASCRIPT] [JS] -\installprettytype [JAVA] [JV] -\installprettytype [JS] [JS] -\installprettytype [JV] [JV] - -\installprettytype [SQL] [SQL] - -\installprettytype [PASCAL] [PAS] -\installprettytype [PAS] [PAS] -\installprettytype [MODULA] [PAS] -\installprettytype [MOD] [PAS] - -\installprettytype [EIFFEL] [EIF] -\installprettytype [EIF] [EIF] -\installprettytype [E] [EIF] - -\installprettytype [XML] [XML] - -\installprettytype [LUA] [LUA] - -%D We use the \CONTEXT\ color system for switching to and from -%D color mode. We can always redefine these colors afterwards. - -\definecolor [colorprettyone] [r=.9, g=.0, b=.0] % red -\definecolor [colorprettytwo] [r=.0, g=.8, b=.0] % green -\definecolor [colorprettythree] [r=.0, g=.0, b=.9] % blue -\definecolor [colorprettyfour] [r=.8, g=.8, b=.6] % yellow - -\definecolor [grayprettyone] [s=.30] -\definecolor [grayprettytwo] [s=.45] -\definecolor [grayprettythree] [s=.60] -\definecolor [grayprettyfour] [s=.75] - -\definepalet - [colorpretty] - [ prettyone=colorprettyone, - prettytwo=colorprettytwo, - prettythree=colorprettythree, - prettyfour=colorprettyfour] - -\definepalet - [graypretty] - [ prettyone=grayprettyone, - prettytwo=grayprettytwo, - prettythree=grayprettythree, - prettyfour=grayprettyfour] - -\definepalet [TEXcolorpretty] [colorpretty] -\definepalet [TEXgraypretty] [graypretty] -\definepalet [PLcolorpretty] [colorpretty] -\definepalet [PLgraypretty] [graypretty] -\definepalet [PMcolorpretty] [colorpretty] -\definepalet [PMgraypretty] [graypretty] -\definepalet [MPcolorpretty] [colorpretty] -\definepalet [MPgraypretty] [graypretty] -\definepalet [JVcolorpretty] [colorpretty] -\definepalet [JVgraypretty] [graypretty] -\definepalet [JScolorpretty] [colorpretty] -\definepalet [JSgraypretty] [graypretty] -\definepalet [SQLcolorpretty] [colorpretty] -\definepalet [SQLgraypretty] [graypretty] -\definepalet [PAScolorpretty] [colorpretty] -\definepalet [PASgraypretty] [graypretty] -\definepalet [EIFcolorpretty] [colorpretty] -\definepalet [EIFgraypretty] [graypretty] -\definepalet [XMLcolorpretty] [colorpretty] -\definepalet [XMLgraypretty] [graypretty] -\definepalet [LUAcolorpretty] [colorpretty] -\definepalet [LUAgraypretty] [graypretty] - -% patched from verb-ini (todo) - -% \let\beginverbatimline\relax -% \let\endverbatimline \relax - -% \appendtoks whatever\par\to\everyverbatimbeginofdisplay -% \appendtoks whatever\to\everyverbatimendofdisplay -% \appendtoks [\to\everyverbatimbeginofinline -% \appendtoks ]\to\everyverbatimendofinline - -\let\doopenupverbatimline\empty - -\newtoks\everyverbatimbeginofdisplay -\newtoks\everyverbatimendofdisplay -\newtoks\everyverbatimbeginofinline -\newtoks\everyverbatimendofinline - -\let\currentverbatimpretty\empty - -\def\doverbatimbeginofdisplay#1% - {\edef\currentverbatimpretty{#1}% - \the\everyverbatimbeginofdisplay} - -\def\doverbatimendofdisplay - {\the\everyverbatimendofdisplay} - -\def\doverbatimbeginofinline#1% - {\edef\currentverbatimpretty{#1}% - \the\everyverbatimbeginofinline} - -\def\doverbatimendofinline - {\the\everyverbatimendofinline} - -\def\doverbatimbeginofline#1% linenumber - {\bgroup % due to pretty status - \iflinepar\else\EveryPar{}\fi - \noindent % was wrong: \dontleavehmode - \xdef\dokeepverbatimlinedata % hm, still needed? - {\parindent \the\parindent - \hangindent\the\hangindent - \hangafter \the\hangafter - \leftskip \the\leftskip - \rightskip \the\rightskip}% - \egroup - \dokeepverbatimlinedata - \doopenupverbatimline + \c!tab=\v!yes] + +%D Buffers + +% [name] [settings] | [name] | [settings] + +\unexpanded\def\typebuffer + {\dodoubleempty\dotypebuffer} + +\unexpanded\def\dotypedefinedbuffer + {\dotripleempty\dodotypedefinedbuffer} + +\appendtoks + \setuevalue{\e!type\currentbuffer}% + {\noexpand\dotypedefinedbuffer + [\v!buffer]% + [def-\number\nofdefinedbuffers]}% +\to \everydefinebuffer + +\def\dotypebuffer[#1][#2]% + {\bgroup + \ifsecondargument + \setuptyping[\v!buffer][#2]% + \processcommalist[#1]{\dododotypebuffer\v!buffer}% [name] [settings] + \else\iffirstargument + \doifassignmentelse{#1} + {\setuptyping[\v!buffer][#1]% + \dododotypebuffer\v!buffer\empty}% [settings] + {\processcommalist[#1]{\dododotypebuffer\v!buffer}}% [name] + \else + \dododotypebuffer\v!buffer\empty% [] + \fi\fi + \egroup} + +\def\dodotypedefinedbuffer[#1][#2][#3]% category name settings + {\bgroup + \ifthirdargument + \setuptyping[#1][#3]% + \fi + \dododotypebuffer{#1}{#2}% + \egroup} + +\def\dododotypebuffer#1#2% category name + {\edef\currenttyping{#1}% + \typingparameter\c!before + \startpacked[\v!blank] + \dosetuptypelinenumbering + \firststageinitializetyping + \secondstageinitializetyping + \beginofverbatimlines + \dostarttagged\t!verbatimblock{#1}% + \ctxcommand{typebuffer { + name = "#2", + strip = "\typingparameter\c!strip", + range = "\typingparameter\c!range", + regime = "\currentregime", + tab = "\typingparameter\c!tab", + method = "\typingparameter\c!option", + escape = \!!bs\typingparameter\c!escape\!!es, + nature = "display", + }}% + \dostoptagged + \endofverbatimlines + \stoppacked + \typingparameter\c!after} + +% process buffers .. settings + +\unexpanded\def\processbuffer + {\dodoubleempty\doprocessbuffer} + +\def\doprocessbuffer[#1][#2]% + {\bgroup + \ifsecondargument + \setuptyping[\v!buffer][#2]% + \processcommalist[#1]{\dodoprocessbuffer\v!buffer}% [name] [settings] + \else\iffirstargument + \doifassignmentelse{#1} + {\setuptyping[\v!buffer][#1]% + \dodoprocessbuffer\v!buffer\empty}% [settings] + {\processcommalist[#1]{\dodoprocessbuffer\v!buffer}}% [name] + \else + \dodoprocessbuffer\v!buffer\empty% [] + \fi\fi + \egroup} + +% get : before/after of buffer +% typing : before/after of typing +% process : no before/after (special case anyway) + +\def\dodoprocessbuffer#1#2% + {\edef\currenttyping{#1}% + \ctxcommand{processbuffer { + name = "#2", + strip = "\typingparameter\c!strip", + tab = "\typingparameter\c!tab", + method = "\typingparameter\c!option", + nature = "direct", + }}} + +% line numbering, keep broken lines together + +\newcount\nofverbatimlines + +\def\doverbatimbeginofline + {\ifconditional\verbatimnumberinglines + \global\advance\nofverbatimlines\plusone + \attribute\verbatimlineattribute\nofverbatimlines + \fi + \noindent + \doverbatimsetlinemargin \the\everyline\strut - }%\beginverbatimline} + \dostarttagged\t!verbatimline\empty} \def\doverbatimendofline - {%\endverbatimline - \global\lineparfalse - \obeyedline\par} + {\dostoptagged + \obeyedline % still needed? + \par + \ifconditional\verbatimnumberinglines + \attribute\verbatimlineattribute\attributeunsetvalue + \fi} \def\doverbatimemptyline - {\strut - \par - \global\linepartrue} + {\dostoptagged + \ifconditional\verbatimnumberinglines + \par\strut\par % this will be an option where we use a signal instead of a strut + \else + \blank[\typingparameter\c!blank]% + \fi + \dostarttagged\t!verbatimlines\empty} + +% hooks: + +\def\doinlineverbatimstart {} +\def\doinlineverbatimstop {} +\def\doinlineverbatimbeginline {} +\def\doinlineverbatimnewline {\obeyedspace} +\def\doinlineverbatimemptyline {\obeyedspace} + +\def\dodisplayverbatimstart {\doverbatimbeginofline} +\def\dodisplayverbatimstop {\doverbatimendofline} +\def\dodisplayverbatimbeginline {\doverbatimbeginofline} +\def\dodisplayverbatimnewline {\doverbatimendofline\par} +\def\dodisplayverbatimemptyline {\doverbatimemptyline} + +\def\doverbatimspace {\obeyedspace} + +\loadmarkfile{buff-imp-default} % preloaded as otherwise spurious spaces inline due to loading +\loadmarkfile{buff-imp-nested} % preloaded as otherwise spurious spaces inline due to loading +\loadmarkfile{buff-imp-escaped} % for completeness \protect \endinput |