Index: base/buff-ini.lua =================================================================== --- base.orig/buff-ini.lua 2009-06-15 10:23:58.000000000 +0200 +++ base/buff-ini.lua 2009-06-15 10:44:03.000000000 +0200 @@ -120,7 +120,15 @@ return first, last, last - first + 1 end -function buffers.type(name) +-- Types a single line of text (used by \type) +function buffers.typesingle(text) + hooks.begin_of_buffer('single') + hooks.flush_line(text) + hooks.end_of_buffer('single') +end + +-- Types text from the named buffer (used by \typebuffer and \starttyping) +function buffers.typebuffer(name) local lines = data[name] local action = buffers.typeline if lines then @@ -129,9 +137,11 @@ end local line, n = 0, 0 local first, last, m = buffers.strip(lines) + hooks.begin_of_buffer('buffer', name) for i=first,last do n, line = action(lines[i], n, m, line) end + hooks.end_of_buffer('buffer', name) end end @@ -145,15 +155,18 @@ return str or "" end +-- Types text from the named file (used by \typefile) function buffers.typefile(name) -- still somewhat messy, since name can be be suffixless local str = buffers.loaddata(name) if str and str~= "" then local lines = str:splitlines() local line, n, action = 0, 0, buffers.typeline local first, last, m = buffers.strip(lines) + hooks.begin_of_buffer('file', name) for i=first,last do n, line = action(lines[i], n, m, line) end + hooks.end_of_buffer('file', name) end end @@ -301,23 +314,43 @@ -- calling routines, don't change +-- Called at the start of every piece of text that is prettyprinted. Type can +-- be: 'single', when only a single line is prettyprinted (e.g. \type), +-- 'buffer', when a buffer is prettyprinted (e.g. \typebuffer) or 'file', when +-- a file is prettyprinted (e.g. \typefile). +-- name is the name of the buffer or file, and empty for 'single'. The special +-- buffer name '_typing_' is used for \starttyping. +function hooks.begin_of_buffer(type, name) + (visualizers[buffers.currentvisualizer].begin_of_buffer or default.begin_of_buffer)(type, name) +end + +-- Called at the end of every piece of text that is prettyprinted. +function hooks.end_of_buffer(type, name) + (visualizers[buffers.currentvisualizer].end_of_buffer or default.end_of_buffer)(type, name) +end + +-- Called for every non-empty line function hooks.flush_line(str,nesting) str = gsub(str," *[\n\r]+ *"," ") ; -- semi colon needed (visualizers[buffers.currentvisualizer].flush_line or default.flush_line)(str,nesting) end +-- Called at the start of every non-empty line (before flush_line) function hooks.begin_of_line(n) (visualizers[buffers.currentvisualizer].begin_of_line or default.begin_of_line)(n) end +-- Called at the end of every non-empty line (after flush_line) function hooks.end_of_line() (visualizers[buffers.currentvisualizer].end_of_line or default.end_of_line)() end +-- Called for every empty line function hooks.empty_line() (visualizers[buffers.currentvisualizer].empty_line or default.empty_line)() end +-- Called for every non-empty line. The result is passed to flush_line. function hooks.line(str) if visualizers.enabletab then str = string.tabtospace(str,visualizers.tablength) @@ -329,6 +362,12 @@ -- defaults +function default.begin_of_buffer(type, name) +end + +function default.end_of_buffer(type, name) +end + function default.begin_of_line(n) texsprint(ctxcatcodes, commands.begin_of_line_command,"{",n,"}") end Index: base/buff-ini.mkiv =================================================================== --- base.orig/buff-ini.mkiv 2009-06-15 10:26:17.000000000 +0200 +++ base/buff-ini.mkiv 2009-06-15 10:30:03.000000000 +0200 @@ -161,13 +161,13 @@ \def\doprocessbufferverbatim {\doinitializeverbatim - \ctxlua{buffers.type("\currentbuffer")}} + \ctxlua{buffers.typebuffer("\currentbuffer")}} \def\doprocessbufferlinesverbatim#1#2#3% {#2% % todo, set up numbers \doinitializeverbatim - \ctxlua{buffers.type("\currentbuffer")} + \ctxlua{buffers.typebuffer("\currentbuffer")} #3} \def\doifelsebuffer#1% Index: base/buff-ver.mkiv =================================================================== --- base.orig/buff-ver.mkiv 2009-06-15 10:24:38.000000000 +0200 +++ base/buff-ver.mkiv 2009-06-15 10:31:34.000000000 +0200 @@ -292,7 +292,7 @@ \def\dodotypeAA#1% {\doinitializeverbatim \def\obs{\obeyedspace}% - \ctxlua{buffers.hooks.flush_line(\!!bs\detokenize{#1}\!!es)}% + \ctxlua{buffers.typesingle(\!!bs\detokenize{#1}\!!es)}% \egroup} \def\dodotypeB#1% @@ -316,7 +316,7 @@ \def\dodotypeCC#1% {\doinitializeverbatim \ifx\obeycharacters\setupprettytype % temp hack, we need a proper signal - \ctxlua{buffers.hooks.flush_line([\!!bs\detokenize{#1}\!!es,true)}% + \ctxlua{buffers.typesingle([\!!bs\detokenize{#1}\!!es,true)}% \else \def\obs{\obeyedspace}% \ctxlua{buffers.visualizers.flush_nested(\!!bs\detokenize{#1}\!!es,true)}% @@ -333,7 +333,7 @@ \def\dodotypeDD#1% {\doinitializeverbatim - \ctxlua{buffers.hooks.flush_line(\!!bs\detokenize{#1}\!!es,true)}% + \ctxlua{buffers.typesingle(\!!bs\detokenize{#1}\!!es,true)}% \egroup \gobbleoneargument} % grab last > @@ -573,7 +573,7 @@ {} {\doinitializeverbatim \beginofverbatimlines - \ctxlua{buffers.type("_typing_")}% + \ctxlua{buffers.typebuffer("_typing_")}% \endofverbatimlines \getvalue{\strippedcsname#2}}}