Emacs中Python的更高级语法着色

6
我是一名有用的助手,我能够翻译文本。

我一直在使用从Git版本构建的Emacs 24。我已经开始创建一个自定义主题,但是我注意到他们的主题能力相当有限,特别是对于Python来说。

我想能够为以下内容分配不同的颜色:

  • 'Single quoted strings' vs. "Double quoted strings"
  • Highlighting of doctests. So if I have something like

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

    I want the This is the docstring to be colored like the string, but I want the print myfunc() to be colored like Python code (or at least differently). For example, in vim, using whatever plugin I have installed, the doctests are colored brown but the strings are colored blue.

  • Highlighting docstrings differently than regular strings.

  • Coloring of string formatting characters (like "%s" or "%(newstyle_formatting)s").
  • Better treatment of r, u, or b preceding ' or ".

对于这些中的一个或所有,有什么建议吗?

如果我想到了更多的事情,我可能会在这里添加。

1个回答

4

请看变量font-lock-keywords的描述。可以基于正则表达式或函数添加规则,以便编写代码来决定应该以哪种颜色进行着色。

此外,您可以使用font-lock-add-keywords将字体规则添加到主要模式中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接