@@ -142,3 +142,32 @@ def errorMessage() -> str:
142
142
self .shell .autocall = self ._magic_state .autocall_save = 1
143
143
144
144
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