all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: kobarity <kobarity@gmail.com>
To: 51362@debbugs.gnu.org
Subject: bug#51362: python font-lock-mode in emacs 28 seems broken
Date: Mon, 18 Apr 2022 08:32:14 +0900	[thread overview]
Message-ID: <CAMQkrSoOiCKC3EOyGcfjFnj6+v2J+H0U05BJujhjm7HOz4++jA@mail.gmail.com> (raw)
In-Reply-To: <CALmFPZ0B_E-BEzkTQw2K-fntBAnEV4Wbir8PymDnnP2HC52muA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3095 bytes --]

Hi,

I reported a new Bug #54992 for the following bug mentioned in Message #24:

- The CustomInt in Sequence[CustomInt] is highlighted — this is *not*
  fixed by subsequent edits

Remaining two following bugs mentioned in Message #24 and Bug #45679
are the same:

- The y in y = x + 1 is not highlighted — this is fixed by subsequent
  edits
- The CustomInt in -> CustomInt is highlighted — this is fixed by
  subsequent edits

Is it better to discuss in Bug #45679?

These bugs are caused by not-simple-operator matching characters
including EOLs. So rx '(+ not-simple-operator)' may span multiple
lines.

This problem can be fixed with the following patch. Behavior of
python-font-lock-assignment-matcher is same as Dario's patch, but I'm
just showing another option using cl-loop. I also modified docstring.

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index c4d8b123a8..d31861dd83 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -394,7 +394,7 @@ python-rx
             (open-paren        (or "{" "[" "("))
             (close-paren       (or "}" "]" ")"))
             (simple-operator   (any ?+ ?- ?/ ?& ?^ ?~ ?| ?* ?< ?> ?= ?%))
-            (not-simple-operator (not simple-operator))
+            (not-simple-operator (not (or simple-operator ?\n)))
             (operator          (or "==" ">=" "is" "not"
                                    "**" "//" "<<" ">>" "<=" "!="
                                    "+" "-" "/" "&" "^" "~" "|" "*" "<" ">"
@@ -603,15 +603,15 @@ python-font-lock-keywords-level-2

 (defun python-font-lock-assignment-matcher (regexp)
   "Font lock matcher for assignments based on REGEXP.
-Return nil if REGEXP matched within a `paren' context (to avoid,
-e.g., default values for arguments or passing arguments by name
-being treated as assignments) or is followed by an '=' sign (to
-avoid '==' being treated as an assignment."
+Search for next occurrence if REGEXP matched within a `paren'
+context (to avoid, e.g., default values for arguments or passing
+arguments by name being treated as assignments) or is followed by
+an '=' sign (to avoid '==' being treated as an assignment."
   (lambda (limit)
-    (let ((res (re-search-forward regexp limit t)))
-      (unless (or (python-syntax-context 'paren)
-                  (equal (char-after (point)) ?=))
-        res))))
+    (cl-loop while (re-search-forward regexp limit t)
+             unless (or (python-syntax-context 'paren)
+                        (equal (char-after) ?=))
+               return t)))

 (defvar python-font-lock-keywords-maximum-decoration
   `((python--font-lock-f-strings)


Please note that not-simple-operator is also used in
python-info-assignment-statement-p, but the patch does not affect it.
Because python-info-assignment-statement-p calls re-search-forward
with BOUND argument set to (line-end-position).

I wrote some tests as the attached patch. Both the above patch and the
patch shown in Bug #54992 are necessary for all of the tests to pass.

[-- Attachment #2: python-font-lock-tests.patch --]
[-- Type: application/x-patch, Size: 6266 bytes --]

  parent reply	other threads:[~2022-04-17 23:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-23 20:06 bug#51362: python font-lock-mode in emacs 28 seems broken Jeff Spencer
2021-10-24 12:45 ` Stefan Kangas
2021-10-24 22:37   ` Jeff Spencer
2021-10-24 22:40     ` Jeff Spencer
2021-10-31  9:34   ` Kévin Le Gouguec
2021-11-11  8:04     ` Dario Gjorgjevski
2021-11-11  8:48       ` Stefan Kangas
2021-11-11 12:37       ` Lars Ingebrigtsen
2022-04-17 23:32 ` kobarity [this message]
2022-04-18  9:50   ` Lars Ingebrigtsen
2022-04-18 12:34     ` kobarity
2022-04-18 12:36       ` Lars Ingebrigtsen
2022-05-16 13:40         ` Lars Ingebrigtsen
2022-05-16 14:21           ` 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=CAMQkrSoOiCKC3EOyGcfjFnj6+v2J+H0U05BJujhjm7HOz4++jA@mail.gmail.com \
    --to=kobarity@gmail.com \
    --cc=51362@debbugs.gnu.org \
    /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.