| 1 |
" black.vim |
| 2 |
" Author: Łukasz Langa |
| 3 |
" Created: Mon Mar 26 23:27:53 2018 -0700 |
| 4 |
" Requires: Vim Ver7.0+ |
| 5 |
" Version: 1.2 |
| 6 |
" |
| 7 |
" Documentation: |
| 8 |
" This plugin formats Python files. |
| 9 |
" |
| 10 |
" History: |
| 11 |
" 1.0: |
| 12 |
" - initial version |
| 13 |
" 1.1: |
| 14 |
" - restore cursor/window position after formatting |
| 15 |
" 1.2: |
| 16 |
" - use autoload script |
| 17 |
|
| 18 |
if exists("g:load_black") |
| 19 |
finish |
| 20 |
endif |
| 21 |
|
| 22 |
if v:version < 700 || !has('python3') |
| 23 |
func! __ERROR() |
| 24 |
let messages = [] |
| 25 |
|
| 26 |
if v:version < 700 |
| 27 |
call add(messages, "vim7.0+") |
| 28 |
endif |
| 29 |
if !has('python3') |
| 30 |
call add(messages, "Python 3.10 support") |
| 31 |
endif |
| 32 |
|
| 33 |
echo "The black.vim plugin requires" join(messages, " and ") |
| 34 |
endfunc |
| 35 |
command! Black :call __ERROR() |
| 36 |
command! BlackUpgrade :call __ERROR() |
| 37 |
command! BlackVersion :call __ERROR() |
| 38 |
finish |
| 39 |
endif |
| 40 |
|
| 41 |
let g:load_black = "py1.0" |
| 42 |
if !exists("g:black_virtualenv") |
| 43 |
if has("nvim") |
| 44 |
let g:black_virtualenv = "~/.local/share/nvim/black" |
| 45 |
else |
| 46 |
let g:black_virtualenv = "~/.vim/black" |
| 47 |
endif |
| 48 |
endif |
| 49 |
if !exists("g:black_fast") |
| 50 |
let g:black_fast = 0 |
| 51 |
endif |
| 52 |
if !exists("g:black_linelength") |
| 53 |
let g:black_linelength = 88 |
| 54 |
endif |
| 55 |
if !exists("g:black_skip_string_normalization") |
| 56 |
if exists("g:black_string_normalization") |
| 57 |
let g:black_skip_string_normalization = !g:black_string_normalization |
| 58 |
else |
| 59 |
let g:black_skip_string_normalization = 0 |
| 60 |
endif |
| 61 |
endif |
| 62 |
if !exists("g:black_skip_magic_trailing_comma") |
| 63 |
if exists("g:black_magic_trailing_comma") |
| 64 |
let g:black_skip_magic_trailing_comma = !g:black_magic_trailing_comma |
| 65 |
else |
| 66 |
let g:black_skip_magic_trailing_comma = 0 |
| 67 |
endif |
| 68 |
endif |
| 69 |
if !exists("g:black_quiet") |
| 70 |
let g:black_quiet = 0 |
| 71 |
endif |
| 72 |
if !exists("g:black_target_version") |
| 73 |
let g:black_target_version = "" |
| 74 |
endif |
| 75 |
if !exists("g:black_use_virtualenv") |
| 76 |
let g:black_use_virtualenv = 1 |
| 77 |
endif |
| 78 |
if !exists("g:black_preview") |
| 79 |
let g:black_preview = 0 |
| 80 |
endif |
| 81 |
|
| 82 |
function BlackComplete(ArgLead, CmdLine, CursorPos) |
| 83 |
return [ |
| 84 |
\ 'target_version=py310', |
| 85 |
\ 'target_version=py311', |
| 86 |
\ 'target_version=py312', |
| 87 |
\ 'target_version=py313', |
| 88 |
\ 'target_version=py314', |
| 89 |
\ ] |
| 90 |
endfunction |
| 91 |
|
| 92 |
command! -nargs=* -complete=customlist,BlackComplete Black :call black#Black(<f-args>) |
| 93 |
command! BlackUpgrade :call black#BlackUpgrade() |
| 94 |
command! BlackVersion :call black#BlackVersion() |