Custom syntax highlighting in Sublime Text 2

2019-01-30 02:24发布

I want to use Sublime Text as log viewer. That's why I need to create tmlanguage file for highlighting of word "ERROR" (and some others). Is there any spec of tmlanguage xml, or can you give me basic example of syntax-highlighting file for sublime text 2?

I've not found the answer in a similar question: Syntax specific highlighting with Sublime Text 2

2条回答
Animai°情兽
2楼-- · 2019-01-30 02:51

You can play around with this app. A lot of the languages have nice definitions in them you can work from.

http://tmtheme-editor.herokuapp.com/#/Cobalt

查看更多
爷的心禁止访问
3楼-- · 2019-01-30 02:52

Sublime Text uses the same syntax highlighting as TextMate. The grammar can be found here. I'd recommend working in JSON then converting to XML, since it's easier (at least it is for me) to read. The PackageDev plugin will give you a starting snippet for defining a new syntax. It also contains some syntax highlighting for configurations, as well as a Plist to JSON converter. Below is a snippet from a protobuf syntax definition file that highlights specific words. As for the colors of the highlights, you will have to look through your color scheme file. In the below example, you would look for the scope "constant.language" for the color it uses. You probably don't need to edit the color scheme, unless you want something other than what is already built into your scheme.

{ 
    "name": "Protocol Buffers",
    "scopeName": "source.proto",
    "fileTypes": ["proto"],
    "patterns": [{
            "match": "\\b(bool|bytes|double|fixed32|fixed64|float|int32|int64|sfixed32|sfixed64|sint32|sint64|string|uint32|uint64)\\b",
            "name": "constant.language.proto"
    }],
    "uuid": "8c8714d5-43ef-43d2-abd9-c9088901ffffd5"
}
查看更多
登录 后发表回答