33# @Author: lime
44# @Date: 2013-10-28 13:39:48
55# @Last Modified by: Lime
6- # @Last Modified time: 2014-08-02 17:43:53
6+ # @Last Modified time: 2014-08-11 19:45:15
7+
78
89import os
910import sys
@@ -73,7 +74,7 @@ def plugin_loaded():
7374 shutil .rmtree (PLUGIN_PATH )
7475 except :
7576 pass
76-
77+
7778 if not os .path .exists (PLUGIN_PATH ):
7879 os .mkdir (PLUGIN_PATH )
7980
@@ -130,10 +131,15 @@ def get_strftime():
130131 '''Get `time_format` setting'''
131132
132133 _ = ['%Y-%m-%d %H:%M:%S' , '%Y-%m-%d' , '%H:%M:%S' ]
133- try :
134- format = _ [Settings ().get ('time_format' )]
135- except IndexError :
136- format = _ [0 ]
134+
135+ format = Settings ().get ('custom_time_format' )
136+
137+ if not format :
138+ try :
139+ format = _ [Settings ().get ('time_format' )]
140+ except IndexError :
141+ format = _ [0 ]
142+
137143 return format
138144
139145
@@ -223,7 +229,7 @@ def get_st2_time():
223229
224230 format = get_strftime ()
225231 c_time , m_time = get_st3_time () if IS_ST3 else get_st2_time ()
226-
232+
227233 file_path = get_file_path (options .get ('path' , None ))
228234 file_name = get_file_name (options .get ('path' , None ))
229235 file_name_without_extension = get_file_name_without_extension (file_name )
@@ -266,7 +272,7 @@ def render_template(syntax_type, part=None, options={}):
266272
267273def get_syntax_type (name ):
268274 '''Judge `syntax_type` according to to `name`'''
269-
275+
270276 syntax_type = Settings ().get ('syntax_when_not_match' )
271277 file_suffix_mapping = Settings ().get ('file_suffix_mapping' )
272278
@@ -454,7 +460,7 @@ def can_add(self, path):
454460 '''Whether can add header to path'''
455461
456462 def can_add_to_dir (path ):
457- return enable_add_to_hidden_dir or (not enable_add_to_hidden_dir
463+ return enable_add_to_hidden_dir or (not enable_add_to_hidden_dir
458464 and not self .is_hidden (path ))
459465
460466 if not os .path .exists (path ):
@@ -571,11 +577,11 @@ def time_pattern(self):
571577 _ = ['\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}' ,
572578 '\d{4}-\d{2}-\d{2}' , '\d{2}:\d{2}:\d{2}' ]
573579 return _ [choice ]
574-
580+
575581 def update_automatically (self , view , what ):
576582 syntax_type = get_syntax_type (view .file_name ())
577583
578- template = get_template_part (syntax_type , 'header' )
584+ template = get_template_part (syntax_type , 'header' )
579585 lines = template .split ('\n ' )
580586
581587 line_pattern = None
@@ -591,7 +597,7 @@ def update_automatically(self, view, what):
591597 if line [i ] != ' ' :
592598 space_start = i + 1
593599 line_header = line [:space_start ]
594- break
600+ break
595601
596602 line_header = re .escape (line_header )
597603 if what == LAST_MODIFIED_BY or what == FILE_NAME or \
@@ -610,15 +616,15 @@ def update_automatically(self, view, what):
610616 _ = view .find (line_pattern , 0 )
611617 if (_ != sublime .Region (- 1 , - 1 ) and _ is not None ):
612618 a = _ .a + space_start
613- b = _ .b - 1
619+ b = _ .b - 1
614620
615621 file_name = get_file_name (view .file_name ())
616622 file_name_without_extension = get_file_name_without_extension (file_name )
617623 file_path = get_file_path (view .file_name ())
618624
619625 if what == LAST_MODIFIED_BY :
620626 strings = get_args (syntax_type )['last_modified_by' ]
621- elif what == LAST_MODIFIED_TIME :
627+ elif what == LAST_MODIFIED_TIME :
622628 strings = datetime .now ().strftime (get_strftime ())
623629 elif what == FILE_NAME :
624630 strings = file_name
@@ -632,7 +638,7 @@ def update_automatically(self, view, what):
632638
633639 region = sublime .Region (int (a ), int (b ))
634640 if view .substr (region ) != strings :
635- view .run_command ('file_header_replace' ,
641+ view .run_command ('file_header_replace' ,
636642 {'a' : a , 'b' : b , 'strings' : strings })
637643
638644 def insert_template (self , view , exists ):
@@ -679,5 +685,5 @@ def on_activated(self, view):
679685 c_time , _ = get_time (view .file_name ())
680686 if c_time is not None and settings .get ('c_time' , None ) is None :
681687 settings .set ('c_time' , pickle .dumps (c_time ))
682-
688+
683689 self .insert_template (view , True )
0 commit comments