├── Default.sublime-keymap
├── Default (OSX).sublime-keymap
├── README.md
├── AppendSemiColon.py
└── Main.sublime-menu
/Default.sublime-keymap:
--------------------------------------------------------------------------------
1 | [
2 | { "keys": ["ctrl+;"], "command": "append_semi_colon" },
3 | { "keys": ["ctrl+shift+;"], "command": "append_semi_colon", "args": {"enter_new_line": "true"} }
4 | ]
5 |
--------------------------------------------------------------------------------
/Default (OSX).sublime-keymap:
--------------------------------------------------------------------------------
1 | [
2 | { "keys": ["super+;"], "command": "append_semi_colon" },
3 | { "keys": ["super+shift+;"], "command": "append_semi_colon", "args": {"enter_new_line": "true"} }
4 | ]
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AppendSemiColon
2 | Sublime package to append semi colons at the end of a line.
3 |
4 | Place a semicolon at the end of the cursor's current line(s) by pressing:
5 | + Command+; on OS X
6 | + Ctrl+; on Windows and Linux
7 |
8 | This is especially useful in situations like these:
9 |
10 | 
11 |
12 | You can also automatically go to the next line at the same time like this:
13 |
14 | 
15 |
16 | with these shorcuts:
17 | + Command+Shift+; on OS X
18 | + Ctrl+Shift+; on Windows and Linux
19 |
20 | ## Other Features
21 | + If a line already ends with a semicolon, no semicolon will be added
22 | + When appending a semicolon to a line ending in a comment, the semicolon will be placed before the comment
23 |
24 | ## Installation
25 |
26 | Install [Package Control](https://packagecontrol.io/installation) and search for AppendSemiColon
27 |
--------------------------------------------------------------------------------
/AppendSemiColon.py:
--------------------------------------------------------------------------------
1 | import sublime_plugin
2 |
3 | class AppendSemiColonCommand(sublime_plugin.TextCommand):
4 | def run(self, edit, **args):
5 |
6 | def insert_semicolon(point):
7 | self.view.insert(edit, point, ';')
8 |
9 | def is_semicolon(point):
10 | return self.view.substr(point) == ';'
11 |
12 | for region in self.view.sel():
13 | line = self.view.line(region)
14 | line_begin = line.begin()
15 | line_end = line.end()
16 |
17 | 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
18 | line_end -= 1
19 |
20 | if line_end == line_begin:
21 | continue
22 |
23 | if self.view.match_selector(line_end - 1, 'comment'):
24 | point = self.view.extract_scope(line_end - 1).a - 1
25 |
26 | if point < line_begin:
27 | continue
28 |
29 | while(self.view.substr(point).isspace() and point != line_begin): # go to the first character before the comment that isn't whitespace
30 | point -= 1
31 |
32 | if not self.view.substr(point).isspace() and not is_semicolon(point):
33 | insert_semicolon(point + 1)
34 |
35 | elif not is_semicolon(line_end - 1):
36 | insert_semicolon(line_end)
37 |
38 | if ('enter_new_line' in args and args['enter_new_line'] == 'true'):
39 | self.view.run_command("run_macro_file", {"file": "Packages/Default/Add Line.sublime-macro"}) # enter new line
40 |
--------------------------------------------------------------------------------
/Main.sublime-menu:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "caption": "Preferences",
4 | "mnemonic": "n",
5 | "id": "preferences",
6 | "children":
7 | [
8 | {
9 | "caption": "Package Settings",
10 | "mnemonic": "P",
11 | "id": "package-settings",
12 | "children":
13 | [
14 | {
15 | "caption": "AppendSemiColon",
16 | "children":
17 | [
18 | {
19 | "command": "open_file",
20 | "args": {
21 | "file": "${packages}/AppendSemiColon/Default (OSX).sublime-keymap",
22 | "platform": "OSX"
23 | },
24 | "caption": "Key Bindings – Default"
25 | },
26 | {
27 | "command": "open_file",
28 | "args": {
29 | "file": "${packages}/AppendSemiColon/Default.sublime-keymap",
30 | "platform": "Linux"
31 | },
32 | "caption": "Key Bindings – Default"
33 | },
34 | {
35 | "command": "open_file",
36 | "args": {
37 | "file": "${packages}/AppendSemiColon/Default.sublime-keymap",
38 | "platform": "Windows"
39 | },
40 | "caption": "Key Bindings – Default"
41 | },
42 | {
43 | "command": "open_file",
44 | "args": {
45 | "file": "${packages}/User/Default (OSX).sublime-keymap",
46 | "platform": "OSX"
47 | },
48 | "caption": "Key Bindings – User"
49 | },
50 | {
51 | "command": "open_file",
52 | "args": {
53 | "file": "${packages}/User/Default (Linux).sublime-keymap",
54 | "platform": "Linux"
55 | },
56 | "caption": "Key Bindings – User"
57 | },
58 | {
59 | "command": "open_file",
60 | "args": {
61 | "file": "${packages}/User/Default (Windows).sublime-keymap",
62 | "platform": "Windows"
63 | },
64 | "caption": "Key Bindings – User"
65 | }
66 | ]
67 | }
68 | ]
69 | }
70 | ]
71 | }
72 | ]
73 |
--------------------------------------------------------------------------------