forked from NETTUTS/How-to-Write-a-Sublime-Text-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prefixr-1.py
24 lines (21 loc) · 848 Bytes
/
Prefixr-1.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
import sublime
import sublime_plugin
class PrefixrCommand(sublime_plugin.TextCommand):
def run(self, edit):
# We check for braces since we can do a better job of preserving
# whitespace when braces are not present
braces = False
sels = self.view.sel()
for sel in sels:
if self.view.substr(sel).find('{') != -1:
braces = True
# Expand selection to braces, unfortunately this can't use the
# built in move_to brackets since that matches parentheses also
if not braces:
new_sels = []
for sel in sels:
new_sels.append(self.view.find('\}', sel.end()))
sels.clear()
for sel in new_sels:
sels.add(sel)
self.view.run_command("expand_selection", {"to": "brackets"})