unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#30750: 25.3; New Python3.6 f-string syntax highlighting support (feature request)
@ 2018-03-08 12:09 Campbell Barton
  2019-06-06 19:57 ` bug#30750: MagicPython Valentin Ignatev
  2020-10-16 18:09 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Campbell Barton @ 2018-03-08 12:09 UTC (permalink / raw)
  To: 30750

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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#30750: MagicPython
  2018-03-08 12:09 bug#30750: 25.3; New Python3.6 f-string syntax highlighting support (feature request) Campbell Barton
@ 2019-06-06 19:57 ` Valentin Ignatev
  2019-06-06 20:49   ` bug#30750: 25.3; New Python3.6 f-string syntax highlighting support (feature request) npostavs
  2020-10-16 18:09 ` Stefan Monnier
  1 sibling, 1 reply; 4+ messages in thread
From: Valentin Ignatev @ 2019-06-06 19:57 UTC (permalink / raw)
  To: 30750

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

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)

[-- Attachment #2: Type: text/html, Size: 1567 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#30750: 25.3; New Python3.6 f-string syntax highlighting support (feature request)
  2019-06-06 19:57 ` bug#30750: MagicPython Valentin Ignatev
@ 2019-06-06 20:49   ` npostavs
  0 siblings, 0 replies; 4+ messages in thread
From: npostavs @ 2019-06-06 20:49 UTC (permalink / raw)
  To: Valentin Ignatev; +Cc: 30750

Valentin Ignatev <valentignatev@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)






^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#30750: 25.3; New Python3.6 f-string syntax highlighting support (feature request)
  2018-03-08 12:09 bug#30750: 25.3; New Python3.6 f-string syntax highlighting support (feature request) Campbell Barton
  2019-06-06 19:57 ` bug#30750: MagicPython Valentin Ignatev
@ 2020-10-16 18:09 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2020-10-16 18:09 UTC (permalink / raw)
  To: Campbell Barton; +Cc: Valentin Ignatev, 30750-done, Stefan Kangas, npostavs

> 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






^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-16 18:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-08 12:09 bug#30750: 25.3; New Python3.6 f-string syntax highlighting support (feature request) Campbell Barton
2019-06-06 19:57 ` bug#30750: MagicPython Valentin Ignatev
2019-06-06 20:49   ` bug#30750: 25.3; New Python3.6 f-string syntax highlighting support (feature request) npostavs
2020-10-16 18:09 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).