Sublime Forum

Change colour patter in plain text .txt files

#1

Hello all,

I have started to use Sublime, and I woul like to do a small Syntax definition which would allow me to change the colour of some patterns, mainly strings like IPC or TST, in a plain text (.txt),for instance to put darker or into another colour. I have created my on Syntax Definition following this, I have come up with this rule syntax

{ "name": "m", "scopeName": "text.plain", "fileTypes": "txt"], "patterns": { "name": "IPC", "match": "IPC|TST" } ], "uuid": "64fc6c87-146e-43f4-a2a1-44b5f97e78e0" }

However, after creating my t.tmLanguage and creating/opening a t.txt which contains IPC|TST strings, I don´t see that they have a different colour at all… SHould I change the plain text.theme as well?

Any tip is highly appreciated!!

Thanks in advance!

0 Likes

#2

Your file is JSON. You must it convert to a plist. Install “AAAPackageDev” for this.
And it’s a good idea to use the naming conventions for scopes: http://manual.macromates.com/en/language_grammars#naming_conventions.html
And, of course, you need a “*.tmTheme” that uses the scopes from your language file.

Edit:

I’ve made a simple example.

"Plain Text.JSON-tmLanguage"

{ "name": "Plain Text", "scopeName": "source.text", "fileTypes": "txt"], "uuid": "bf19e425-1b25-4d9b-81b3-d97bdf074559", "patterns": { "match": "\\b(IPC|TST)\\b", "comment": "Match IPC or TST word boundary", "name": "keyword.other.text" } ] }
"Plain Text.tmLanguage"

[code]<?xml version="1.0" encoding="UTF-8"?>

fileTypes txt name Plain Text patterns comment Match IPC or TST word boundary match \b(IPC|TST)\b name keyword.other.text scopeName source.text uuid bf19e425-1b25-4d9b-81b3-d97bdf074559 [/code] **"Plain Text.JSON-tmTheme"** [code]{ "name": "Plain Text", "uuid": "fa5a725c-f98f-46e0-9d71-10a3034298e6", "settings": { "settings": { "invisibles": "#BFBFBF", "lineHighlight": "#FFFED8", "caret": "#000000", "foreground": "#000000", "gutterForeground": "#000090", "selection": "#E6FACD", "background": "#F6FCFD" } }, { "scope": "keyword.other", "name": "IPC or TST", "settings": { "foreground": "#9191C2", "fontStyle": "" } } ] } [/code] **"Plain Text.tmTheme"** [code]<?xml version="1.0" encoding="UTF-8"?> name Plain Text settings settings background #F6FCFD caret #000000 foreground #000000 gutterForeground #000090 invisibles #BFBFBF lineHighlight #FFFED8 selection #E6FACD name IPC or TST scope keyword.other settings fontStyle foreground #9191C2 uuid fa5a725c-f98f-46e0-9d71-10a3034298e6 [/code]
0 Likes