emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Syntax tables for multiple modes [was: bug#22983: syntax-ppss return


From: Andreas Röhler
Subject: Re: Syntax tables for multiple modes [was: bug#22983: syntax-ppss returns wrong result.]
Date: Thu, 24 Mar 2016 08:30:03 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Icedove/38.5.0



On 23.03.2016 12:41, Stefan Monnier wrote:
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



Stefan, came across SMIE as it looked like an interesting abstraction. Estimate your efforts. Nonetheless think that path turned out wrong meanwhile. SMIE-based indentation will not be easier, but run into more and more complexity instead. The reasons deserve being discussed elsewhere.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]