code: def transpose_chars(event: E) -> None:
      """
      Emulate Emacs transpose-char behavior: at the beginning of the buffer,
      do nothing.  At the end of a line or buffer, swap the characters before
      the cursor.  Otherwise, move the cursor right, and then swap the
      characters before the cursor.
      """
      b = event.current_buffer
      p = b.cursor_position
      if p == 0:
          return
      elif p == len(b.text) or b.text[p] == "\n":
          b.swap_characters_before_cursor()
      else:
          b.cursor_position += b.document.get_cursor_right_position()
          b.swap_characters_before_cursor()
  
imports: from __future__ import annotations
  from typing import Callable, TypeVar, Union, cast
  from prompt_toolkit.document import Document
  from prompt_toolkit.enums import EditingMode
  from prompt_toolkit.key_binding.key_bindings import Binding, key_binding
  from prompt_toolkit.key_binding.key_processor import KeyPress, KeyPressEvent
  from prompt_toolkit.keys import Keys
  from prompt_toolkit.layout.controls import BufferControl
  from prompt_toolkit.search import SearchDirection
  from prompt_toolkit.selection import PasteMode
  from .completion import display_completions_like_readline, generate_completions
label_desc: Use image node_id 23 for calling a global function with example usage: transpose_chars(event) without return types