-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.py
76 lines (66 loc) · 2.53 KB
/
user.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
69
70
71
72
73
74
75
import sublime, sublime_plugin
import re
class UserListenerCommand(sublime_plugin.EventListener):
# Manage when to kick off bracket matching.
# Try and reduce redundant requests by letting the
# background thread ensure certain needed match occurs
def on_load(self, view):
filename = view.file_name()
if filename is not None:
view.set_status('filename', filename)
class AddCurrentIsoTimeCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if region.empty():
self.view.insert(edit, region.begin(), strftime("%Y-%m-%dT%H:%M:%SZ"))
class SwitchColorSetCommand(sublime_plugin.WindowCommand):
def run(self, **args):
config = {
"dark": {
"color_scheme": "Packages/Phix Color Scheme/Phix Dark.tmTheme",
"theme": "Soda Dark.sublime-theme"
},
"light": {
"color_scheme": "Packages/Color Scheme - Default/Solarized (Light).tmTheme",
"theme": "Soda Light.sublime-theme"
}
}
s = sublime.load_settings("Preferences.sublime-settings")
new_set = args["name"]
s.set("color_scheme", config[new_set]["color_scheme"])
s.set("theme", config[new_set]["theme"])
sublime.save_settings("Preferences.sublime-settings")
class TransformPlugin(sublime_plugin.TextCommand):
def transform(self, s):
return s
def run(self, edit):
for region in self.view.sel():
if not region.empty():
# Get the selected text
s = self.view.substr(region)
# Transform it
result = self.transform(s)
# Replace the selection with transformed text
self.view.replace(edit, region, result)
class RailsErbifyCommand(TransformPlugin):
def transform(self, s):
s = '<%= ' + s + ' %>'
return s
class RailsI18nifyCommand(TransformPlugin):
def transform(self, s):
s = re.sub(r'^[\'\"]', '', s)
s = re.sub(r'[\'\"]$', '', s)
key = re.sub('[^\w]', '_', s.strip()).lower()
key = re.sub('^_*', '', key)
key = re.sub('_*$', '', key)
s = "t('."+key+"', default: '"+s+"')"
return s
class FileNameOnStatusBar(sublime_plugin.EventListener):
def on_activated(self, view):
path = view.file_name()
if path:
for folder in view.window().folders():
path = path.replace(folder + '/', '', 1)
view.set_status('zz_file_name', path)
else:
view.set_status('zz_file_name', 'untitled')