-
Notifications
You must be signed in to change notification settings - Fork 71
/
jotter.py
69 lines (49 loc) · 2.15 KB
/
jotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
import sublime, sublime_plugin
import os, time
ST3 = int(sublime.version()) >= 3000
if not ST3:
from codecs import open
def settings():
return sublime.load_settings('Notes.sublime-settings')
def get_root():
return os.path.normpath(os.path.expanduser(settings().get("root")))
def brain_dir():
brain_settings = settings().get("jotter_dir")
if brain_settings:
return brain_settings
else:
return ".brain"
class JotterCommand(sublime_plugin.TextCommand):
def run(self, edit):
window = self.view.window()
output = self.view.window().get_output_panel("jotter")
self.view.window().run_command("show_panel", {"panel": "output.jotter"})
output.settings().set("color_scheme", settings().get("jotter_color_scheme"))
output.settings().set("is_jott", True)
output.set_syntax_file("Packages/PlainNotes/Note.tmLanguage")
sublime.status_message(u" ✎ Jot down your note and press ESC when done. It will be saved to your 'Inbox'")
output.set_read_only(False)
window.focus_view(output)
class SaveJotAndHidePanelCommand(sublime_plugin.TextCommand):
def run(self, edit):
v = self.view
w = self.view.window()
if not v.settings().get("is_jott"):
w.run_command("hide_panel", {"cancel": True})
return
text = v.substr(sublime.Region(0, v.size()))
if not text or text.isspace():
w.run_command("hide_panel", {"cancel": True})
return
jot = '# ' + time.strftime(settings().get("jotter_date_format")) + u' — ' + time.strftime(settings().get("jotter_time_format")) + u'\n' + text.rstrip(u'\r\n') + u'\n\n'
with open(os.path.join(get_root(), brain_dir(), "Inbox.note"), mode='r+', encoding='utf-8') as f:
content = f.read()
f.seek(0, 0)
f.write(jot + content)
w.run_command("hide_panel", {"cancel": True})
class OpenInboxCommand(sublime_plugin.ApplicationCommand):
def run(self):
root = get_root()
inbox = os.path.join(root, brain_dir(), 'Inbox.note')
sublime.active_window().open_file(inbox)