|
| 1 | +The built-in black formatter knows how to format python code. |
| 2 | +If you aren't familiar with basic codefmt usage yet, see main.vroom first. |
| 3 | + |
| 4 | +We'll set up codefmt and configure the vroom environment, then jump into some |
| 5 | +examples. |
| 6 | + |
| 7 | + :source $VROOMDIR/setupvroom.vim |
| 8 | + |
| 9 | + :let g:repeat_calls = [] |
| 10 | + :function FakeRepeat(...)<CR> |
| 11 | + | call add(g:repeat_calls, a:000)<CR> |
| 12 | + :endfunction |
| 13 | + :call maktaba#test#Override('repeat#set', 'FakeRepeat') |
| 14 | + |
| 15 | + :call codefmt#SetWhetherToPerformIsAvailableChecksForTesting(0) |
| 16 | + |
| 17 | + |
| 18 | +The black formatter expects the black executable to be installed on your |
| 19 | +system. |
| 20 | + |
| 21 | + % f() |
| 22 | + :FormatCode black |
| 23 | + ! black .* |
| 24 | + $ f() |
| 25 | + |
| 26 | +The name or path of the black executable can be configured via the |
| 27 | +black_executable flag if the default of "black" doesn't work. |
| 28 | + |
| 29 | + :Glaive codefmt black_executable='blackpy3' |
| 30 | + :FormatCode black |
| 31 | + ! blackpy3 .* |
| 32 | + $ f() |
| 33 | + :Glaive codefmt black_executable='black' |
| 34 | + |
| 35 | + |
| 36 | +You can format any buffer with black specifying the formatter explicitly. |
| 37 | +Here's an example: |
| 38 | + |
| 39 | + @clear |
| 40 | + % if True: pass |
| 41 | + |
| 42 | + :FormatCode black |
| 43 | + ! black .* |
| 44 | + $ if True: |
| 45 | + $ pass |
| 46 | + if True: |
| 47 | + pass |
| 48 | + @end |
| 49 | + |
| 50 | +Here's a second example: |
| 51 | + |
| 52 | + @clear |
| 53 | + % some_tuple=( 1,2, 3,'a' );<CR> |
| 54 | + |if bar : bar+=1; bar=bar* bar<CR> |
| 55 | + |else: bar-=1; |
| 56 | + |
| 57 | + :FormatCode black |
| 58 | + ! black .* |
| 59 | + $ some_tuple = (1, 2, 3, "a"); |
| 60 | + $ if bar: |
| 61 | + $ bar += 1 |
| 62 | + $ bar = bar * bar |
| 63 | + $ else: |
| 64 | + $ bar -= 1 |
| 65 | + some_tuple = (1, 2, 3, "a"); |
| 66 | + if bar: |
| 67 | + bar += 1 |
| 68 | + bar = bar * bar |
| 69 | + else: |
| 70 | + bar -= 1 |
| 71 | + @end |
0 commit comments