is there a way that sublime text automatically updates the date in a comment block on a file when I edit and save it?
like:
/**
* @author yada yada
* @date 2015-01-08
*/
to:
/**
* @author yada yada
* @date 2015-01-19
*/
is there a way that sublime text automatically updates the date in a comment block on a file when I edit and save it?
like:
/**
* @author yada yada
* @date 2015-01-08
*/
to:
/**
* @author yada yada
* @date 2015-01-19
*/
ok, got it. it's a mix of
Preferences > Key Bindings- User
[
{"keys": ["ctrl+s"], "command": "date_and_save" }
]
add_date.py
'''
Autodate header
@date <>
'''
from datetime import datetime
import sublime, sublime_plugin
class AddDateCommand(sublime_plugin.TextCommand):
def run(self, args):
content = self.view.substr(sublime.Region(0, self.view.size()))
begin = content.find('@date <',0,100)
if begin == -1:
return
end = content.find("\n", begin)
target_region = sublime.Region(begin, end)
self.view.sel().clear()
self.view.sel().add(target_region)
self.view.run_command(
"insert_snippet",
{ "contents": "@date <%s>" % datetime.now().strftime("%Y-%m-%d %H:%M:%S") } )
class DateAndSaveCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.run_command("add_date")
self.window.run_command("save")
\o/
Awesome stuff! Small addition to the above solution:
Instead of
end = begin + 19
This line will make it more dynamical, because it will get rid of everything until the end of the line.
end = content.find("\n", begin)
Helps with versioning up, for example, where the line-length can vary.