Edit Book: Fix group references causing errors when used in replace string in the normal mode search and replace

This commit is contained in:
Kovid Goyal 2017-01-05 22:09:45 +05:30
parent 1196db5f20
commit 41a40e73be

View File

@ -1215,6 +1215,21 @@ def get_search_regex(state):
return ans
def get_search_function(state):
ans = state['replace']
is_regex = state['mode'] != 'normal'
if not is_regex:
ans = regex.sub(r'\\([0-9g])', r'\\\\\1', ans)
if state['mode'] == 'function':
try:
return replace_functions()[ans]
except KeyError:
if not ans:
return Function('empty-function', '')
raise NoSuchFunction(ans)
return ans
def initialize_search_request(state, action, current_editor, current_editor_name, searchable_names):
editor = None
where = state['where']
@ -1255,18 +1270,6 @@ class NoSuchFunction(ValueError):
pass
def get_search_function(search):
ans = search['replace']
if search['mode'] == 'function':
try:
return replace_functions()[ans]
except KeyError:
if not ans:
return Function('empty-function', '')
raise NoSuchFunction(ans)
return ans
def show_function_debug_output(func):
if isinstance(func, Function):
val = func.debug_buf.getvalue().strip()