##// END OF EJS Templates
autoreformat
Matthias Bussonnier -
Show More
@@ -89,7 +89,6 b' def create_ipython_shortcuts(shell):'
89 89 _preceding_text_cache = {}
90 90 _following_text_cache = {}
91 91
92
93 92 def preceding_text(pattern):
94 93 try:
95 94 return _preceding_text_cache[pattern]
@@ -105,7 +104,6 b' def create_ipython_shortcuts(shell):'
105 104 _preceding_text_cache[pattern] = condition
106 105 return condition
107 106
108
109 107 def following_text(pattern):
110 108 try:
111 109 return _following_text_cache[pattern]
@@ -121,19 +119,18 b' def create_ipython_shortcuts(shell):'
121 119 _following_text_cache[pattern] = condition
122 120 return condition
123 121
124
125 122 # auto match
126 @kb.add('(', filter=focused_insert & following_text(r"[,)}\]]|$"))
123 @kb.add("(", filter=focused_insert & following_text(r"[,)}\]]|$"))
127 124 def _(event):
128 125 event.current_buffer.insert_text("()")
129 126 event.current_buffer.cursor_left()
130 127
131 @kb.add('[', filter=focused_insert & following_text(r"[,)}\]]|$"))
128 @kb.add("[", filter=focused_insert & following_text(r"[,)}\]]|$"))
132 129 def _(event):
133 130 event.current_buffer.insert_text("[]")
134 131 event.current_buffer.cursor_left()
135 132
136 @kb.add('{', filter=focused_insert & following_text(r"[,)}\]]|$"))
133 @kb.add("{", filter=focused_insert & following_text(r"[,)}\]]|$"))
137 134 def _(event):
138 135 event.current_buffer.insert_text("{}")
139 136 event.current_buffer.cursor_left()
@@ -149,23 +146,32 b' def create_ipython_shortcuts(shell):'
149 146 event.current_buffer.cursor_left()
150 147
151 148 # raw string
152 @kb.add('(', filter=focused_insert & preceding_text(r".*(r|R)[\"'](-*)$"))
149 @kb.add("(", filter=focused_insert & preceding_text(r".*(r|R)[\"'](-*)$"))
153 150 def _(event):
154 matches = re.match(r".*(r|R)[\"'](-*)", event.current_buffer.document.current_line_before_cursor)
151 matches = re.match(
152 r".*(r|R)[\"'](-*)",
153 event.current_buffer.document.current_line_before_cursor,
154 )
155 155 dashes = matches.group(2) or ""
156 156 event.current_buffer.insert_text("()" + dashes)
157 157 event.current_buffer.cursor_left(len(dashes) + 1)
158 158
159 @kb.add('[', filter=focused_insert & preceding_text(r".*(r|R)[\"'](-*)$"))
159 @kb.add("[", filter=focused_insert & preceding_text(r".*(r|R)[\"'](-*)$"))
160 160 def _(event):
161 matches = re.match(r".*(r|R)[\"'](-*)", event.current_buffer.document.current_line_before_cursor)
161 matches = re.match(
162 r".*(r|R)[\"'](-*)",
163 event.current_buffer.document.current_line_before_cursor,
164 )
162 165 dashes = matches.group(2) or ""
163 166 event.current_buffer.insert_text("[]" + dashes)
164 167 event.current_buffer.cursor_left(len(dashes) + 1)
165 168
166 @kb.add('{', filter=focused_insert & preceding_text(r".*(r|R)[\"'](-*)$"))
169 @kb.add("{", filter=focused_insert & preceding_text(r".*(r|R)[\"'](-*)$"))
167 170 def _(event):
168 matches = re.match(r".*(r|R)[\"'](-*)", event.current_buffer.document.current_line_before_cursor)
171 matches = re.match(
172 r".*(r|R)[\"'](-*)",
173 event.current_buffer.document.current_line_before_cursor,
174 )
169 175 dashes = matches.group(2) or ""
170 176 event.current_buffer.insert_text("{}" + dashes)
171 177 event.current_buffer.cursor_left(len(dashes) + 1)
@@ -181,30 +187,48 b' def create_ipython_shortcuts(shell):'
181 187 event.current_buffer.cursor_left()
182 188
183 189 # just move cursor
184 @kb.add(')', filter=focused_insert & following_text(r"^\)"))
185 @kb.add(']', filter=focused_insert & following_text(r"^\]"))
186 @kb.add('}', filter=focused_insert & following_text(r"^\}"))
187 @kb.add('"', filter=focused_insert & following_text("^\""))
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('^"'))
188 194 @kb.add("'", filter=focused_insert & following_text("^'"))
189 195 def _(event):
190 196 event.current_buffer.cursor_right()
191 197
192 @kb.add('backspace', filter=focused_insert & preceding_text(r".*\($") & following_text(r"^\)"))
193 @kb.add('backspace', filter=focused_insert & preceding_text(r".*\[$") & following_text(r"^\]"))
194 @kb.add('backspace', filter=focused_insert & preceding_text(r".*\{$") & following_text(r"^\}"))
195 @kb.add('backspace', filter=focused_insert & preceding_text('.*"$') & following_text('^"'))
196 @kb.add('backspace', filter=focused_insert & preceding_text(r".*'$") & following_text(r"^'"))
198 @kb.add(
199 "backspace",
200 filter=focused_insert & preceding_text(r".*\($") & following_text(r"^\)"),
201 )
202 @kb.add(
203 "backspace",
204 filter=focused_insert & preceding_text(r".*\[$") & following_text(r"^\]"),
205 )
206 @kb.add(
207 "backspace",
208 filter=focused_insert & preceding_text(r".*\{$") & following_text(r"^\}"),
209 )
210 @kb.add(
211 "backspace",
212 filter=focused_insert & preceding_text('.*"$') & following_text('^"'),
213 )
214 @kb.add(
215 "backspace",
216 filter=focused_insert & preceding_text(r".*'$") & following_text(r"^'"),
217 )
197 218 def _(event):
198 219 event.current_buffer.delete()
199 220 event.current_buffer.delete_before_cursor()
200 221
201
202 if shell.display_completions == 'readlinelike':
203 kb.add('c-i', filter=(has_focus(DEFAULT_BUFFER)
204 & ~has_selection
205 & insert_mode
206 & ~cursor_in_leading_ws
207 ))(display_completions_like_readline)
222 if shell.display_completions == "readlinelike":
223 kb.add(
224 "c-i",
225 filter=(
226 has_focus(DEFAULT_BUFFER)
227 & ~has_selection
228 & insert_mode
229 & ~cursor_in_leading_ws
230 ),
231 )(display_completions_like_readline)
208 232
209 233 if sys.platform == "win32":
210 234 kb.add("c-v", filter=(has_focus(DEFAULT_BUFFER) & ~vi_mode))(win_paste)
General Comments 0
You need to be logged in to leave comments. Login now