emacs_state.py 884 B

123456789101112131415161718192021222324252627282930313233343536
  1. from __future__ import annotations
  2. from .key_processor import KeyPress
  3. __all__ = [
  4. "EmacsState",
  5. ]
  6. class EmacsState:
  7. """
  8. Mutable class to hold Emacs specific state.
  9. """
  10. def __init__(self) -> None:
  11. # Simple macro recording. (Like Readline does.)
  12. # (For Emacs mode.)
  13. self.macro: list[KeyPress] | None = []
  14. self.current_recording: list[KeyPress] | None = None
  15. def reset(self) -> None:
  16. self.current_recording = None
  17. @property
  18. def is_recording(self) -> bool:
  19. "Tell whether we are recording a macro."
  20. return self.current_recording is not None
  21. def start_macro(self) -> None:
  22. "Start recording macro."
  23. self.current_recording = []
  24. def end_macro(self) -> None:
  25. "End recording macro."
  26. self.macro = self.current_recording
  27. self.current_recording = None