More advanced syntax coloring in emacs for Python

I am using emacs 24 (built from git version). I started to create a custom theme, but I noticed that the theme’s capabilities are quite limited, especially for Python.

I want to be able to assign different colors to things like

  • Single quotes and Double quotes
  • Underlining doctrines. Therefore, if I have something like

    def myfunc(x): """ This is the docstring. >>> # These are the examples >>> print myfunc(x) 1 """ return 1 

    I want This is the docstring be colored as a string, but I want print myfunc() be colored as Python code (or at least differently). For example, in vim, using any plugin I installed, the doctrines are browned, but the lines are blue.

  • Highlighting docstrings is different than regular lines.

  • Coloring line formatting characters (for example, "%s" or "%(newstyle_formatting)s" ).
  • Better handling with r, u or b preceding "or".

Any suggestions for one or all of them?

I could add more things here if I think about them.

+6
source share
1 answer

Take a look at the description of the font-lock-keywords variable. You can add rules based on regexp: s, but also based on functions so that you can write code to decide what should be painted and in what color.

In addition, you can use font-lock-add-keywords to add sorting rules to the main modes.

+4
source

Source: https://habr.com/ru/post/906234/


All Articles