No, no. Context should not have absolute positions in it. That would ruin the
whole thing. It should contain information about the nesting of language
constructs sufficient to be able to indent first line of an inner span without
any other positional knowledge.
As explained, the SMIE indentation has no such "summary of context".
The only context it could use is either a position or the complete text
before that position.
For example, if current line is directly part of IF block, most
languages don't care what precedes IF head at all, only the offset
of IF.
Yes, there are simple cases we know how to handle. The problem is the
general case, along with the work to modify the existing indentation
codes to be able to generate and use that data.
So an entry in the context data structure might look like (IF
. IF-OFFSET). If line number within the block is important then you
can pass (IF IF-OFFSET . RELATIVE-LINE). My hunch is that for most
languages you would be able to reduce indentation to a small number of
block-continuation constructs (less than 10).
Consider
x = a << b + c * d
the code after this line can be indented in various different ways:
* e
or
+ e
or
== e
or
; e
And of course, in this example, I put all relevant operators, but in
practice they'll generally be on different lines. And SMIE (which
supports that kinds of indentation, e.g. in sm-c-mode) doesn't
pre-compute that context: it's only when it sees the "+" at the
beginning of line that it moves back over higher-precedence operators to
find the matching alignment spot.
In theory, SMIE could try to create the kind of context you're thinking
of, but that would amount to a complete rewrite (and it would likely be
very difficult if not impossible to make it work with existing
smie-rules-functions, so it'd break backward compatibility).
Stefan