Skip to content

Commit ddb0874

Browse files
authored
Merge pull request #22 from KM4YRI/master
Allow ''' in addition to """ for docstring quotes
2 parents bbaa1a5 + 164f302 commit ddb0874

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed

Default.sublime-keymap

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
],
77
"command": "docblockr_python",
88
"context": [
9-
{ "key": "selector", "operator": "equal", "operand": "string.quoted.double.block", "match_all": false },
10-
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
11-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
12-
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
13-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\")\\s*$", "match_all": true }
9+
{ "key": "selector", "operator": "equal", "operand": "string.quoted.double.block", "match_all": false },
10+
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
11+
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
12+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
13+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\"|''')\\s*$", "match_all": true }
1414
]
1515
},
1616
{
@@ -19,11 +19,11 @@
1919
],
2020
"command": "docblockr_python",
2121
"context": [
22-
{ "key": "selector", "operator": "equal", "operand": "string.quoted.double.block", "match_all": false },
23-
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
24-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
25-
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
26-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\")\\s*$", "match_all": true }
22+
{ "key": "selector", "operator": "equal", "operand": "string.quoted.double.block", "match_all": false },
23+
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
24+
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
25+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
26+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\"|''')\\s*$", "match_all": true }
2727
]
2828
},
2929
{
@@ -32,11 +32,11 @@
3232
],
3333
"command": "docblockr_python",
3434
"context": [
35-
{ "key": "selector", "operator": "equal", "operand": "string.quoted.double.block", "match_all": false },
36-
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
37-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
38-
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
39-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\")\\s*$", "match_all": true }
35+
{ "key": "selector", "operator": "equal", "operand": "string.quoted.double.block", "match_all": false },
36+
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
37+
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
38+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
39+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\"|''')\\s*$", "match_all": true }
4040
]
4141
},
4242

@@ -47,11 +47,11 @@
4747
],
4848
"command": "docblockr_python",
4949
"context": [
50-
{ "key": "selector", "operator": "equal", "operand": "comment.block.python", "match_all": false },
51-
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
52-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
53-
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
54-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\")\\s*$", "match_all": true }
50+
{ "key": "selector", "operator": "equal", "operand": "comment.block.python", "match_all": false },
51+
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
52+
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
53+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
54+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\"|''')\\s*$", "match_all": true }
5555
]
5656
},
5757
{
@@ -60,11 +60,11 @@
6060
],
6161
"command": "docblockr_python",
6262
"context": [
63-
{ "key": "selector", "operator": "equal", "operand": "comment.block.python", "match_all": false },
64-
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
65-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
66-
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
67-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\")\\s*$", "match_all": true }
63+
{ "key": "selector", "operator": "equal", "operand": "comment.block.python", "match_all": false },
64+
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
65+
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
66+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
67+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\"|''')\\s*$", "match_all": true }
6868
]
6969
},
7070
{
@@ -73,11 +73,11 @@
7373
],
7474
"command": "docblockr_python",
7575
"context": [
76-
{ "key": "selector", "operator": "equal", "operand": "comment.block.python", "match_all": false },
77-
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
78-
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
79-
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
80-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\")\\s*$", "match_all": true }
76+
{ "key": "selector", "operator": "equal", "operand": "comment.block.python", "match_all": false },
77+
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
78+
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
79+
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
80+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\"|''')\\s*$", "match_all": true }
8181
]
8282
},
8383

@@ -92,7 +92,7 @@
9292
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
9393
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
9494
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
95-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\")\\s*$", "match_all": true }
95+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\"|''')\\s*$", "match_all": true }
9696
]
9797
},
9898
{
@@ -105,7 +105,7 @@
105105
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
106106
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
107107
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
108-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\")\\s*$", "match_all": true }
108+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\"|''')\\s*$", "match_all": true }
109109
]
110110
},
111111
{
@@ -118,7 +118,7 @@
118118
{ "key": "setting.auto_indent", "operator": "equal", "operand": true, "match_all": true },
119119
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
120120
{ "key": "auto_complete_visible", "operator": "equal", "operand": false, "match_all": true },
121-
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\")\\s*$", "match_all": true }
121+
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^\\s*(\"\"\"|''')\\s*$", "match_all": true }
122122
]
123123
}
124124
]

commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def initialize(self, view):
121121
self.trailing_rgn = sublime.Region(position, view.line(position).end())
122122
self.trailing_string = view.substr(self.trailing_rgn).strip()
123123
# drop trailing '"""'
124-
self.trailing_string = escape(re.sub(r'\s*"""\s*$', '', self.trailing_string))
124+
self.trailing_string = escape(re.sub(r'\s*("""|\'\'\')\s*$', '', self.trailing_string))
125125

126126
self.parser = parser = get_parser(view)
127127

parsers/parser.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,12 @@ class PythonParser:
208208
209209
Contains the relevant parsing configuration to be able to handle Python style
210210
source files.
211-
212-
Variables:
213-
closing_string {String}
214211
"""
215212

216-
closing_string = '"""'
217-
218213
def __init__(self, view_settings=None):
219214
"""---."""
220215
self.view_settings = view_settings
216+
self.closing_string = '"""'
221217

222218
@classmethod
223219
def get_definition(self, view, position):
@@ -676,13 +672,22 @@ def is_docstring_closed(self, view, position):
676672
Returns:
677673
{Bool} True if the docstring is confirmed closed
678674
"""
675+
def set_closing_string(match):
676+
if match is not None:
677+
s = match.group(0).strip()[0:3]
678+
if s in ['"""', "'''"]:
679+
self.closing_string = s
680+
else:
681+
raise Exception('could not find closing string. Match was: {}'.format(match))
682+
679683
indentation_level = view.indentation_level(position)
680684

681685
# Check the current line first, and ignore if docstring is closed on this line
682686
line = view.substr(view.line(position))
683-
match = re.search(r'^\s*""".*"""\s*$', line)
687+
match = re.search(r'^\s*(""".*"""|\'\'\'.*\'\'\')\s*$', line)
684688

685689
if match is not None:
690+
set_closing_string(match)
686691
return False
687692

688693
for current_line in read_next_line(view, position):
@@ -701,7 +706,10 @@ def is_docstring_closed(self, view, position):
701706
break
702707

703708
# Line only contains whitespace and """
704-
if re.search(r'^\s*"""', current_line_string) is not None:
709+
match = re.search(r'^\s*("""|\'\'\')', current_line_string)
710+
if match is not None:
711+
set_closing_string(match)
705712
return True
706713

714+
set_closing_string(re.search(r'^\s*("""|\'\'\')', line))
707715
return False

0 commit comments

Comments
 (0)