hnt*_*rmr 3 sublimetext sublimetext3
当我编辑和保存文件时,有没有办法让 sublime text 自动更新文件注释块中的日期?
喜欢:
/**
* @author yada yada
* @date 2015-01-08
*/
Run Code Online (Sandbox Code Playgroud)
到:
/**
* @author yada yada
* @date 2015-01-19
*/
Run Code Online (Sandbox Code Playgroud)
好的,我知道了。这是一个混合
首选项 > 键绑定 - 用户
[
{"keys": ["ctrl+s"], "command": "date_and_save" }
]
Run Code Online (Sandbox Code Playgroud)
添加日期.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")
Run Code Online (Sandbox Code Playgroud)
\o/
| 归档时间: |
|
| 查看次数: |
897 次 |
| 最近记录: |