Created
March 18, 2016 12:53
-
-
Save is/7858c68f76cca54ccc13 to your computer and use it in GitHub Desktop.
Sublime tagline plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sublime, sublime_plugin | |
| import time | |
| class IsNoteCommand(sublime_plugin.TextCommand): | |
| def run(self, edit): | |
| pos = self.view.sel()[0].begin() | |
| noteid = self.noteid() | |
| message = "==NOTE-%d %s" % (noteid, time.strftime("%Y.%m.%d %H:%M:%S\n")) | |
| self.view.insert(edit, pos, message) | |
| def noteid(self): | |
| # ref: | |
| # https://forum.sublimetext.com/t/how-to-get-complete-text-contents-of-active-tab/4758/2 | |
| noteid = 0 | |
| content = self.view.substr(sublime.Region(0, self.view.size())) | |
| lines = content.replace("\r\n", "\n").replace("\r", "\n").split("\n") | |
| for line in lines: | |
| if (line.startswith("==NOTE-")): | |
| curid = int(line[7:].split()[0]) | |
| if (curid > noteid): | |
| noteid = curid | |
| noteid += 1 | |
| return noteid; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment