What are good *abstractions* for writing custom functions to autoindent code?
===

This month I've spent some time fighting with Emacs Lisp to try to get automatic indentation that better meets my needs.  It's striking just how low-level most of the indentation code is.  I've seen just a very small number of abstractions such as

  - Search for the first instance of a regular expression that is not in a string or a comment

I suspect there are many more useful abstractions out there which would help write indentation code that is easier to understand and easier to modify.  (Even the abstraction I cite could be improved to "apply this function to these arguments repeatedly until either the function returns nil or point is not in a string or a comment".)

I'm working with emacs but I've tagged this question with vim as well because I'll take good ideas from anywhere.

If you wanted to program clean, well-designed, modular, custom indentation functions, **what abstractions would you use?**   (I would also be happy to see pointers to code that you think uses good abstractions or just is well designed.)