##// END OF EJS Templates
Merge pull request #13528 from algmyr/master...
Matthias Bussonnier -
r27537:935dedb4 merge
parent child Browse files
Show More
@@ -116,6 +116,22 b' def black_reformat_handler(text_before_cursor):'
116 116 return formatted_text
117 117
118 118
119 def yapf_reformat_handler(text_before_cursor):
120 from yapf.yapflib import file_resources
121 from yapf.yapflib import yapf_api
122
123 style_config = file_resources.GetDefaultStyleForDir(os.getcwd())
124 formatted_text, was_formatted = yapf_api.FormatCode(
125 text_before_cursor, style_config=style_config
126 )
127 if was_formatted:
128 if not text_before_cursor.endswith("\n") and formatted_text.endswith("\n"):
129 formatted_text = formatted_text[:-1]
130 return formatted_text
131 else:
132 return text_before_cursor
133
134
119 135 class TerminalInteractiveShell(InteractiveShell):
120 136 mime_renderers = Dict().tag(config=True)
121 137
@@ -185,7 +201,7 b' class TerminalInteractiveShell(InteractiveShell):'
185 201
186 202 autoformatter = Unicode(
187 203 "black",
188 help="Autoformatter to reformat Terminal code. Can be `'black'` or `None`",
204 help="Autoformatter to reformat Terminal code. Can be `'black'`, `'yapf'` or `None`",
189 205 allow_none=True
190 206 ).tag(config=True)
191 207
@@ -232,6 +248,8 b' class TerminalInteractiveShell(InteractiveShell):'
232 248 self.reformat_handler = lambda x:x
233 249 elif formatter == 'black':
234 250 self.reformat_handler = black_reformat_handler
251 elif formatter == "yapf":
252 self.reformat_handler = yapf_reformat_handler
235 253 else:
236 254 raise ValueError
237 255
General Comments 0
You need to be logged in to leave comments. Login now