GNU bug report logs - #45341
[PATCH] Make python-mode fontify more assignment statements

Previous Next

Package: emacs;

Reported by: Dario Gjorgjevski <dario.gjorgjevski <at> gmail.com>

Date: Sun, 20 Dec 2020 16:26:01 UTC

Severity: normal

Tags: fixed, patch

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 45341 in the body.
You can then email your comments to 45341 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#45341; Package emacs. (Sun, 20 Dec 2020 16:26:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Dario Gjorgjevski <dario.gjorgjevski <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 20 Dec 2020 16:26:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Dario Gjorgjevski <dario.gjorgjevski <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Make python-mode fontify more assignment statements
Date: Sun, 20 Dec 2020 17:25:16 +0100
[Message part 1 (text/plain, inline)]
The current implementation in python-mode fontifies only basic
assignment statements.  It makes mistakes on or entirely misses more
complex ones such as

  [a, b, c] = 1, 2, 3
  a, *b, c = range(10)
  inst.a, inst.b, inst.c = 'foo', 'bar', 'baz'
  (a, b, *c, d) = x, *y = 5, 6, 7, 8, 9

The patch attached below extends the fontification to work correctly
with all these cases.  I tested things as well as I could, but would
appreciate further testing.

[0001-Make-python-mode-fontify-more-assignment-statements.patch (text/x-diff, attachment)]
[Message part 3 (text/plain, inline)]
Best regards,
Dario

-- 
$ keyserver=hkps://hkps.pool.sks-keyservers.net
$ keyid=744A4F0B4F1C9371
$ gpg --keyserver $keyserver --search-keys $keyid

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45341; Package emacs. (Sun, 20 Dec 2020 18:06:02 GMT) Full text and rfc822 format available.

Message #8 received at 45341 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: Dario Gjorgjevski <dario.gjorgjevski <at> gmail.com>
Cc: 45341 <at> debbugs.gnu.org
Subject: Re: bug#45341: [PATCH] Make python-mode fontify more assignment
 statements
Date: Sun, 20 Dec 2020 18:04:59 +0000
Dario Gjorgjevski <dario.gjorgjevski <at> gmail.com> writes:

> +(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."
> +  (lambda (limit)
> +    (let ((res (re-search-forward regexp limit t)))
> +      (unless (or (python-syntax-context 'paren)
> +                  (equal (char-after (point)) ?=))

Nit: char-after already defaults to looking at point, but you could also
use following-char which always returns a natnum.

-- 
Basil




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45341; Package emacs. (Mon, 21 Dec 2020 04:43:02 GMT) Full text and rfc822 format available.

Message #11 received at 45341 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Dario Gjorgjevski <dario.gjorgjevski <at> gmail.com>
Cc: 45341 <at> debbugs.gnu.org
Subject: Re: bug#45341: [PATCH] Make python-mode fontify more assignment
 statements
Date: Mon, 21 Dec 2020 05:41:52 +0100
Dario Gjorgjevski <dario.gjorgjevski <at> gmail.com> writes:

> The patch attached below extends the fontification to work correctly
> with all these cases.  I tested things as well as I could, but would
> appreciate further testing.

I did some cursory testing, and it seemed to work well for me, so I've
applied your patch to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#45341; Package emacs. (Mon, 21 Dec 2020 04:44:01 GMT) Full text and rfc822 format available.

Message #14 received at 45341 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: Dario Gjorgjevski <dario.gjorgjevski <at> gmail.com>, 45341 <at> debbugs.gnu.org
Subject: Re: bug#45341: [PATCH] Make python-mode fontify more assignment
 statements
Date: Mon, 21 Dec 2020 05:43:22 +0100
"Basil L. Contovounesios" <contovob <at> tcd.ie> writes:

>> +    (let ((res (re-search-forward regexp limit t)))
>> +      (unless (or (python-syntax-context 'paren)
>> +                  (equal (char-after (point)) ?=))
>
> Nit: char-after already defaults to looking at point, but you could also
> use following-char which always returns a natnum.

The old code also used this idiom, so I didn't rewrite it before
applying.  python.el mostly uses (eq (char-after) ?x) throughout its
code, though.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 21 Dec 2020 04:44:01 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 45341 <at> debbugs.gnu.org and Dario Gjorgjevski <dario.gjorgjevski <at> gmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 21 Dec 2020 04:44:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 18 Jan 2021 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 238 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.