Show More
@@ -188,6 +188,15 b' class TerminalInteractiveShell(InteractiveShell):' | |||
|
188 | 188 | allow_none=True |
|
189 | 189 | ).tag(config=True) |
|
190 | 190 | |
|
191 | auto_match = Bool( | |
|
192 | False, | |
|
193 | help=""" | |
|
194 | Automatically add/delete closing bracket or quote when opening bracket or quote is entered/deleted. | |
|
195 | Brackets: (), [], {} | |
|
196 | Quotes: '', \"\" | |
|
197 | """, | |
|
198 | ).tag(config=True) | |
|
199 | ||
|
191 | 200 | mouse_support = Bool(False, |
|
192 | 201 | help="Enable mouse support in the prompt\n(Note: prevents selecting text with the mouse)" |
|
193 | 202 | ).tag(config=True) |
@@ -85,6 +85,10 b' def create_ipython_shortcuts(shell):' | |||
|
85 | 85 | |
|
86 | 86 | kb.add('f2', filter=has_focus(DEFAULT_BUFFER))(open_input_in_editor) |
|
87 | 87 | |
|
88 | @Condition | |
|
89 | def auto_match(): | |
|
90 | return shell.auto_match | |
|
91 | ||
|
88 | 92 | focused_insert = (vi_insert_mode | emacs_insert_mode) & has_focus(DEFAULT_BUFFER) |
|
89 | 93 | _preceding_text_cache = {} |
|
90 | 94 | _following_text_cache = {} |
@@ -120,27 +124,27 b' def create_ipython_shortcuts(shell):' | |||
|
120 | 124 | return condition |
|
121 | 125 | |
|
122 | 126 | # auto match |
|
123 | @kb.add("(", filter=focused_insert & following_text(r"[,)}\]]|$")) | |
|
127 | @kb.add("(", filter=focused_insert & auto_match & following_text(r"[,)}\]]|$")) | |
|
124 | 128 | def _(event): |
|
125 | 129 | event.current_buffer.insert_text("()") |
|
126 | 130 | event.current_buffer.cursor_left() |
|
127 | 131 | |
|
128 | @kb.add("[", filter=focused_insert & following_text(r"[,)}\]]|$")) | |
|
132 | @kb.add("[", filter=focused_insert & auto_match & following_text(r"[,)}\]]|$")) | |
|
129 | 133 | def _(event): |
|
130 | 134 | event.current_buffer.insert_text("[]") |
|
131 | 135 | event.current_buffer.cursor_left() |
|
132 | 136 | |
|
133 | @kb.add("{", filter=focused_insert & following_text(r"[,)}\]]|$")) | |
|
137 | @kb.add("{", filter=focused_insert & auto_match & following_text(r"[,)}\]]|$")) | |
|
134 | 138 | def _(event): |
|
135 | 139 | event.current_buffer.insert_text("{}") |
|
136 | 140 | event.current_buffer.cursor_left() |
|
137 | 141 | |
|
138 | @kb.add('"', filter=focused_insert & following_text(r"[,)}\]]|$")) | |
|
142 | @kb.add('"', filter=focused_insert & auto_match & following_text(r"[,)}\]]|$")) | |
|
139 | 143 | def _(event): |
|
140 | 144 | event.current_buffer.insert_text('""') |
|
141 | 145 | event.current_buffer.cursor_left() |
|
142 | 146 | |
|
143 | @kb.add("'", filter=focused_insert & following_text(r"[,)}\]]|$")) | |
|
147 | @kb.add("'", filter=focused_insert & auto_match & following_text(r"[,)}\]]|$")) | |
|
144 | 148 | def _(event): |
|
145 | 149 | event.current_buffer.insert_text("''") |
|
146 | 150 | event.current_buffer.cursor_left() |
@@ -187,33 +191,48 b' def create_ipython_shortcuts(shell):' | |||
|
187 | 191 | event.current_buffer.cursor_left() |
|
188 | 192 | |
|
189 | 193 | # just move cursor |
|
190 | @kb.add(")", filter=focused_insert & following_text(r"^\)")) | |
|
191 | @kb.add("]", filter=focused_insert & following_text(r"^\]")) | |
|
192 | @kb.add("}", filter=focused_insert & following_text(r"^\}")) | |
|
193 | @kb.add('"', filter=focused_insert & following_text('^"')) | |
|
194 | @kb.add("'", filter=focused_insert & following_text("^'")) | |
|
194 | @kb.add(")", filter=focused_insert & auto_match & following_text(r"^\)")) | |
|
195 | @kb.add("]", filter=focused_insert & auto_match & following_text(r"^\]")) | |
|
196 | @kb.add("}", filter=focused_insert & auto_match & following_text(r"^\}")) | |
|
197 | @kb.add('"', filter=focused_insert & auto_match & following_text('^"')) | |
|
198 | @kb.add("'", filter=focused_insert & auto_match & following_text("^'")) | |
|
195 | 199 | def _(event): |
|
196 | 200 | event.current_buffer.cursor_right() |
|
197 | 201 | |
|
198 | 202 | @kb.add( |
|
199 | 203 | "backspace", |
|
200 | filter=focused_insert & preceding_text(r".*\($") & following_text(r"^\)"), | |
|
204 | filter=focused_insert | |
|
205 | & preceding_text(r".*\($") | |
|
206 | & auto_match | |
|
207 | & following_text(r"^\)"), | |
|
201 | 208 | ) |
|
202 | 209 | @kb.add( |
|
203 | 210 | "backspace", |
|
204 | filter=focused_insert & preceding_text(r".*\[$") & following_text(r"^\]"), | |
|
211 | filter=focused_insert | |
|
212 | & preceding_text(r".*\[$") | |
|
213 | & auto_match | |
|
214 | & following_text(r"^\]"), | |
|
205 | 215 | ) |
|
206 | 216 | @kb.add( |
|
207 | 217 | "backspace", |
|
208 | filter=focused_insert & preceding_text(r".*\{$") & following_text(r"^\}"), | |
|
218 | filter=focused_insert | |
|
219 | & preceding_text(r".*\{$") | |
|
220 | & auto_match | |
|
221 | & following_text(r"^\}"), | |
|
209 | 222 | ) |
|
210 | 223 | @kb.add( |
|
211 | 224 | "backspace", |
|
212 | filter=focused_insert & preceding_text('.*"$') & following_text('^"'), | |
|
225 | filter=focused_insert | |
|
226 | & preceding_text('.*"$') | |
|
227 | & auto_match | |
|
228 | & following_text('^"'), | |
|
213 | 229 | ) |
|
214 | 230 | @kb.add( |
|
215 | 231 | "backspace", |
|
216 | filter=focused_insert & preceding_text(r".*'$") & following_text(r"^'"), | |
|
232 | filter=focused_insert | |
|
233 | & preceding_text(r".*'$") | |
|
234 | & auto_match | |
|
235 | & following_text(r"^'"), | |
|
217 | 236 | ) |
|
218 | 237 | def _(event): |
|
219 | 238 | event.current_buffer.delete() |
General Comments 0
You need to be logged in to leave comments.
Login now