44

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

Community
  • 1
  • 1
sev3ryn
  • 1,055
  • 1
  • 9
  • 17
  • Also, take a look at this question: http://stackoverflow.com/questions/15010032/how-to-add-syntax-highlighting-to-sublime-text-2. I assume you would have to edit the xml tmLanguage file and add a context for "ERROR" instances. Then edit the color scheme file you are using and add a foreground color for ERRORs. – d_rail Mar 05 '13 at 22:10
  • For anyone that is looking for Monokai and nice JSON highlighting: https://goo.gl/39ZBnA – electronix384128 Dec 21 '14 at 21:05

2 Answers2

39

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"
}
MattDMo
  • 100,794
  • 21
  • 241
  • 231
skuroda
  • 19,514
  • 4
  • 50
  • 34
  • Well I was wondering, how can I use Sublime to do syntax highlighting for .proto ( Protocol Buffer ) files ? – java_enthu Jan 03 '14 at 10:23
  • @java_enthu It's pretty minimal, but you can use https://github.com/skuroda/config/blob/master/sublime_text/Syntax/Protobuf/protobuf.tmLanguage. Save the contents of that file in your User folder. – skuroda Jan 04 '14 at 01:04
  • Thanks @skuroda : Do you mean if its windows box , the file to be saved in c:/users/Username folder ? – java_enthu Jan 06 '14 at 06:18
  • 1
    @java_enthu If you go to `Preferences -> Browse Packages`, it'll put you in the proper location. From there, you can copy/paste the absolute path. If you want to find it yourself, it will be located at `%APPDATA%/Roaming/Sublime Text 2/Packages/` (may be Sublime Text 3 depending on version). – skuroda Jan 06 '14 at 06:46
7

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

geedew
  • 1,368
  • 12
  • 16