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