Skip to content

Commit ed10fd9

Browse files
committed
fix #50 #51
1 parent 39d6b34 commit ed10fd9

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

FileHeader.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# @Author: Lime
33
# @Date: 2013-10-28 13:39:48
44
# @Last Modified by: Lime
5-
# @Last Modified time: 2016-02-29 12:32:35
5+
# @Last Modified time: Thu Mar 03, 2016 07:43:26 PM
66

77
import os
88
import sys
@@ -600,25 +600,27 @@ def update_automatically(self, view, what):
600600
for line in lines:
601601
search = regex.search(line)
602602
if search is not None:
603-
index, line_header = line.find(search.group()), ''
604-
for i in range(index - 1, 0, -1):
603+
variable = search.group()
604+
index = line.find(variable)
605+
606+
line_head, line_tail = '', line[index + len(variable):]
607+
for i in range(index - 1, -1, -1):
605608
if line[i] != ' ':
606609
space_start = i + 1
607-
line_header = line[:space_start]
610+
line_head = line[:space_start]
608611
break
609-
line_pattern = '{}.*\n'.format(line_header)
612+
613+
for r in '.^$*+?{}[]()':
614+
line_head = line_head.replace(r, '\\{}'.format(r))
615+
616+
line_pattern = '{}.*\n'.format(line_head)
610617
break
611618

612619
if line_pattern is not None:
613620
_ = view.find(line_pattern, 0)
614621
if(_ != sublime.Region(-1, -1) and _ is not None):
615-
a = _.a + space_start
616-
b = _.b - 1
617-
622+
a, b = _.a + space_start, _.b - 1
618623
file_name = get_file_name(view.file_name())
619-
file_name_without_extension = get_file_name_without_extension(
620-
file_name)
621-
file_path = get_file_path(view.file_name())
622624

623625
if what == LAST_MODIFIED_BY:
624626
strings = get_args(syntax_type)['last_modified_by']
@@ -627,11 +629,12 @@ def update_automatically(self, view, what):
627629
elif what == FILE_NAME:
628630
strings = file_name
629631
elif what == FILE_NAME_WITHOUT_EXTENSION:
630-
strings = file_name_without_extension
632+
strings = get_file_name_without_extension(file_name)
631633
elif what == FILE_PATH:
632-
strings = file_path
634+
strings = get_file_path(view.file_name())
633635

634-
strings = ' ' * (index - space_start) + strings
636+
strings = '{}{}{}'.format(
637+
' ' * (index - space_start), strings, line_tail)
635638

636639
region = sublime.Region(int(a), int(b))
637640
if view.substr(region) != strings:

0 commit comments

Comments
 (0)