I have a plugin I copy/pasted from the net which adds a timestamp to tpl files on save, works on ST2 but not on ST3, the issue is due to begin_edit()
and would like to request for help on how to convert it so that it works on ST3 or a link to some examples on using the new begin_edit().
import sublime, sublime_plugin, datetime
class TimestampListener (sublime_plugin.EventListener):
def on_pre_save (self, view):
fileType = view.file_name()-4:]
if (not fileType == ".tpl"):
return
edit = view.begin_edit()
# Check for existing timestamp to replace
stamp = view.find_all("last modified:\\s*(201[0-9]-\\d+-\\d+\\s+\\d+:\\d+:\\d+(\\.\\d+)]\\s+\\+[0-9]{4}?)", 0)
for region in reversed(stamp):
view.replace(edit, region, "last modified:")
# Generate timestamp
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S +0800')
# Locate timestamp placeholder
newStamp = view.find_all("last modified:", 0)
for region in reversed(newStamp):
view.replace(edit, region, "last modified: {0}".format(timestamp))
view.end_edit (edit)
TIA