diff --git a/src/calibre/gui2/tweak_book/search.py b/src/calibre/gui2/tweak_book/search.py index fb8713b433..b835ed4b4d 100644 --- a/src/calibre/gui2/tweak_book/search.py +++ b/src/calibre/gui2/tweak_book/search.py @@ -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()