Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyanhui committed Nov 3, 2013
1 parent d700fef commit 01ad2c5
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions FileHeader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# @Date: 2013-10-28 13:39:48
# @Email: [email protected]
# @Last modified by: lime
# @Last Modified time: 2013-11-03 12:08:08
# @Last Modified time: 2013-11-03 14:26:11

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


PLUGIN_NAME = 'FileHeader'
PACKAGES_PATH = sublime.packages_path()
PLUGIN_PATH = os.path.join(PACKAGES_PATH, PLUGIN_NAME)
Expand Down Expand Up @@ -436,14 +437,21 @@ def run(self, paths=[]):


class FileHeaderReplaceCommand(sublime_plugin.TextCommand):

'''Replace contents in the `region` with `stirng`'''

def run(self, edit, a, b, strings):
region = sublime.Region(int(a), int(b))
self.view.replace(edit, region, strings)


class FileHeaderMultiUndoCommand(sublime_plugin.TextCommand):
'''Repeat Undo'''

def run(self, edit, times):
for i in range(times):
self.view.run_command('undo')


class FileHeaderListener(sublime_plugin.EventListener):

'''Auto update `last_modified_time` when save file'''
Expand Down Expand Up @@ -482,14 +490,16 @@ def get_line_pattern(self, view, lines, what):
line_header = line[: space_start]
break

origin_line_header = line_header

line_header = line_header.replace('*', '\*')
if what == 'BY':
line_pattern = '%s.*' % line_header
else:
line_pattern = '%s\s*%s.*' % (line_header,
self.time_pattern())

line_header = line_header + (index - space_start) * ' '
line_header = origin_line_header + (index - space_start) * ' '
break

return line_pattern, line_header
Expand Down Expand Up @@ -554,17 +564,22 @@ def on_new(self, view):

FileHeaderListener.new_view_id.append(view.id())

def on_text_command(self, view, command_name, args):
pass


def on_pre_save(self, view):
if view.id() in FileHeaderListener.new_view_id:
self.insert_template(view, False)
index = FileHeaderListener.new_view_id.index(view.id())
del FileHeaderListener.new_view_id[index]
else:
new_buffer, found = self.get_new_buffer(view)
if found:
view.run_command('file_header_replace',
{'a': 0, 'b': view.size(),
'strings': new_buffer})
if view.is_dirty():
new_buffer, found = self.get_new_buffer(view)
if found:
view.run_command('file_header_replace',
{'a': 0, 'b': view.size(),
'strings': new_buffer})

def on_activated(self, view):
self.insert_template(view, True)

0 comments on commit 01ad2c5

Please sign in to comment.