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