-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaser_command.py
More file actions
54 lines (41 loc) · 1.73 KB
/
caser_command.py
File metadata and controls
54 lines (41 loc) · 1.73 KB
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
import re
import sublime
import sublime_plugin
import types
from . import modifiers
class CaserCommand(sublime_plugin.TextCommand):
def modify_regions(self, edit, modifier, omit_comments = False):
regions = self.view.sel()
use_whole_file = modifiers.SETTINGS.get("use_entire_file_if_no_selection", True)
if modifiers.SETTINGS.get("omit_comments") or omit_comments:
comment_regions = self.view.find_by_selector("comment")
for region in comment_regions: # here is another_comment
regions.subtract(region) # here is a CamelCaseComment
selections = []
for region in regions:
if region.empty() and len(regions) == 1 and use_whole_file:
selection = sublime.Region(0, self.view.size())
else:
selection = region
base_str = self.view.substr(selection)
modified_str = getattr(modifiers, modifier)(base_str)
self.view.replace(edit, selection, modified_str)
sublime.status_message('Finished Changing Cases.')
class CaserDowncaseCommand(CaserCommand):
def run(self, edit):
self.modify_regions(edit, 'lower')
class CaserUpcaseCommand(CaserCommand):
def run(self, edit):
self.modify_regions(edit, 'upper')
class CaserTitleizeCommand(CaserCommand):
def run(self, edit):
self.modify_regions(edit, 'title')
class CaserSnakeCaseCommand(CaserCommand):
def run(self, edit):
self.modify_regions(edit, 'snake_case')
class CaserCamelCaseCommand(CaserCommand):
def run(self, edit):
self.modify_regions(edit, 'camel_case')
class CaserWordCommand(CaserCommand):
def run(self, edit):
self.modify_regions(edit, 'snake_to_words')