From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: kobarity Newsgroups: gmane.emacs.bugs Subject: bug#74738: 31.0.50; Freezes in Python-mode on some Python file when searching or scrolling Date: Wed, 11 Dec 2024 23:24:34 +0900 Message-ID: References: <868qsqf54x.fsf@gnu.org> Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Wed_Dec_11_23:24:34_2024-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29017"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/31.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Cc: 74738@debbugs.gnu.org, Stefan Monnier To: rehan malak , Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 11 15:26:18 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tLNfN-0007JL-Hy for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 11 Dec 2024 15:26:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLNfE-0001Xl-Er; Wed, 11 Dec 2024 09:26:08 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLNf9-0001XR-RX for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 09:26:04 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tLNf9-0000Pm-Cr for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 09:26:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:From:Date:To:Subject; bh=gKdRSiRN01C4K9uOdzmMOwqFJxgFSo/Qj0fqo82ofsM=; b=tw89bjvQWDEAU2v4+ORoFvVF8Zxn6IJAWKgr0FOy5kn0OuyzJGlXVY4OcRVVhgrFl0cr+ompU3G1QmQ8PdDBCnXPqMjxYzLL50gs76IFUt6ctexSb9JHyvz2CzYQGG5go3oRJ9plUUNquutugtD6H90hoD8Z5OmCZLiXCLzLtBuW4ccMHd9iW5ZlpE2qouufdUy3hj0EqWu8YfISSlwqjvcYCi93OYi4ulgHdTpPPKoHgNmn0H7sCjsWwHL7mqa97ansB9S/VuUg7Az1GApaOPT7tUUor8i688mc3tQ8h+K4UgkVoVRbPXGJI+zToT8kXMxL834+dfNF95wFtdG/Xg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tLNf8-00030i-70 for bug-gnu-emacs@gnu.org; Wed, 11 Dec 2024 09:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 11 Dec 2024 14:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74738 X-GNU-PR-Package: emacs Original-Received: via spool by 74738-submit@debbugs.gnu.org id=B74738.173392714611547 (code B ref 74738); Wed, 11 Dec 2024 14:26:02 +0000 Original-Received: (at 74738) by debbugs.gnu.org; 11 Dec 2024 14:25:46 +0000 Original-Received: from localhost ([127.0.0.1]:33656 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLNeq-000308-RW for submit@debbugs.gnu.org; Wed, 11 Dec 2024 09:25:45 -0500 Original-Received: from mail-pf1-f176.google.com ([209.85.210.176]:44523) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tLNel-0002zu-VJ for 74738@debbugs.gnu.org; Wed, 11 Dec 2024 09:25:42 -0500 Original-Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-725f4025e25so2719075b3a.1 for <74738@debbugs.gnu.org>; Wed, 11 Dec 2024 06:25:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733927078; x=1734531878; darn=debbugs.gnu.org; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:from:to:cc:subject:date:message-id:reply-to; bh=gKdRSiRN01C4K9uOdzmMOwqFJxgFSo/Qj0fqo82ofsM=; b=BgW+OwcFolADCm3qyJrylTBuzFUz0Hj37ptKo1zMg2JhDEDNqbTK2EOGOfz9kVu3Ee yjntGDbuXP5SMPV6AURURzejYnA3XFSa87RfSmwon9N81w+AzeabCAwMpWRSzko0z+Z0 81AG+GW/WJcz6vu7w3ZQKDjrjV7nTPg1ngJrWGPaGB/91U88znyYruojJHk1bUMWyJNe R55HyamuQLwePm7PmOXyqIykvXG57OmcSRvdPpWiONiBQL0E454vz+lAm/qUoqpfqjUr Ah3MHotJ8aanRFU40sCorbGnfE/RjoayYd7alP7PCFTaYWecll78LARJyolw4wyrM/Qt b9eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733927078; x=1734531878; h=mime-version:user-agent:references:in-reply-to:subject:cc:to:from :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gKdRSiRN01C4K9uOdzmMOwqFJxgFSo/Qj0fqo82ofsM=; b=b6b/hSdR2zoGgW64V5M/Sfps7UUPu+MgrPNWhiax/axjicKTAfV7XG2pYyiWPkgi5+ FQGSbRVPNsUJBNQiRPLojqYdeSckGDB+f5NiENyLkzwrGxgekdHbhFKHBxND5rn/Ksko EHvAO1rqrDBM/9Pyz8BGtqUZYReoifzumPMlKYMpwXmo88Z2DOX7PLu3JI1GbbIsEV/U sEB+XciYCPgtk62Be0blEfmfgz6DU0jwPmYWHoEQZyNJ2EHZPZcTYuyScRm1yGquXwvk Pd8NfYkx7u79W/ba3pfPKxnWoktcWnObAZ+9IhKz+Yk4aE8daWKbECfvaGJahGxd4ZyL eQLQ== X-Forwarded-Encrypted: i=1; AJvYcCUnfRpYnbFBzmPlh/9CaryGAuojHWp9UAtNsGz3MEh1XW0grovn1qzGukWN7QYWb/KnTDOw9g==@debbugs.gnu.org X-Gm-Message-State: AOJu0Yyj2N7LqbZyt9LOI+yAMWnHGkjedPDUyru/AJbTColXjFnP80PY yLvflkQ+WApedMyvoqdJ016rq0QN9msG3e/PQkgJIoQ4b2GtOPEg X-Gm-Gg: ASbGncvh3+hS4GYqK2E3moR+qqBSPv347MKP5mGBj4RsGeRCdWzDARAbdnAeRup+Oq+ NMON4SByyes26aIOPNKeHcQs1eVpOnHlRkCU3m+EbafBkTd8xUsaLCeFq0BJPEyxZLzF2mvfLjc cxUk39TylwT8dKo/cxJ02pCvHeLluqlLVCeFlUSnmouQMXfYOlX9JJqHTa95JiQlEHM/EkogiZb UBN/2vCZrwMe04q152oPEg+om6Nns4UWtnxy64wxWLr4ifahECk6pyiv7EL/3IynE4s6Xs8lx4f Er1wgUDL X-Google-Smtp-Source: AGHT+IF/NehyN1K0+w6k5UZc7P/vhrY/HaJ3i+oaaGBM6e9rrmpTD0HBOhCVnLdaOG3z54l0ReXbRQ== X-Received: by 2002:a05:6a20:4307:b0:1e0:bb0d:b1f4 with SMTP id adf61e73a8af0-1e1c12b54e4mr5099159637.11.1733927077907; Wed, 11 Dec 2024 06:24:37 -0800 (PST) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7263803a805sm4741743b3a.14.2024.12.11.06.24.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Dec 2024 06:24:37 -0800 (PST) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:296828 Archived-At: --Multipart_Wed_Dec_11_23:24:34_2024-1 Content-Type: text/plain; charset=US-ASCII rehan malak wrote: > Deleting all the "#" in the f-string of the gef.py file removes the problem on my side. > sed -i -e 's/#0{align/0{align/g' gef.py > sed -i -e 's/#0{width/0{width/g' gef.py > sed -i -e 's/#07x}/07x}/g' gef.py > sed -i -e 's/#06x}/06x}/g' gef.py > sed -i -e 's/#04x}/04x}/g' gef.py > sed -i -e 's/#4x}/4x}/g' gef.py > sed -i -e 's/#8x}/8x}/g' gef.py > sed -i -e 's/#10x}/10x}/g' gef.py > sed -i -e 's/#x}/x}/g' gef.py > > Your smaller example Eli also contains a f-string with the "#". > > This python f-string format specifier is described here: > https://docs.python.org/3/library/string.html#format-specification-mini-language > > Is this format specifier supported from the beginning ? > > For example : > > value = 0xab > print(f"{value:x} is a value") > > => color syntax : is a value has the color defined by font-lock-string-face > > while > > value = 0xab > print(f"{value:#x} is a value") > > => color are messed up... is has color defined by font-lock-keyword-face and a value has color defined by default face 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. 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. --Multipart_Wed_Dec_11_23:24:34_2024-1 Content-Type: text/plain; type=patch; name="0001-Fix-font-lock-of-Python-f-strings.patch"; charset=US-ASCII Content-Disposition: attachment; filename="0001-Fix-font-lock-of-Python-f-strings.patch" Content-Transfer-Encoding: 7bit >From 697f942d70e40bcd9bd32596313a9a371fffe35c Mon Sep 17 00:00:00 2001 From: kobarity Date: Wed, 11 Dec 2024 23:21:04 +0900 Subject: [PATCH] Fix font-lock of Python f-strings * lisp/progmodes/python.el (python--font-lock-f-strings): Bind 'parse-sexp-ignore-comments' to nil so that we can look for closing braces even if a hash is used in the format specifier. * test/lisp/progmodes/python-tests.el (python-font-lock-f-string-1): New test. (Bug#74738) --- lisp/progmodes/python.el | 4 +++- test/lisp/progmodes/python-tests.el | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index cfa3cc59568..827f437013f 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -631,7 +631,9 @@ python--font-lock-f-strings (forward-char 1) ;Just skip over {{ (let ((beg (match-beginning 0)) (end (condition-case nil - (progn (up-list 1) (min send (point))) + (let ((parse-sexp-ignore-comments)) + (up-list 1) + (min send (point))) (scan-error send)))) (goto-char end) (put-text-property beg end 'face nil)))) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 4cc4040d0ff..ac17c5b1263 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -709,6 +709,14 @@ python-font-lock-string-literal-concatenation (17 . font-lock-operator-face) (18) (19 . font-lock-string-face)))) +(ert-deftest python-font-lock-f-string-1 () + "Test for bug#74738." + (python-tests-assert-faces + "print(f\"{value:#x} is a value\")" + '((1 . font-lock-builtin-face) (6) + (8 . font-lock-string-face) (9) + (19 . font-lock-string-face) (31)))) + ;;; Indentation -- 2.43.0 --Multipart_Wed_Dec_11_23:24:34_2024-1--