MCPcopy Create free account
hub / github.com/bpython/bpython / UnconfiguredEdits

Class UnconfiguredEdits

bpython/curtsiesfrontend/manual_readline.py:90–133  ·  view source on GitHub ↗

Maps key to edit functions, and bins them by what parameters they take. Only functions with specific signatures can be added: * func(**kwargs) -> cursor_offset, line * func(**kwargs) -> cursor_offset, line, cut_buffer where kwargs are in among the keys of Edits.default_k

Source from the content-addressed store, hash-verified

88
89
90class UnconfiguredEdits(AbstractEdits):
91 """Maps key to edit functions, and bins them by what parameters they take.
92
93 Only functions with specific signatures can be added:
94 * func(**kwargs) -> cursor_offset, line
95 * func(**kwargs) -> cursor_offset, line, cut_buffer
96 where kwargs are in among the keys of Edits.default_kwargs
97 These functions will be run to determine their return type, so no side
98 effects!
99
100 More concrete Edits instances can be created by applying a config with
101 Edits.mapping_with_config() - this creates a new Edits instance
102 that uses a config file to assign config_attr bindings.
103
104 Keys can't be added twice, config attributes can't be added twice.
105 """
106
107 def mapping_with_config(self, config, key_dispatch):
108 """Creates a new mapping object by applying a config object"""
109 return ConfiguredEdits(
110 self.simple_edits,
111 self.cut_buffer_edits,
112 self.awaiting_config,
113 config,
114 key_dispatch,
115 )
116
117 def on(self, key=None, config=None):
118 if not ((key is None) ^ (config is None)):
119 raise ValueError("Must use exactly one of key, config")
120 if key is not None:
121
122 def add_to_keybinds(func):
123 self.add(key, func)
124 return func
125
126 return add_to_keybinds
127 else:
128
129 def add_to_config(func):
130 self.add_config_attr(config, func)
131 return func
132
133 return add_to_config
134
135
136class ConfiguredEdits(AbstractEdits):

Callers 2

setUpMethod · 0.90
manual_readline.pyFile · 0.85

Calls

no outgoing calls

Tested by 1

setUpMethod · 0.72