How to get correct syntax highlighting for Python 3 formatted strings
-
For me, Notepad++ 7.9.1 is rendering f-strings as unstyled text rather than in the style of regular strings.
Could someone provide guidance on how to address this issue?
Thanks.
/jimv -
Have you tried searching this forum for
f-strings? -
Thanks for your quick response.
I did search this forum prior to posting - implicit in my subject title being verbatim that of a previous (now locked) posting.
My search revealed posts on this subject by you (among others) that seemed to indicate f-string styling should be supported by Notepad 3.9.1 without modification to XML configuration files. Am I mistaken?Prior to posting, I also verified C:\Program Files (x86)\Notepad++\stylers.model.xml contains F STRING specifications under the <LexerType name=“python” desc=“Python” ext=“”> tag.
I’m misunderstanding something, but I do not know what.
-
@J-Vickroy said in How to get correct syntax highlighting for Python 3 formatted strings:
without modification to XML configuration files. Am I mistaken?
You’re using the default styler, not a theme, correct?
-
@J-Vickroy said in How to get correct syntax highlighting for Python 3 formatted strings:
Prior to posting, I also verified C:\Program Files (x86)\Notepad++\stylers.model.xml contains F STRING specifications under the <LexerType name=“python” desc=“Python” ext=“”> tag.
Right. but does your
%AppData%\Notepad++\stylers.xml(or, appropriate theme) also contain the F STRING. Becausestylers.model.xmlis only read if there isn’t astylers.xmlin an appropriate config directory (either the install directory or the appdata location I mentioned or in your cloud folder) – and that, only to effectivelycopy stylers.model.xml right\path\to\stylers.xmlbefore loading that new stylers.xml. If you have an outdatedstylers.xml(or if you have a different theme selected, and the theme config XML hasn’t been updated), then the config file Notepad++ actually reads that stylers.xml (or theme xml), and doesn’t see the F STRING setting.I did search this forum prior to posting - implicit in my subject title being verbatim that of a previous (now locked) posting.
Hmm, I haven’t found that verbatim-title post yet. My search-fu must be weak.
I did find Python Syntax Highlighting, whose last post gives the strong indication that having an outdated theme can be the culprit.
Or then there’s the Python 3 f-strings not colourizing correctly discussion, where the user supplied the screenshot showing that the Style Configurator was out of date – where I even provide a procedure for how to copy the relevant portions of stylers.model.xml into stylers.xml, if you don’t want to overwrite any other customizations you’ve made to stylers.xml.
-
@Michael-Vincent
Thanks for your reply. I was using the Zenburn theme, but switching to Default (stylers.xml) did not alter the behavior. -
@J-Vickroy said in How to get correct syntax highlighting for Python 3 formatted strings:
switching to Default (stylers.xml) did not alter the behavior.
… which confirms that your
stylers.xmlhas not been updated to matchstylers.model.xml. (and I just checked: the most recent zenburn.xml has not been updated to have f-string syntax…)So follow the instructions I linked which explain how to get those appropriate lines from
stylers.model.xmlintostylers.xmlorzenburn.xml, or whatever theme you want to put them in (same instructions, different filename). -
@PeterJones
Thanks Peter.I just verified my %AppData%\Notepad++\stylers.xml file did not contain any F * entries.
Adding the F * entries to stylers.xml and switching to the Default theme fixed the issue. So it seems, I did have to modify an XML (stylers.xml) file.All that remains is for me to determine how to make it work for other (e.g., Zenburn) themes.
-
@PeterJones
Thanks again Peter for your followup post with the link on how to repair for non-default themes! This is great and I learned something in the process!
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login