Subject: bug#5560: 23.1.92; parens matching in c-mode broken

From: Alan Mackenzie <[email-masked]>
Date: Mon, 22 Feb 2016 10:35:55 +0000

Hello, David.

On Sun, Feb 21, 2016 at 04:40:09PM -0500, David Reitter wrote:
> Alan,

> Your patch works as advertised for my test case.  It’s certainly
> better to error out than to do the wrong thing.

> I think you are catching the right situations, but my confidence is
> low because of the readability of the code (what is 4, 5?).

4 and 5 are the low level codes for "open paren" and "close paren"
syntax.  I don't like them much either, but `syntax-after' is the only
interface available which returns the syntax of a character in a buffer,
taking account of syntax-table text properties.  4 and 5 (or, more
precisely, (4 . ?\)), (5 . ?\()) are what we have to work with.

One way would be to create two constants with fancy names with values 4
and 5, but I don't think that helps much - anybody debugging and
suspicious of the values still has to find the page in the elisp manual
to check, but has an extra irritating indirection to cope with.

How would you feel about explanatory comments on the two lines -
something like:

+         (if (/= (car (syntax-after start)) 4) ; low-level code for ?\(

?

What we really need is a better interface.  Perhaps `char-syntax-after',
which would actually return ?\( and ?\).  In fact, I think I'll raise a
bug report for this.

> I think the question is whether that fix is appropriate for the 25.1
> release.  If you want to apply it there, I would probably test a whole
> lot of cases in modes that are derivates of c-mode.

I think the fix should go into 25.1.  I'm confident enough about the
mechanism of the bug that I'm not sure extensive testing is warranted.

> - David

-- 
Alan Mackenzie (Nuremberg, Germany).