-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- If there is a comment at the end of the line, place the semicolon before the comment - Don't place a semicolon if one is already present
- Loading branch information
Maurice Zhang
committed
Jun 26, 2015
1 parent
5688b82
commit 06983ab
Showing
1 changed file
with
34 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
import sublime_plugin; | ||
import sublime_plugin | ||
|
||
class AppendSemiColonCommand(sublime_plugin.TextCommand): | ||
def run(self, edit): | ||
for region in self.view.sel(): | ||
line_end = self.view.line(region).end() | ||
if self.view.substr(line_end - 1) != ';': | ||
self.view.insert(edit, line_end, ';') | ||
def run(self, edit): | ||
|
||
def insert_semicolon(point): | ||
self.view.insert(edit, point, ';') | ||
|
||
def is_semicolon(point): | ||
return self.view.substr(point) == ';' | ||
|
||
for region in self.view.sel(): | ||
line = self.view.line(region) | ||
line_begin = line.begin() | ||
line_end = line.end() | ||
|
||
while(self.view.substr(line_end - 1).isspace() and line_end != line_begin): # go to the first character from the end that isn't whitespace | ||
line_end -= 1 | ||
|
||
if line_end == line_begin: | ||
continue | ||
|
||
if self.view.match_selector(line_end - 1, 'comment'): | ||
point = self.view.extract_scope(line_end - 1).a - 1 | ||
|
||
if point < line_begin: | ||
continue | ||
|
||
while(self.view.substr(point).isspace() and point != line_begin): # go to the first character before the comment that isn't whitespace | ||
point -= 1 | ||
|
||
if not self.view.substr(point).isspace() and not is_semicolon(point): | ||
insert_semicolon(point + 1) | ||
|
||
elif not is_semicolon(line_end - 1): | ||
insert_semicolon(line_end) |