Changelog / Header / TimeStamp Plugin for Sublime Text?

二次信任 提交于 2019-12-12 05:13:05

问题


I am looking for a simple Sublime Text 2 plugin that will allow me to:

  • Insert (hopefully automatically, but not necessary) a short template with

% Created: TIMESTAMP

% Modified: TIMESTAMP

and then will replace the first TIMESTAMP once and the second every time the file is saved.


回答1:


The following plugin will get you a timestamp (modified from this question):

import sublime_plugin
from datetime import datetime

class TimeStampCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        # formatting options at http://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
        stamp = datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")  # 2013-07-18 14:54:23 UTC
        # to get the local time, change utcnow() to now()
        for r in self.view.sel():
            if r.empty():
                self.view.insert(edit, r.a, stamp)
            else:
                self.view.replace(edit, r, stamp)

Save it as Packages/User/time_stamp.py and bind it to CtrlAltT by adding

{ "keys": ["ctrl+alt+t"], "command": "time_stamp" }

to your keymap (Preferences->Key Bindings - User).

Making a plugin to automatically update the timestamp is slightly more complex, involving calling an event listener. I'm still debugging it, so check back for more...




回答2:


The FileHeader plugin for ST provides this functionality and much more.



来源:https://stackoverflow.com/questions/17714586/changelog-header-timestamp-plugin-for-sublime-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!