From: Guillaume Brunerie <guillaume.brunerie@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: monnier@iro.umontreal.ca, 74415@debbugs.gnu.org
Subject: bug#74415: 29.4; mouse-start-end does not respect syntax-table text properties
Date: Mon, 9 Dec 2024 20:21:49 +0100 [thread overview]
Message-ID: <CAFJ3QWL5fyP_H+XaJJ=fc+DcRgAmxy-xtJ1m2by8v6W5vqo4YQ@mail.gmail.com> (raw)
In-Reply-To: <86seqzisg2.fsf@gnu.org>
Den lör 7 dec. 2024 kl 13:33 skrev Eli Zaretskii <eliz@gnu.org>:
>
> > From: Guillaume Brunerie <guillaume.brunerie@gmail.com>
> > Date: Thu, 5 Dec 2024 07:13:20 +0100
> > Cc: Stefan Monnier <monnier@iro.umontreal.ca>, 74415@debbugs.gnu.org
> >
> > Den tors 28 nov. 2024 kl 17:02 skrev Eli Zaretskii <eliz@gnu.org>:
> > > Thanks. Guillaume, does the patch below give good results?
> >
> > Thank you, I haven’t managed to apply the patch locally yet but I
> > think that would work (I’m on Emacs 29.4, but I guess I might need to
> > get the development version of Emacs? The patch seems to fail on my
> > mouse.el).
> > But one thing I want to point out is that the two `(signal 'scan-error
> > [...])` seem to be dead code now, as they test the exact opposite of
> > what the previous test now does.
>
> Sorry, I don't understand. The changes I proposed didn't touch the
> lines that signals errors. Are you saying that those errors were dead
> code before these changes as well? If not, could you please elaborate
> on the issues you see with the changes I proposed?
No, it was not dead code before, but changing the outer condition
makes it impossible for both the outer condition and the inner
condition to be true at the same time.
The current code is the following (inside a cond)
((and (= mode 1)
(= start end)
(char-after start)
(= (char-syntax (char-after start)) ?\())
(if (/= (syntax-class (syntax-after start)) 4) ; raw syntax code for ?\(
;; This happens in CC Mode when unbalanced parens in CPP
;; constructs are given punctuation syntax with
;; syntax-table text properties. (2016-02-21).
(signal 'scan-error (list "Containing expression ends prematurely"
start start))
(list start
(save-excursion
(goto-char start)
(forward-sexp 1)
(point)))))
So the 'scan-error happens when the character is a parenthesis
character according to the syntax table (that's what is tested by (=
(char-syntax (char-after start)) ?\()) but has a text property telling
Emacs to treat it as something else than a parenthesis instead.
Changing the "char-syntax" test to (= (syntax-class-to-char
(syntax-class (syntax-after start))) ?\()) makes it so that the
'scan-error happens if the character is both a parenthesis and not a
parenthesis according to text properties, which is not possible.
In other words, it is not possible for both (= (syntax-class-to-char
(syntax-class (syntax-after start))) ?\()) and (/= (syntax-class
(syntax-after start)) 4) to be simultaneously true, as they are the
exact opposite of each other, so when they are nested conditions, the
inner one becomes dead code.
That said, it only seems to happen in rare edge cases (as in
https://lists.gnu.org/archive/html/bug-gnu-emacs/2016-02/msg00988.html),
as regular unmatched parentheses do seem to still trigger a different
"Unbalanced parentheses" scan error.
Apart from that, I have now managed to test the patch, and I can
confirm that it fixes my original issue
next prev parent reply other threads:[~2024-12-09 19:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 10:12 bug#74415: 29.4; mouse-start-end does not respect syntax-table text properties Guillaume Brunerie
2024-11-24 9:59 ` Eli Zaretskii
2024-11-25 23:15 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-28 16:02 ` Eli Zaretskii
2024-11-28 20:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-05 6:13 ` Guillaume Brunerie
2024-12-07 12:33 ` Eli Zaretskii
2024-12-09 19:21 ` Guillaume Brunerie [this message]
2024-12-13 17:05 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFJ3QWL5fyP_H+XaJJ=fc+DcRgAmxy-xtJ1m2by8v6W5vqo4YQ@mail.gmail.com' \
--to=guillaume.brunerie@gmail.com \
--cc=74415@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).