8000 define magic for controlling autobalance · ipython/ipython@eef46e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit eef46e8

Browse files
committed
define magic for controlling autobalance
1 parent 86e13a0 commit eef46e8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

IPython/core/magics/auto.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,32 @@ def errorMessage() -> str:
142142
self.shell.autocall = self._magic_state.autocall_save = 1
143143

144144
print("Automatic calling is:", list(valid_modes.values())[self.shell.autocall])
145+
146+
@line_magic
147+
def autobalance(self, parameter_s=""):
148+
"""Automatically balance parenthesis, braces and brackets.
149+
150+
On single line cell, this mode add automatically needed symbol at the
151+
begin of the expression and the end of the line. If symbols need to
152+
be added at other place, there exists a ambiguity, and this
153+
transformation is not applied.
154+
155+
Without arguments toggles on/off. With arguments it sets the value, and
156+
you can use any of (case insensitive):
157+
158+
- on, 1, True: to activate
159+
160+
- off, 0, False: to deactivate.
161+
162+
When symbols are added, the rewritten line is displayed. See
163+
shell configuration `show_rewritten_input` to change this behavior.
164+
"""
165+
166+
arg = parameter_s.lower()
167+
if arg in ("on", "1", "true"):
168+
self.shell.autobalance = True
169+
elif arg in ("off", "0", "false"):
170+
self.shell.autobalance = False
171+
else:
172+
self.shell.autobalance = not self.shell.autobalance
173+
print("Autobalance " + ("enabled" if self.shell.autobalance else "disabled"))

0 commit comments

Comments
 (0)
0