Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3e26559

Browse files
committed
Reformat and move some mapping to global location.
1 parent 3c529d3 commit 3e26559

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

IPython/terminal/shortcuts/__init__.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def preceding_text(pattern: Union[str, Callable]):
165165
return _preceding_text_cache[pattern]
166166

167167
if callable(pattern):
168+
168169
def _preceding_text():
169170
app = get_app()
170171
before_cursor = app.current_buffer.document.current_line_before_cursor
@@ -215,12 +216,18 @@ def not_inside_unclosed_string():
215216
return not ('"' in s or "'" in s)
216217

217218
# auto match
218-
auto_match_parens = {"(": match.parenthesis, "[": match.brackets, "{": match.braces}
219-
for key, cmd in auto_match_parens.items():
219+
for key, cmd in match.auto_match_parens.items():
220220
kb.add(key, filter=focused_insert & auto_match & following_text(r"[,)}\]]|$"))(
221221
cmd
222222
)
223223

224+
# raw string
225+
for key, cmd in match.auto_match_parens_raw_string.items():
226+
kb.add(
227+
key,
228+
filter=focused_insert & auto_match & preceding_text(r".*(r|R)[\"'](-*)$"),
229+
)(cmd)
230+
224231
kb.add(
225232
'"',
226233
filter=focused_insert
@@ -255,18 +262,6 @@ def not_inside_unclosed_string():
255262
& preceding_text(r"^.*''$"),
256263
)(match.docstring_single_quotes)
257264

258-
# raw string
259-
auto_match_parens_raw_string = {
260-
"(": match.raw_string_parenthesis,
261-
"[": match.raw_string_bracket,
262-
"{": match.raw_string_braces,
263-
}
264-
for key, cmd in auto_match_parens_raw_string.items():
265-
kb.add(
266-
key,
267-
filter=focused_insert & auto_match & preceding_text(r".*(r|R)[\"'](-*)$"),
268-
)(cmd)
269-
270265
# just move cursor
271266
kb.add(")", filter=focused_insert & auto_match & following_text(r"^\)"))(
272267
match.skip_over

IPython/terminal/shortcuts/auto_match.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,11 @@ def delete_pair(event: KeyPressEvent):
9494
"""Delete auto-closed parenthesis"""
9595
event.current_buffer.delete()
9696
event.current_buffer.delete_before_cursor()
97+
98+
99+
auto_match_parens = {"(": parenthesis, "[": brackets, "{": braces}
100+
auto_match_parens_raw_string = {
101+
"(": raw_string_parenthesis,
102+
"[": raw_string_bracket,
103+
"{": raw_string_braces,
104+
}

0 commit comments

Comments
 (0)