Custom syntax highlighting in Sublime Text 2

孤人 提交于 2019-11-28 15:51:30

问题


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


回答1:


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-c9088901ddd5"
}



回答2:


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



来源:https://stackoverflow.com/questions/15221150/custom-syntax-highlighting-in-sublime-text-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!