|
# coding: utf8 |
|
import sublime, sublime_plugin |
|
from datetime import datetime |
|
|
|
class InsertTimestampCommand(sublime_plugin.TextCommand): |
|
def run(self, edit): |
|
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
|
pattern = '\{\s*@timestamp\s*\}' |
|
insert_ts = self.view.find_all(pattern, 0) |
|
insert_ts.reverse() |
|
for region in insert_ts: |
|
self.view.replace(edit, region, timestamp) |
|
|
|
class InsertTimestamp(sublime_plugin.EventListener): |
|
def on_pre_save(self, view): |
|
filename = view.file_name() |
|
if filename.lower().endswith(('.tpl','.html','.php','.css','.js')): |
|
view.run_command("insert_timestamp") |
|
|
|
class UpdateTimestampCommand(sublime_plugin.TextCommand): |
|
def run(self, edit): |
|
timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
|
pattern = "(20[0-9][0-9]-\\d+-\\d+\\s+\\d+:\\d+:\\d+[(\\.\\d+)]?)" |
|
update_ts = self.view.find_all(pattern, 0) |
|
update_ts.reverse() |
|
for region in update_ts: |
|
replacement = '%s' % timestamp |
|
self.view.replace(edit, region, replacement) |
|
|
|
class UpdateTimestamp(sublime_plugin.EventListener): |
|
def on_pre_save(self, view): |
|
filename = view.file_name() |
|
if filename.lower().endswith(('.tpl','.html','.php','.css','.js')): |
|
view.run_command("update_timestamp") |
|
|