33# @Author: lime
44# @Date: 2013-10-28 13:39:48
55# @Last Modified by: Lime
6- # @Last Modified time: 2014-08-11 19:45:15
7-
6+ # @Last Modified time: 2014-11-25 14:20:32
87
98import os
109import sys
2726else :
2827 import subprocess as process
2928
30-
3129PLUGIN_NAME = 'FileHeader'
3230INSTALLED_PLUGIN_NAME = '%s.sublime-package' % PLUGIN_NAME
3331PACKAGES_PATH = sublime .packages_path ()
@@ -106,7 +104,6 @@ def get_template_part(syntax_type, part):
106104 tmpl_file = os .path .join (path , tmpl_name )
107105
108106 custom_template_path = Settings ().get ('custom_template_%s_path' % part )
109- print (custom_template_path )
110107 if custom_template_path :
111108 _ = os .path .join (custom_template_path , tmpl_name )
112109 if os .path .exists (_ ) and os .path .isfile (_ ):
@@ -123,8 +120,9 @@ def get_template_part(syntax_type, part):
123120
124121
125122def get_template (syntax_type ):
126- parts = ['header' , 'body' ]
127- return '' .join ([get_template_part (syntax_type , part ) for part in parts ])
123+ return '' .join (
124+ [get_template_part (syntax_type , part )
125+ for part in ['header' , 'body' ]])
128126
129127
130128def get_strftime ():
@@ -160,7 +158,8 @@ def get_project_name():
160158 '''Get project name'''
161159
162160 project_data = sublime .active_window ().project_data ()
163- project = os .path .basename (project_data ['folders' ][0 ]['path' ]) if project_data else None
161+ project = os .path .basename (
162+ project_data ['folders' ][0 ]['path' ]) if project_data else None
164163
165164 return project
166165
@@ -275,14 +274,23 @@ def get_syntax_type(name):
275274
276275 syntax_type = Settings ().get ('syntax_when_not_match' )
277276 file_suffix_mapping = Settings ().get ('file_suffix_mapping' )
277+ extension_equivalence = Settings ().get ('extension_equivalence' )
278278
279279 if name is not None :
280280 name = name .split ('.' )
281281 if len (name ) <= 1 :
282282 return syntax_type
283283
284+ for i in range (1 , len (name )):
285+ suffix = '%s' % '.' .join (name [i :])
286+ if suffix in extension_equivalence :
287+ suffix = extension_equivalence [suffix ]
288+ break
289+ else :
290+ suffix = name [- 1 ]
291+
284292 try :
285- syntax_type = file_suffix_mapping [name [ - 1 ] ]
293+ syntax_type = file_suffix_mapping [suffix ]
286294 except KeyError :
287295 pass
288296
@@ -340,7 +348,8 @@ def new_file(self, path, syntax_type):
340348 new_file = Window ().open_file (path )
341349
342350 try :
343- block (new_file , new_file .set_syntax_file , get_syntax_file (syntax_type ))
351+ block (new_file ,
352+ new_file .set_syntax_file , get_syntax_file (syntax_type ))
344353 except :
345354 pass
346355
@@ -563,7 +572,8 @@ class FileHeaderListener(sublime_plugin.EventListener):
563572 LAST_MODIFIED_BY_REGEX = re .compile ('\{\{\s*last_modified_by\s*\}\}' )
564573 LAST_MODIFIED_TIME_REGEX = re .compile ('\{\{\s*last_modified_time\s*\}\}' )
565574 FILE_NAME_REGEX = re .compile ('\{\{\s*file_name\s*\}\}' )
566- FILE_NAME_WITHOUT_EXTENSION_REGEX = re .compile ('\{\{\s*file_name_without_extension\s*\}\}' )
575+ FILE_NAME_WITHOUT_EXTENSION_REGEX = re .compile (
576+ '\{\{\s*file_name_without_extension\s*\}\}' )
567577 FILE_PATH_REGEX = re .compile ('\{\{\s*file_path\s*\}\}' )
568578
569579 new_view_id = []
@@ -601,11 +611,13 @@ def update_automatically(self, view, what):
601611
602612 line_header = re .escape (line_header )
603613 if what == LAST_MODIFIED_BY or what == FILE_NAME or \
604- what == FILE_NAME_WITHOUT_EXTENSION or what == FILE_PATH :
614+ what == FILE_NAME_WITHOUT_EXTENSION or \
615+ what == FILE_PATH :
605616 line_pattern = '%s.*\n ' % line_header
606617
607618 elif what == LAST_MODIFIED_TIME :
608- line_pattern = '%s\s*%s.*\n ' % (line_header , self .time_pattern ())
619+ line_pattern = '%s\s*%s.*\n ' % (
620+ line_header , self .time_pattern ())
609621
610622 else :
611623 raise KeyError ()
@@ -619,7 +631,8 @@ def update_automatically(self, view, what):
619631 b = _ .b - 1
620632
621633 file_name = get_file_name (view .file_name ())
622- file_name_without_extension = get_file_name_without_extension (file_name )
634+ file_name_without_extension = get_file_name_without_extension (
635+ file_name )
623636 file_path = get_file_path (view .file_name ())
624637
625638 if what == LAST_MODIFIED_BY :
0 commit comments