Skip to content

Commit

Permalink
fix vim plugin for 19.3b0 (#755) (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlv authored and JelleZijlstra committed Mar 17, 2019
1 parent ba64fc7 commit a2f6706
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions plugin/black.vim
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,14 @@ if _initialize_black_env():
def Black():
start = time.time()
fast = bool(int(vim.eval("g:black_fast")))
line_length = int(vim.eval("g:black_linelength"))
mode = black.FileMode.AUTO_DETECT
if bool(int(vim.eval("g:black_skip_string_normalization"))):
mode |= black.FileMode.NO_STRING_NORMALIZATION
if vim.current.buffer.name.endswith('.pyi'):
mode |= black.FileMode.PYI
mode = black.FileMode(
line_length=int(vim.eval("g:black_linelength")),
string_normalization=not bool(int(vim.eval("g:black_skip_string_normalization"))),
is_pyi=vim.current.buffer.name.endswith('.pyi'),
)
buffer_str = '\n'.join(vim.current.buffer) + '\n'
try:
new_buffer_str = black.format_file_contents(buffer_str, line_length=line_length, fast=fast, mode=mode)
new_buffer_str = black.format_file_contents(buffer_str, fast=fast, mode=mode)
except black.NothingChanged:
print(f'Already well formatted, good job. (took {time.time() - start:.4f}s)')
except Exception as exc:
Expand Down

0 comments on commit a2f6706

Please sign in to comment.