Refactor pre block matching function
commitb87f246e6200ec7003d11dfb8efc944e1e8450fa
authorJason Blevins <jrblevin@sdf.org>
Tue, 9 Aug 2011 04:06:25 +0000 (9 00:06 -0400)
committerJason Blevins <jrblevin@sdf.org>
Tue, 9 Aug 2011 18:00:44 +0000 (9 14:00 -0400)
treec97318d6daff48deaa29cf07aab81356549451be
parent434a6103bca19dec58d7c35662465d23d56306bd
Refactor pre block matching function

* Match entire blocks at or above the current indentation level.

* Improve starting point of search: don't start at blocks with indentation
  less than four.

* Keep block matching functions internal to `markdown-match-pre-blocks'.
  They are probably not general or robust enough to use elsewhere right now.

* Only compare pre block indentation with indentation of the final line of
  the previous block.

* Remove some unused variables and factor out others that were unnecessary.

* Remove some unnecessary tests and bounds checks.

Hopefully this is more efficient and robust than the first, experimental
version.

This is still not pretty, and will not correspond to Markdown in some edge
cases, but is infinitely better than the pre block matching in the previous
version of markdown-mode.  There are two main complicating factors.  First,
Emacs font lock functions are really designed for inline constructs, rather
than multi-line constructs like pre blocks.  We can mitigate this to some
extent by extending the region.  The second is that Emacs expects the
function to match elements in a given limited range.  To accurately match pre
blocks in all cases, such as in complex nested lists, we need quite a bit of
context from previous lines.  On the other hand, parsing that much of the
document each time this function is called would be slow.

Given the constraints, hopefully this implementation strikes a good balance
between 100% accuracy and speed.  The alternative, which for now I am saving
for future work, is to work outside of the standard Emacs Font Lock
framework.  Packages such as AUCTeX do this, and markdown-mode even does this
for keeping wiki link highlighting up to date.
markdown-mode.el