Skip to content

Commit 43a4c0d

Browse files
committed
fix #19
1 parent 524a67f commit 43a4c0d

2 files changed

Lines changed: 56 additions & 44 deletions

File tree

FileHeader.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
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

89
import os
910
import 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

267273
def 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)

FileHeader.sublime-settings

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,28 @@
1313
*/
1414
"time_format": 0,
1515
/*
16+
The custom time format. It will format `create_time` and `last_modified_time`
17+
instead of `time_format` if you set it. The time format refers to`
18+
https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior`.
19+
*/
20+
"custom_time_format": "",
21+
/*
1622
Whether add template to the empty file.
1723
18-
It's useful when you create new file through other command, for
24+
It's useful when you create new file through other command, for
1925
example, the default Sublime Text's **New File...** or other plugin.
2026
*/
2127
"enable_add_template_to_empty_file": true,
2228
/*
23-
Set your custom template header path here, it is a directory in which
24-
you write your own header files. The file name should be a language,
25-
"Python.tmpl" for example.
29+
Set your custom template header path here, it is a directory in which
30+
you write your own header files. The file name should be a language,
31+
"Python.tmpl" for example.
2632
*/
2733
"custom_template_header_path": "",
2834
/*
29-
Set your custom template body path here, it is a directory in which
30-
you write your own body files. The file name should be a language,
31-
"Python.tmpl" for example.
35+
Set your custom template body path here, it is a directory in which
36+
you write your own body files. The file name should be a language,
37+
"Python.tmpl" for example.
3238
3339
The template structure is:
3440
@@ -40,23 +46,23 @@
4046
*/
4147
"custom_template_body_path": "",
4248
/*
43-
Whether show input panel when you add header. The default file which
49+
Whether show input panel when you add header. The default file which
4450
you add header to is the current file you edit.
4551
*/
4652
"show_input_panel_when_add_header": true,
4753
/*
48-
Whether open file when you add header to files in the specified
54+
Whether open file when you add header to files in the specified
4955
directory.
5056
*/
5157
"open_file_when_add_header_to_directory": true,
5258
/*
53-
Whether enable add header to hidden directory. If false, FileHeader
54-
won't add header to files under it.
59+
Whether enable add header to hidden directory. If false, FileHeader
60+
won't add header to files under it.
5561
*/
5662
"enable_add_header_to_hidden_dir": false,
5763
/*
58-
Whether enable add header to hidden file. If false, FileHeader
59-
won't add header to it.
64+
Whether enable add header to hidden file. If false, FileHeader
65+
won't add header to it.
6066
*/
6167
"enable_add_header_to_hidden_file": false,
6268
/*
@@ -68,7 +74,7 @@
6874
"syntax_when_not_match": "Text",
6975
/*
7076
FileHeader will judge programming language according to file suffix.
71-
You can add more file suffix here. Note: language should be one of
77+
You can add more file suffix here. Note: language should be one of
7278
that under **Default**. If FileHeader don't find the suffix,
7379
FileHeader will set language as **syntax_when_not_match** above.
7480
*/
@@ -78,7 +84,7 @@
7884
"asp": "ASP",
7985
"aspx": "ASP",
8086
"bat": "Batch File",
81-
"cmd": "Batch File",
87+
"cmd": "Batch File",
8288
"c": "C",
8389
"cs": "C#",
8490
"cpp": "C++",
@@ -119,47 +125,47 @@
119125
Variables
120126
=========
121127
*/
122-
128+
123129
/*
124130
Below is the variables you render templater.
125131
*/
126132
"Default": {
127133
/*
128134
Builtin Variables
129135
=================
130-
136+
131137
- create_time
132138
133139
The file created time. It will be automatically set when you create
134-
a new file if you use it.
140+
a new file if you use it.
135141
136142
Can't be set custom.
137143
138144
- author
139145
140-
The file creator.
146+
The file creator.
141147
142148
FileHeader will set it automatically. If it's in
143-
a git repository and the `user.name` has been set, `autor`
144-
will set to `user.name`, otherwise it will be set to current
149+
a git repository and the `user.name` has been set, `autor`
150+
will set to `user.name`, otherwise it will be set to current
145151
system user.
146152
147153
Can be set custom.
148154
149155
- last_modified_by
150156
151-
The file last modified by who? It is specially useful when
152-
cooperation programming.
157+
The file last modified by who? It is specially useful when
158+
cooperation programming.
153159
154160
FileHeader will set it automatically. If it's in
155-
a git repository and the `user.name` has been set, `autor`
156-
will set to `user.name`, otherwise it will be set to current
157-
system logined user.
161+
a git repository and the `user.name` has been set, `autor`
162+
will set to `user.name`, otherwise it will be set to current
163+
system logined user.
158164
159165
Can be set custom.
160166
161167
- last_modified_time
162-
168+
163169
The file last modified time.
164170
165171
FileHeader will set it automatically when you save the file.
@@ -208,7 +214,7 @@
208214
// You can add more here......
209215
},
210216
/*
211-
You can set different variables in different languages. It will cover
217+
You can set different variables in different languages. It will cover
212218
that in "Default".
213219
*/
214220
"ASP": {},

0 commit comments

Comments
 (0)