GNU bug report logs - #30750
25.3; New Python3.6 f-string syntax highlighting support (feature request)

Previous Next

Package: emacs;

Reported by: Campbell Barton <ideasman42 <at> gmail.com>

Date: Thu, 8 Mar 2018 12:10:02 UTC

Severity: wishlist

Tags: confirmed

Found in version 25.3

Done: Stefan Monnier <monnier <at> iro.umontreal.ca>

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 30750 in the body.
You can then email your comments to 30750 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#30750; Package emacs. (Thu, 08 Mar 2018 12:10:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Campbell Barton <ideasman42 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 08 Mar 2018 12:10:02 GMT) Full text and rfc822 format available.

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

From: Campbell Barton <ideasman42 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.3;
 New Python3.6 f-string syntax highlighting support (feature request)
Date: Thu, 8 Mar 2018 23:09:36 +1100
In python 3.6, code can be evaluated in a string, called an f-string,
see: https://www.python.org/dev/peps/pep-0498/

It would be nice if python-mode would not syntax highlight the code in
the f-string as a string, and instead use regular syntax highlighting.

eg:

    print(f'Test {} me!'.format(2 + 2))

can be written as:

    print(f'Test {2 + 2} me!')

I noticed php-mode (which had something like this for many years)
does for for PHP's strings, eg: "Test {$2 + 2} me!"

----

It was recommended I send in a feature request:
see: https://emacs.stackexchange.com/questions/39283

Thanks




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30750; Package emacs. (Thu, 06 Jun 2019 19:57:02 GMT) Full text and rfc822 format available.

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

From: Valentin Ignatev <valentignatev <at> gmail.com>
To: 30750 <at> debbugs.gnu.org
Subject: MagicPython
Date: Thu, 6 Jun 2019 22:57:32 +0300
[Message part 1 (text/plain, inline)]
I wonder if MagicPython project could be useful to implement this.
Currently, it has a pretty comprehensive test suit:
https://github.com/MagicStack/MagicPython/tree/master/test/fstrings

And it has f-strings grammar defined in a yaml file:
https://github.com/MagicStack/MagicPython/blob/master/grammars/src/pyfstring.inc.syntax.yaml

At the very least, it could serve as a widely adopted reference (Atom,
Sublime, and VS Code use it).

I also wrote a very naive and wrong hack for personal use, based on
php-mode:

```
(defconst python-f-string-regexp
  "{[[:word:]]+\\.?[[:word:]]+?}")

(defun python-f-string-font-lock-find (limit)
  (while (re-search-forward python-f-string-regexp limit t)
      (when (python-syntax-comment-or-string-p)
        (put-text-property (match-beginning 0) (match-end 0)
                           'face 'font-lock-variable-name-face)))
  nil)

(with-eval-after-load 'python
  (font-lock-add-keywords
   'python-mode
   `((python-f-string-font-lock-find))
   'append))
```

(I'm really sorry, I don't know how to format monospaced text in debbugs)
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30750; Package emacs. (Thu, 06 Jun 2019 20:51:02 GMT) Full text and rfc822 format available.

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

From: npostavs <at> gmail.com
To: Valentin Ignatev <valentignatev <at> gmail.com>
Cc: 30750 <at> debbugs.gnu.org
Subject: Re: bug#30750: 25.3;
 New Python3.6 f-string syntax highlighting support (feature request)
Date: Thu, 06 Jun 2019 16:49:59 -0400
Valentin Ignatev <valentignatev <at> gmail.com> writes:

> I wonder if MagicPython project could be useful to implement this.

Not directly, unless we port Emacs to JavaScript.

> At the very least, it could serve as a widely adopted reference (Atom,
> Sublime, and VS Code use it).

That's true.

> (I'm really sorry, I don't know how to format monospaced text in debbugs)

No worries, check https://debbugs.gnu.org/30750#8, your whole post is
already monospaced :)

(but posting code as attachment often works better, because gmail tends
to add line wrapping to the email body)





Added tag(s) confirmed. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Sat, 28 Sep 2019 21:49:01 GMT) Full text and rfc822 format available.

Reply sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
You have taken responsibility. (Fri, 16 Oct 2020 18:10:01 GMT) Full text and rfc822 format available.

Notification sent to Campbell Barton <ideasman42 <at> gmail.com>:
bug acknowledged by developer. (Fri, 16 Oct 2020 18:10:01 GMT) Full text and rfc822 format available.

Message #18 received at 30750-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Campbell Barton <ideasman42 <at> gmail.com>
Cc: Valentin Ignatev <valentignatev <at> gmail.com>,
 Stefan Kangas <stefan <at> marxist.se>, 30750-done <at> debbugs.gnu.org,
 npostavs <at> gmail.com
Subject: Re: bug#30750: 25.3; New Python3.6 f-string syntax highlighting
 support (feature request)
Date: Fri, 16 Oct 2020 14:09:18 -0400
> It would be nice if python-mode would not syntax highlight the code in
> the f-string as a string, and instead use regular syntax highlighting.

I just pushed a change to the `master` branch of Emacs which should
do that.


        Stefan





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 14 Nov 2020 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 157 days ago.

Previous Next


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