Skip to content

Commit b0d3e2e

Browse files
committed
Fix issue #23
1 parent 43a4c0d commit b0d3e2e

15 files changed

+102
-71
lines changed

Context.sublime-menu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@
1818
}
1919
}
2020
]
21-
2221
}
2322
]

Default (Linux).sublime-keymap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[
22
{
3-
"keys": ["ctrl+alt+n"],
3+
"keys": ["ctrl+alt+n"],
44
"command": "file_header_new_file",
55
"args":{
66
"paths": []
77
}
88
},
99
{
10-
"keys": ["ctrl+alt+a"],
10+
"keys": ["ctrl+alt+a"],
1111
"command": "file_header_add_header",
1212
"args":{
1313
"paths": []

Default (OSX).sublime-keymap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[
22
{
3-
"keys": ["super+alt+n"],
3+
"keys": ["super+alt+n"],
44
"command": "file_header_new_file",
55
"args":{
66
"paths": []
77
}
88
},
99
{
10-
"keys": ["super+alt+a"],
10+
"keys": ["super+alt+a"],
1111
"command": "file_header_add_header",
1212
"args":{
1313
"paths": []

Default (Windows).sublime-keymap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[
22
{
3-
"keys": ["ctrl+alt+n"],
3+
"keys": ["ctrl+alt+n"],
44
"command": "file_header_new_file",
55
"args":{
66
"paths": []
77
}
88
},
99
{
10-
"keys": ["ctrl+alt+a"],
10+
"keys": ["ctrl+alt+a"],
1111
"command": "file_header_add_header",
1212
"args":{
1313
"paths": []

FileHeader.py

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

98
import os
109
import sys
@@ -27,7 +26,6 @@
2726
else:
2827
import subprocess as process
2928

30-
3129
PLUGIN_NAME = 'FileHeader'
3230
INSTALLED_PLUGIN_NAME = '%s.sublime-package' % PLUGIN_NAME
3331
PACKAGES_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

125122
def 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

130128
def 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:

FileHeader.sublime-settings

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
that under **Default**. If FileHeader don't find the suffix,
7979
FileHeader will set language as **syntax_when_not_match** above.
8080
*/
81-
"file_suffix_mapping":{
81+
"file_suffix_mapping": {
8282
"as": "ActionScript",
8383
"scpt": "AppleScript",
8484
"asp": "ASP",
@@ -120,6 +120,14 @@
120120
"txt": "Text",
121121
"xml": "XML"
122122
},
123+
/*
124+
Set special file suffix equivalence. Take `blade.php` for example,
125+
FileHeader will initial file with suffix `blade.php` with that of `html`.
126+
127+
*/
128+
"extension_equivalence": {
129+
"blade.php": "html",
130+
},
123131

124132
/*
125133
Variables
@@ -205,7 +213,6 @@
205213
Can't be set custom.
206214
*/
207215

208-
209216
/*
210217
Email
211218
*/

Main.sublime-menu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"caption": "File Header",
1414
"children":
1515
[
16-
1716
{
1817
"command": "open_file",
1918
"args": {"file": "${packages}/FileHeader/FileHeader.sublime-settings"},

0 commit comments

Comments
 (0)