From: kobarity <kobarity@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>,
rehan malak <rehan.malak@gmail.com>
Cc: Eli Zaretskii <eliz@gnu.org>, 74738@debbugs.gnu.org
Subject: bug#74738: 31.0.50; Freezes in Python-mode on some Python file when searching or scrolling
Date: Sun, 15 Dec 2024 23:26:05 +0900 [thread overview]
Message-ID: <eke7ikrl3tvm.wl-kobarity@gmail.com> (raw)
In-Reply-To: <jwvzfkznp5e.fsf-monnier+emacs@gnu.org> <CABGgh3Bf8EdR-E0dzMd1XA1-+Whvq84yGmo=YyRd0LhTiqnwuw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1979 bytes --]
rehan malak wrote:
> thanks kobarity, with your patch, I confirm that :
> - I can open gef.py and scroll
> - I get the correct font-lock-string-face in the f-string after a "#" in the format
Thank you for your confirmation.
Stefan Monnier wrote:
> > The mechanism of the hang is still unclear, but I found the cause of
> > the font-lock malfunction: when using `up-list' to find the
> > corresponding closing brace for an opening brace in an f-string, if
> > the format specifier contains "#", the rest of the string is
> > considered a comment and the search fails. Therefore, it can be
> > worked around by temporarily binding `parse-sexp-ignore-comments' to
> > nil, as in the attached patch.
>
> Maybe a cleaner solution would be to locally use a different
> syntax-table (where # doesn't start a comment), but I'm not sure it's
> worth the trouble. So I installed your patch into `master`, thank you.
Thank you. I agree with you about the syntax-table.
> Maybe we should also temporarily setup a narrowing so `up-list` can't
> look past `send`.
>
> BTW, beside removing the `font-lock-string-face` from the `face`
> property, `python--font-lock-f-strings` should probably also add
> a special face for the ":<FMT>" thingies found (optionally) at the end.
>
> > Hangs on gef.py can also be avoided with this patch, but it assumes
> > that the braces are properly closed. If you remove the closing braces
> > of expressions containing "#", it will eventually hang.
>
> Hmm...
Narrowing might improve it, but what about binding
`forward-sexp-function' to nil as well, as in the attached patch? It
seems to resolve the hang caused by the unbalanced braces in
f-strings.
1. wget https://raw.githubusercontent.com/hugsy/gef/refs/heads/main/gef.py
2. sed -i -e 's/\(:#\d*x\)}/\1/g' gef.py
3. emacs -Q gef.py
4. Scroll down the file.
I don't think `python-nav-forward-sexp' is necessary here, since the
inside of the braces should be an expression, not statements.
[-- Attachment #2: 0001-Fix-hangs-caused-by-unbalanced-braces-in-Python-f-st.patch --]
[-- Type: text/plain, Size: 1148 bytes --]
From bb2c1a3e03416532fb97d6fa7ef276c5feebb356 Mon Sep 17 00:00:00 2001
From: kobarity <kobarity@gmail.com>
Date: Sun, 15 Dec 2024 23:02:51 +0900
Subject: [PATCH] Fix hangs caused by unbalanced braces in Python f-strings
* lisp/progmodes/python.el (python--font-lock-f-strings):
Temporarily bind forward-sexp-function to nil when calling
'up-list'. (Bug#74738)
---
lisp/progmodes/python.el | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 5729b12573f..493eab5e611 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -623,7 +623,8 @@ python--font-lock-f-strings
(forward-char 1) ;Just skip over {{
(let ((beg (match-beginning 0))
(end (condition-case nil
- (let ((parse-sexp-ignore-comments))
+ (let ((forward-sexp-function)
+ (parse-sexp-ignore-comments))
(up-list 1)
(min send (point)))
(scan-error send))))
--
2.43.0
next prev parent reply other threads:[~2024-12-15 14:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-08 13:05 bug#74738: 31.0.50; Freezes in Python-mode on some Python file when searching or scrolling rehan malak
2024-12-08 17:37 ` Eli Zaretskii
2024-12-09 14:58 ` rehan malak
2024-12-11 14:24 ` kobarity
2024-12-12 3:49 ` rehan malak
2024-12-15 14:26 ` kobarity [this message]
2024-12-15 15:03 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-21 9:50 ` Eli Zaretskii
2024-12-21 14:21 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-13 23:35 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-09 15:04 ` kobarity
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eke7ikrl3tvm.wl-kobarity@gmail.com \
--to=kobarity@gmail.com \
--cc=74738@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=rehan.malak@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.