Home Download Buy Blog Forum Support

Automatic detection of diff files

Automatic detection of diff files

Postby vincentp on Thu Jan 26, 2012 9:31 am

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 :)
vincentp
 
Posts: 5
Joined: Thu Jan 26, 2012 9:25 am

Re: Automatic detection of diff files

Postby bizoo on Thu Jan 26, 2012 10:23 am

FWIK, file are identified by extension or with the first line content according to what is specified in the tmLanguage.
For Diff file:
Code: Select all
   <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:
Code: Select all
diff --git a/git.py b/git.py
...

It work for me on Windows.
bizoo
 
Posts: 889
Joined: Wed Dec 08, 2010 6:53 am
Location: Switzerland

Re: Automatic detection of diff files

Postby jps on Thu Jan 26, 2012 10:37 am

There's an issue with the associated regex; will fix for the next build
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Automatic detection of diff files

Postby vincentp on Thu Jan 26, 2012 2:00 pm

Ok, thanks. Any quickfix for now? Like changing manually the regex on my app?
vincentp
 
Posts: 5
Joined: Thu Jan 26, 2012 9:25 am

Re: Automatic detection of diff files

Postby jps on Thu Jan 26, 2012 9:20 pm

Edit the associated .tmLanguage file, and change:

Code: Select all
diff\ --git\


to

Code: Select all
diff\ --git[ ]
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Automatic detection of diff files

Postby vincentp on Thu Jan 26, 2012 9:33 pm

Thanks a lot for the fast response and the great job, it works perfectly :)
vincentp
 
Posts: 5
Joined: Thu Jan 26, 2012 9:25 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 18 guests