##// END OF EJS Templates
Merge pull request #13708 from suzaku/improve-automatch-perf...
Matthias Bussonnier -
r27784:7dbb26a6 merge
parent child Browse files
Show More
@@ -106,20 +106,40 b' 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
122 return bool(m.match(app.current_buffer.document.current_line_before_cursor))
131 def _preceding_text():
132 app = get_app()
133 before_cursor = app.current_buffer.document.current_line_before_cursor
134 return bool(pattern(before_cursor))
135
136 else:
137 m = re.compile(pattern)
138
139 def _preceding_text():
140 app = get_app()
141 before_cursor = app.current_buffer.document.current_line_before_cursor
142 return bool(m.match(before_cursor))
123
143
124 condition = Condition(_preceding_text)
144 condition = Condition(_preceding_text)
125 _preceding_text_cache[pattern] = condition
145 _preceding_text_cache[pattern] = condition
@@ -173,6 +193,7 b' def create_ipython_shortcuts(shell):'
173 filter=focused_insert
193 filter=focused_insert
174 & auto_match
194 & auto_match
175 & not_inside_unclosed_string
195 & not_inside_unclosed_string
196 & preceding_text(lambda line: all_quotes_paired('"', line))
176 & following_text(r"[,)}\]]|$"),
197 & following_text(r"[,)}\]]|$"),
177 )
198 )
178 def _(event):
199 def _(event):
@@ -184,6 +205,7 b' def create_ipython_shortcuts(shell):'
184 filter=focused_insert
205 filter=focused_insert
185 & auto_match
206 & auto_match
186 & not_inside_unclosed_string
207 & not_inside_unclosed_string
208 & preceding_text(lambda line: all_quotes_paired("'", line))
187 & following_text(r"[,)}\]]|$"),
209 & following_text(r"[,)}\]]|$"),
188 )
210 )
189 def _(event):
211 def _(event):
General Comments 0
You need to be logged in to leave comments. Login now