|
| 1 | +The built-in fish_indent knows how to format fish 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 | +You can format any buffer with fish_indent specifying the formatter explicitly. |
| 18 | + |
| 19 | + @clear |
| 20 | + % if test 42 -eq $truth; echo '42 is truth'; else; echo 'I do not know what to believe'; end |
| 21 | + |
| 22 | + :FormatCode fish_indent |
| 23 | + ! fish_indent .*2>.* |
| 24 | + $ if test 42 -eq $truth |
| 25 | + $ echo '42 is truth' |
| 26 | + $ else |
| 27 | + $ echo 'I do not know what to believe' |
| 28 | + $ end |
| 29 | + if test 42 -eq $truth |
| 30 | + echo '42 is truth' |
| 31 | + else |
| 32 | + echo 'I do not know what to believe' |
| 33 | + end |
| 34 | + @end |
| 35 | + |
| 36 | +The fish filetype will use the fish_indent formatter by default. |
| 37 | + |
| 38 | + @clear |
| 39 | + % function f; echo f; end |
| 40 | + |
| 41 | + :set filetype=fish |
| 42 | + :FormatCode |
| 43 | + ! fish_indent .*2>.* |
| 44 | + $ function f |
| 45 | + $ echo f |
| 46 | + $ end |
| 47 | + function f |
| 48 | + echo f |
| 49 | + end |
| 50 | + @end |
| 51 | + :set filetype= |
| 52 | + |
| 53 | +It can format specific line ranges of code using :FormatLines. |
| 54 | + |
| 55 | + @clear |
| 56 | + % function foo; echo "my name is:"; echo "foo"; end<CR> |
| 57 | + |function bar; echo "my name is:"; echo "bar"; end |
| 58 | + |
| 59 | + :1,2FormatLines fish_indent |
| 60 | + ! fish_indent .*2>.* |
| 61 | + $ function foo echo "my name is:" |
| 62 | + $ echo "my name is:" |
| 63 | + $ echo "foo" |
| 64 | + $ end |
| 65 | + $ function bar echo "my name is:"; echo "bar"; end |
| 66 | + function foo echo "my name is:" |
| 67 | + echo "my name is:" |
| 68 | + echo "foo" |
| 69 | + end |
| 70 | + function bar echo "my name is:"; echo "bar"; end |
| 71 | + @end |
| 72 | + |
| 73 | +Errors are reported. |
| 74 | + |
| 75 | + @clear |
| 76 | + % function f; |
| 77 | + :FormatCode fish_indent |
| 78 | + ! fish_indent .*2> (.*) |
| 79 | + $ echo test error >\1 (command) |
| 80 | + $ 1 (status) |
| 81 | + ~ test error |
| 82 | + function f; |
| 83 | + @end |
| 84 | + |
| 85 | +The name or path of the fish_indent executable can be configured via the |
| 86 | +fish_indent_executable flag if the default of "fish_indent" doesn't work. |
| 87 | + |
| 88 | + @clear |
| 89 | + :Glaive codefmt fish_indent_executable='my_fish_indent' |
| 90 | + % function f; |
| 91 | + :FormatCode fish_indent |
| 92 | + ! my_fish_indent .* |
| 93 | + $ function f |
| 94 | + function f |
| 95 | + @end |
| 96 | + :Glaive codefmt fish_indent_executable='fish_indent' |
0 commit comments