Subject: Re: bug#22983: syntax-ppss returns wrong result.

From: Alan Mackenzie <[email-masked]>
Date: Fri, 11 Mar 2016 21:24:10 +0000

Hello, Dmitry.

On Fri, Mar 11, 2016 at 10:31:50PM +0200, Dmitry Gutov wrote:
> On 03/11/2016 05:15 PM, Alan Mackenzie wrote:

> > At this point, `ppss-1' and `parse' should match (apart from elements 2
> > and 6).  What we actually have is:

> >     ppss-1: (2 39992 nil nil nil nil 2 nil nil (39975 39992))
> >     parse:  (0 nil 15674 34 nil nil 0 nil 15675 nil)

> I think you mean that ppss-0 and ppss-1 must match independent of 
> narrowing, and also match (parse-partial-sexp 1 40000).

Er no, I meant what I wrote: the result of (syntax-ppss pos) must match
that of (parse-partial-sexp (point-min) pos).  I think ppss-0 and ppss-1
did actually match (but I can't quite remember).

> Considering narrowing can change point-min arbitrarily, specifying 
> (syntax-ppss pos) as (parse-partial-sexp (point-min) pos) is a losing 
> proposition if you want consistency.

Indeed.  But that is how syntax-ppss is specified, and (partially) how
it is implemented.

> Alas, we have some code out there that implements multiple-major-mode 
> functionality using narrowing and some hacking of syntax-ppss-last 
> syntax-ppss-cache values.

> Changing syntax-ppss to be independent of narrowing will break it, and 
> we'll need to provide some alternative first.

syntax-ppss is broken, and can't be fixed.  The only sensible fix would
be to specify that (syntax-ppss pos) is the same as (parse-partial-sexp
1 pos).  But that is then a totally different function, and there are
around 200 uses in the Emacs sources to check and fix, to say nothing of
external code.

> We could introduce a syntax-ppss-dont-widen variable, though. Similar to 
> font-lock-dont-widen.

I'm trying to figure that out.  Wouldn't that still leave you with
problems when point-min is inside a string?

-- 
Alan Mackenzie (Nuremberg, Germany).