Skip to content

Commit

Permalink
Fix issue #23
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyanhui committed Nov 25, 2014
1 parent 43a4c0d commit b0d3e2e
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 71 deletions.
1 change: 0 additions & 1 deletion Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
}
}
]

}
]
4 changes: 2 additions & 2 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[
{
"keys": ["ctrl+alt+n"],
"keys": ["ctrl+alt+n"],
"command": "file_header_new_file",
"args":{
"paths": []
}
},
{
"keys": ["ctrl+alt+a"],
"keys": ["ctrl+alt+a"],
"command": "file_header_add_header",
"args":{
"paths": []
Expand Down
4 changes: 2 additions & 2 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[
{
"keys": ["super+alt+n"],
"keys": ["super+alt+n"],
"command": "file_header_new_file",
"args":{
"paths": []
}
},
{
"keys": ["super+alt+a"],
"keys": ["super+alt+a"],
"command": "file_header_add_header",
"args":{
"paths": []
Expand Down
4 changes: 2 additions & 2 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[
{
"keys": ["ctrl+alt+n"],
"keys": ["ctrl+alt+n"],
"command": "file_header_new_file",
"args":{
"paths": []
}
},
{
"keys": ["ctrl+alt+a"],
"keys": ["ctrl+alt+a"],
"command": "file_header_add_header",
"args":{
"paths": []
Expand Down
39 changes: 26 additions & 13 deletions FileHeader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# @Author: lime
# @Date: 2013-10-28 13:39:48
# @Last Modified by: Lime
# @Last Modified time: 2014-08-11 19:45:15

# @Last Modified time: 2014-11-25 14:20:32

import os
import sys
Expand All @@ -27,7 +26,6 @@
else:
import subprocess as process


PLUGIN_NAME = 'FileHeader'
INSTALLED_PLUGIN_NAME = '%s.sublime-package' % PLUGIN_NAME
PACKAGES_PATH = sublime.packages_path()
Expand Down Expand Up @@ -106,7 +104,6 @@ def get_template_part(syntax_type, part):
tmpl_file = os.path.join(path, tmpl_name)

custom_template_path = Settings().get('custom_template_%s_path' % part)
print(custom_template_path)
if custom_template_path:
_ = os.path.join(custom_template_path, tmpl_name)
if os.path.exists(_) and os.path.isfile(_):
Expand All @@ -123,8 +120,9 @@ def get_template_part(syntax_type, part):


def get_template(syntax_type):
parts = ['header', 'body']
return ''.join([get_template_part(syntax_type, part) for part in parts])
return ''.join(
[get_template_part(syntax_type, part)
for part in ['header', 'body']])


def get_strftime():
Expand Down Expand Up @@ -160,7 +158,8 @@ def get_project_name():
'''Get project name'''

project_data = sublime.active_window().project_data()
project = os.path.basename(project_data['folders'][0]['path']) if project_data else None
project = os.path.basename(
project_data['folders'][0]['path']) if project_data else None

return project

Expand Down Expand Up @@ -275,14 +274,23 @@ def get_syntax_type(name):

syntax_type = Settings().get('syntax_when_not_match')
file_suffix_mapping = Settings().get('file_suffix_mapping')
extension_equivalence = Settings().get('extension_equivalence')

if name is not None:
name = name.split('.')
if len(name) <= 1:
return syntax_type

for i in range(1, len(name)):
suffix = '%s' % '.'.join(name[i:])
if suffix in extension_equivalence:
suffix = extension_equivalence[suffix]
break
else:
suffix = name[-1]

try:
syntax_type = file_suffix_mapping[name[-1]]
syntax_type = file_suffix_mapping[suffix]
except KeyError:
pass

Expand Down Expand Up @@ -340,7 +348,8 @@ def new_file(self, path, syntax_type):
new_file = Window().open_file(path)

try:
block(new_file, new_file.set_syntax_file, get_syntax_file(syntax_type))
block(new_file,
new_file.set_syntax_file, get_syntax_file(syntax_type))
except:
pass

Expand Down Expand Up @@ -563,7 +572,8 @@ class FileHeaderListener(sublime_plugin.EventListener):
LAST_MODIFIED_BY_REGEX = re.compile('\{\{\s*last_modified_by\s*\}\}')
LAST_MODIFIED_TIME_REGEX = re.compile('\{\{\s*last_modified_time\s*\}\}')
FILE_NAME_REGEX = re.compile('\{\{\s*file_name\s*\}\}')
FILE_NAME_WITHOUT_EXTENSION_REGEX = re.compile('\{\{\s*file_name_without_extension\s*\}\}')
FILE_NAME_WITHOUT_EXTENSION_REGEX = re.compile(
'\{\{\s*file_name_without_extension\s*\}\}')
FILE_PATH_REGEX = re.compile('\{\{\s*file_path\s*\}\}')

new_view_id = []
Expand Down Expand Up @@ -601,11 +611,13 @@ def update_automatically(self, view, what):

line_header = re.escape(line_header)
if what == LAST_MODIFIED_BY or what == FILE_NAME or \
what == FILE_NAME_WITHOUT_EXTENSION or what == FILE_PATH:
what == FILE_NAME_WITHOUT_EXTENSION or \
what == FILE_PATH:
line_pattern = '%s.*\n' % line_header

elif what == LAST_MODIFIED_TIME:
line_pattern = '%s\s*%s.*\n' % (line_header, self.time_pattern())
line_pattern = '%s\s*%s.*\n' % (
line_header, self.time_pattern())

else:
raise KeyError()
Expand All @@ -619,7 +631,8 @@ def update_automatically(self, view, what):
b = _.b - 1

file_name = get_file_name(view.file_name())
file_name_without_extension = get_file_name_without_extension(file_name)
file_name_without_extension = get_file_name_without_extension(
file_name)
file_path = get_file_path(view.file_name())

if what == LAST_MODIFIED_BY:
Expand Down
11 changes: 9 additions & 2 deletions FileHeader.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
that under **Default**. If FileHeader don't find the suffix,
FileHeader will set language as **syntax_when_not_match** above.
*/
"file_suffix_mapping":{
"file_suffix_mapping": {
"as": "ActionScript",
"scpt": "AppleScript",
"asp": "ASP",
Expand Down Expand Up @@ -120,6 +120,14 @@
"txt": "Text",
"xml": "XML"
},
/*
Set special file suffix equivalence. Take `blade.php` for example,
FileHeader will initial file with suffix `blade.php` with that of `html`.
*/
"extension_equivalence": {
"blade.php": "html",
},

/*
Variables
Expand Down Expand Up @@ -205,7 +213,6 @@
Can't be set custom.
*/


/*
Email
*/
Expand Down
1 change: 0 additions & 1 deletion Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"caption": "File Header",
"children":
[

{
"command": "open_file",
"args": {"file": "${packages}/FileHeader/FileHeader.sublime-settings"},
Expand Down
Loading

0 comments on commit b0d3e2e

Please sign in to comment.