Sublime Forum

Automatic detection of diff files

#1

Hi,

Textmate was automatically detecting that my file was a diff file, so the colors were there straight away: git diff | mate
Doing it with sublime text, it doesn’t recognize my file type, so I always have to select the ‘diff’ extension in the dropdown…
The header of the file always starts with ‘diff --git /a …’, is there a way to make that automatic?

Thanks :smile:

0 Likes

#2

FWIK, file are identified by extension or with the first line content according to what is specified in the tmLanguage.
For Diff file:

<key>fileTypes</key> <array> <string>diff</string> <string>patch</string> </array> <key>firstLineMatch</key> <string>(?x)^ (===\ modified\ file |==== \s* // .+ \s - \s .+ \s+ ==== |Index:\ |---\ ^%] |\*\*\*.*\d{4}\s*$ |\d+(,\d+)* (a|d|c) \d+(,\d+)* $ |diff\ --git\ ) </string>
So “diff --git xxx” is in the firstLineMatch and it must work if your file look like:

diff --git a/git.py b/git.py ...
It work for me on Windows.

0 Likes

#3

There’s an issue with the associated regex; will fix for the next build

0 Likes

#4

Ok, thanks. Any quickfix for now? Like changing manually the regex on my app?

0 Likes

#5

Edit the associated .tmLanguage file, and change:

diff\ --git\

to

diff\ --git ]
0 Likes

#6

Thanks a lot for the fast response and the great job, it works perfectly :smile:

0 Likes