bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#30750: MagicPython


From: Valentin Ignatev
Subject: bug#30750: MagicPython
Date: Thu, 6 Jun 2019 22:57:32 +0300

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)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]