Show More
@@ -106,20 +106,37 def create_ipython_shortcuts(shell): | |||||
106 | def auto_match(): |
|
106 | def auto_match(): | |
107 | return shell.auto_match |
|
107 | return shell.auto_match | |
108 |
|
108 | |||
|
109 | def all_quotes_paired(quote, buf): | |||
|
110 | paired = True | |||
|
111 | i = 0 | |||
|
112 | while i < len(buf): | |||
|
113 | c = buf[i] | |||
|
114 | if c == quote: | |||
|
115 | paired = not paired | |||
|
116 | elif c == '\\': | |||
|
117 | i += 1 | |||
|
118 | i += 1 | |||
|
119 | return paired | |||
|
120 | ||||
109 | focused_insert = (vi_insert_mode | emacs_insert_mode) & has_focus(DEFAULT_BUFFER) |
|
121 | focused_insert = (vi_insert_mode | emacs_insert_mode) & has_focus(DEFAULT_BUFFER) | |
110 | _preceding_text_cache = {} |
|
122 | _preceding_text_cache = {} | |
111 | _following_text_cache = {} |
|
123 | _following_text_cache = {} | |
112 |
|
124 | |||
113 | def preceding_text(pattern): |
|
125 | def preceding_text(pattern): | |
114 | try: |
|
126 | if pattern in _preceding_text_cache: | |
115 | return _preceding_text_cache[pattern] |
|
127 | return _preceding_text_cache[pattern] | |
116 | except KeyError: |
|
|||
117 | pass |
|
|||
118 | m = re.compile(pattern) |
|
|||
119 |
|
128 | |||
120 | def _preceding_text(): |
|
129 | if callable(pattern): | |
121 | app = get_app() |
|
130 | def _preceding_text(): | |
122 | return bool(m.match(app.current_buffer.document.current_line_before_cursor)) |
|
131 | app = get_app() | |
|
132 | before_cursor = app.current_buffer.document.current_line_before_cursor | |||
|
133 | return bool(pattern(before_cursor)) | |||
|
134 | else: | |||
|
135 | m = re.compile(pattern) | |||
|
136 | ||||
|
137 | def _preceding_text(): | |||
|
138 | app = get_app() | |||
|
139 | return bool(m.match(app.current_buffer.document.current_line_before_cursor)) | |||
123 |
|
140 | |||
124 | condition = Condition(_preceding_text) |
|
141 | condition = Condition(_preceding_text) | |
125 | _preceding_text_cache[pattern] = condition |
|
142 | _preceding_text_cache[pattern] = condition | |
@@ -173,6 +190,7 def create_ipython_shortcuts(shell): | |||||
173 | filter=focused_insert |
|
190 | filter=focused_insert | |
174 | & auto_match |
|
191 | & auto_match | |
175 | & not_inside_unclosed_string |
|
192 | & not_inside_unclosed_string | |
|
193 | & preceding_text(lambda line: all_quotes_paired('"', line)) | |||
176 | & following_text(r"[,)}\]]|$"), |
|
194 | & following_text(r"[,)}\]]|$"), | |
177 | ) |
|
195 | ) | |
178 | def _(event): |
|
196 | def _(event): | |
@@ -184,6 +202,7 def create_ipython_shortcuts(shell): | |||||
184 | filter=focused_insert |
|
202 | filter=focused_insert | |
185 | & auto_match |
|
203 | & auto_match | |
186 | & not_inside_unclosed_string |
|
204 | & not_inside_unclosed_string | |
|
205 | & preceding_text(lambda line: all_quotes_paired("'", line)) | |||
187 | & following_text(r"[,)}\]]|$"), |
|
206 | & following_text(r"[,)}\]]|$"), | |
188 | ) |
|
207 | ) | |
189 | def _(event): |
|
208 | def _(event): |
General Comments 0
You need to be logged in to leave comments.
Login now