##// 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 106 def auto_match():
107 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 121 focused_insert = (vi_insert_mode | emacs_insert_mode) & has_focus(DEFAULT_BUFFER)
110 122 _preceding_text_cache = {}
111 123 _following_text_cache = {}
112 124
113 125 def preceding_text(pattern):
114 try:
126 if pattern in _preceding_text_cache:
115 127 return _preceding_text_cache[pattern]
116 except KeyError:
117 pass
118 m = re.compile(pattern)
119 128
120 def _preceding_text():
121 app = get_app()
122 return bool(m.match(app.current_buffer.document.current_line_before_cursor))
129 if callable(pattern):
130
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 144 condition = Condition(_preceding_text)
125 145 _preceding_text_cache[pattern] = condition
@@ -173,6 +193,7 b' def create_ipython_shortcuts(shell):'
173 193 filter=focused_insert
174 194 & auto_match
175 195 & not_inside_unclosed_string
196 & preceding_text(lambda line: all_quotes_paired('"', line))
176 197 & following_text(r"[,)}\]]|$"),
177 198 )
178 199 def _(event):
@@ -184,6 +205,7 b' def create_ipython_shortcuts(shell):'
184 205 filter=focused_insert
185 206 & auto_match
186 207 & not_inside_unclosed_string
208 & preceding_text(lambda line: all_quotes_paired("'", line))
187 209 & following_text(r"[,)}\]]|$"),
188 210 )
189 211 def _(event):
General Comments 0
You need to be logged in to leave comments. Login now