From: Matthijs Kooijman Date: Thu, 27 Aug 2009 11:42:57 +0000 (+0200) Subject: Let pret-lam support blocks of multiple lambda expressions. X-Git-Tag: final-thesis~280 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=ffef13cb64e18f66825b861a0ee709637125d9c3;p=matthijs%2Fmaster-project%2Freport.git Let pret-lam support blocks of multiple lambda expressions. This enables subscript detection from one lambda expression or buffer to influence the lambda detection in other buffer. --- diff --git a/pret-lam.lua b/pret-lam.lua index ce4ac47..2e70001 100644 --- a/pret-lam.lua +++ b/pret-lam.lua @@ -101,14 +101,38 @@ local function do_subscripts(word) return word end +local in_block = 0 + +-- Mark the begin of a block of lambda formatted buffers or expressions. This +-- means that, until you call end_of_block again, the subscript bases are +-- shared. For example, if you have \lam{y1} some text \lam{yn} within a +-- single block, the yn will properly get subscripted. Be sure to call +-- end_of_block again! +-- +-- Blocks can be partially nested, meaning that the block +-- won't be closed until end_of_block was called exactly as often as +-- begin_of_block. However, subscripts from the inner block can still +-- influence subscripts in the outer block. +function vis.begin_of_block() + vis.begin_of_display() + in_block = in_block + 1 +end + +-- Ends the current block +function vis.end_of_block() + in_block = in_block - 1 +end + function vis.begin_of_display() - -- Initially allow subscripts using _ or just appending a number (later, - -- we will add extra patterns here. - submatches = {"^(%a*)_([%a%d,]+)$", "^(%a+)(%d+)$"} - -- This stores all the bases we've encountered so far (to prevent - -- duplicates). For each of them there will be a pattern in submatches - -- above. - bases = {} + if in_block == 0 then + -- Initially allow subscripts using _ or just appending a number (later, + -- we will add extra patterns here. + submatches = {"^(%a*)_([%a%d,]+)$", "^(%a+)(%d+)$"} + -- This stores all the bases we've encountered so far (to prevent + -- duplicates). For each of them there will be a pattern in submatches + -- above. + bases = {} + end end -- Make things work for inline typeing (e.g., \type{}) as well.