-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
23 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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''' | ||
|
@@ -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 | ||
|
@@ -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) |