简体   繁体   中英

Highlight Function Calls Sublime Text (python)

I would like to be able to find a way to color the name of function calls in python with a different color. This behavior is found for the C language, but not for Python. that's why I think it should be possible to do it.

Edit:

I'm not looking for the Color Scheme syntax specific, I'm rather looking for the specific lines I would have to add to the Python.tmLanguage.

After trying the suggestion by jdi, I ended up with this:

在此处输入图片说明

What I would like would be only array to be colored differently, not the parenthesis, objects calling methods, etc ...

You will need to edit an existing theme, or duplicate one, modify it, and set to that... Then you can add something like this to the bottom:

<dict>
    <key>name</key>
    <string>Function call</string>
    <key>scope</key>
    <string>meta.function-call - punctuation - meta.function-call.arguments</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#FF0000</string>
    </dict>
</dict>

This takes the function-call pattern, and subtracts the subsets for the parenthesis of the call, leaving just the name.

Default themes are located in: Packages/Color Scheme - Default

高亮文本示例

This is what I have so far it is not perfect but it kinda works:

I took this piece from the C.tmLanguage file that comes bundled in every ST2 and added a few things so that this can be colored differently from some of the default functions in Python defined in the Python.tmLanguage file:

    <dict>
        <key>captures</key>
        <dict>
            <key>1</key>
            <dict>
                <key>name</key>
                <string>punctuation.whitespace.function-call.leading.python</string>
            </dict>
            <key>2</key>
            <dict>
                <key>name</key>
                <string>support.function.any-method.python</string>
            </dict>
            <key>3</key>
            <dict>
                <key>name</key>
                <string>punctuation.definition.parameters.python</string>
            </dict>
        </dict>
        <key>match</key>
        <string>(?x) (?: (?= \s )  (?:(?&lt;=else|new|return) | (?&lt;!\w)) (\s+))?
(\b
    (?!(while|for|do|if|else|switch|catch|enumerate|return|r?iterate|
        __import__|all|abs|any|apply|callable|chr|cmp|coerce|compile|delattr|dir|
        divmod|eval|execfile|filter|getattr|globals|hasattr|hash|hex|id|
        input|intern|isinstance|issubclass|iter|len|locals|map|max|min|oct|
        ord|pow|range|raw_input|reduce|reload|repr|round|setattr|sorted|
        sum|unichr|vars|zip|basestring|bool|buffer|classmethod|complex|dict|enumerate|file|
        float|frozenset|int|list|long|object|open|property|reversed|set|
        slice|staticmethod|str|super|tuple|type|unicode|xrange|
        abs|add|and|call|cmp|coerce|complex|contains|del|delattr|
        delete|delitem|delslice|div|divmod|enter|eq|exit|float|
        floordiv|ge|get|getattr|getattribute|getitem|getslice|gt|
        hash|hex|iadd|iand|idiv|ifloordiv|ilshift|imod|imul|init|
        int|invert|ior|ipow|irshift|isub|iter|itruediv|ixor|le|len|
        long|lshift|lt|mod|mul|ne|neg|new|nonzero|oct|or|pos|pow|
        radd|rand|rdiv|rdivmod|repr|rfloordiv|rlshift|rmod|rmul|ror|
        rpow|rrshift|rshift|rsub|rtruediv|rxor|set|setattr|setitem|
        setslice|str|sub|truediv|unicode|xor
    )\s*\()(?:(?!NS)[A-Za-z_][A-Za-z0-9_]*+\b | :: )++                  # actual name
)
 \s*(\()</string>
        <key>name</key>
        <string>meta.function-call.python</string>
    </dict>

And this is how the output looks like using the Monokai Bright theme, although it is very subtle you can notice how open is formatted different to array .

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM