Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Python syntax highlighting

    Help wanted · · · – – – · · ·
    3
    6
    3825
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Queer Chemist
      Queer Chemist last edited by

      Hi all, thanks in advance for the help. New to NP++, I’m switching over from IDLE for Python coding because IDLE still has no support for code folding. Wondering if NP++ has a option for highlighting the keywords that would normally be purple in IDLE - things like the int() function, IndexError/KeyError/etc, the input() function, etc. Can’t seem to find a setting for this.

      1 Reply Last reply Reply Quote 0
      • Steven Haymes
        Steven Haymes last edited by Steven Haymes

        Hi Queer Chemist :

        You can set the Python syntax highlighting as follows:

        Settings -> Style Configurator… -> Language: -> Python

        It is my recommendation that before this, you:

        • Copy the default stylers.xml file in C:\Users\My_Account\AppData\Roaming\Notepad++ into C:\Users\My_Account\AppData\Roaming\Notepad++\themes and give it a new name like “My_Theme.xml”.
        • Select “My_Theme” in the Style Configurator and make your changes there as to not modify the default theme.
        • Maybe select Language: -> Global Styles first and adjust a few global style settings before adjusting a few language-specific style settings.

        Good luck!

        Steve

        1 Reply Last reply Reply Quote 1
        • Queer Chemist
          Queer Chemist last edited by

          Hi Steve,

          Thanks for your response! I’ve actually already set syntax highlighting to Python with the Style Configurator and it works great for things like comments, while/try/except/if, strings, etc. but the things mentioned in my original post that would normally be highlighted as purple in IDLE don’t seem to be an available option. Is there a way to add custom “keywords”?

          Thanks again!

          1 Reply Last reply Reply Quote 0
          • Steven Haymes
            Steven Haymes last edited by Steven Haymes

            You may want to look at C:\Program Files (x86)\Notepad++\langs.model.xml and C:\Program Files (x86)\Notepad++\autoCompletion\python.xml. The second file contains a much longer list of key words which can probably be added to the first file. Make sure that you make a backup of these file before you make any changes to them.

            Note that I have not added words from the second file to the first file so I am just assuming that this will work.

            S

            1 Reply Last reply Reply Quote 0
            • PeterJones
              PeterJones last edited by

              @Queer-Chemist said:

              Is there a way to add custom “keywords”?

              Yes. You can manually edit the XML config files, as @Steven-Haymes suggested. Or you can go to Settings -> Style Configurator… -> Language: -> Python, and then select KEYWORDS, and add whatever user-defined keywords you want.

              This won’t, however, keep them separately colored compared to normal Python keywords. If you want the new keywords colored separately, you cannot do it natively. However, using the PythonScript plugin (see this guide for installation instructions), and the EnhanceAnyBuiltinLexer PythonScript which @ekopalypse shared some months back, which will allow you to set a regular expression to add extra highlighting that the active lexer isn’t providing

              1 Reply Last reply Reply Quote 1
              • Steven Haymes
                Steven Haymes last edited by

                Pete,

                Thanks for the better answer! I have not had to use this very obvious feature of the Style Configurator 🙄

                Steve

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors