code: def preceding_text(pattern: Union[str, Callable]):
      if pattern in _preceding_text_cache:
          return _preceding_text_cache[pattern]
  
      if callable(pattern):
  
          def _preceding_text():
              app = get_app()
              before_cursor = (
                  app.current_buffer.document.current_line_before_cursor
              )
              # mypy can't infer if(callable): https://github.com/python/mypy/issues/3603
              return bool(pattern(before_cursor))  # type: ignore[operator]
  
      else:
          m = re.compile(pattern)
  
          def _preceding_text():
              app = get_app()
              before_cursor = (
                  app.current_buffer.document.current_line_before_cursor
              )
              return bool(m.match(before_cursor))
  
          _preceding_text.__name__ = f"preceding_text({pattern!r})"
  
      condition = Condition(_preceding_text)
      _preceding_text_cache[pattern] = condition
      return condition
  
imports: import ast
  import re
  import signal
  import sys
  from typing import Callable, Dict, Union
  from prompt_toolkit.application.current import get_app
  from prompt_toolkit.enums import DEFAULT_BUFFER, SEARCH_BUFFER
  from prompt_toolkit.key_binding import KeyPressEvent
  from prompt_toolkit.filters import Condition, Filter, emacs_insert_mode, has_completions
  from prompt_toolkit.filters import has_focus
  from prompt_toolkit.filters import Always, Never, has_selection, has_suggestion, vi_insert_mode, vi_mode
  from prompt_toolkit.layout.layout import FocusableElement
  from IPython.core.getipython import get_ipython
  from IPython.core.guarded_eval import _find_dunder, BINARY_OP_DUNDERS, UNARY_OP_DUNDERS
  from IPython.terminal.shortcuts import auto_suggest
  from IPython.utils.decorators import undoc
label_desc: Use image node_id 10 for calling a global function with example usage: preceding_text(pattern) and returns: condition, _preceding_text_cache, bool, bool