|
| 1 | +These examples demonstrate specific cursor positioning behavior related to the |
| 2 | +overall clang-format formatting demonstrated in clangformat.vroom. See the |
| 3 | +examples in that file first if you're unfamiliar with formatting behavior. |
| 4 | + |
| 5 | +We'll set up codefmt and configure the vroom environment, then jump into some |
| 6 | +examples. |
| 7 | + |
| 8 | + :source $VROOMDIR/setupvroom.vim |
| 9 | + |
| 10 | + :let g:repeat_calls = [] |
| 11 | + :function FakeRepeat(...)<CR> |
| 12 | + | call add(g:repeat_calls, a:000)<CR> |
| 13 | + :endfunction |
| 14 | + :call maktaba#test#Override('repeat#set', 'FakeRepeat') |
| 15 | + |
| 16 | + :call codefmt#SetWhetherToPerformIsAvailableChecksForTesting(0) |
| 17 | + |
| 18 | + |
| 19 | +It will keep the cursor in the correct position when formatting code (assuming |
| 20 | +that clang-format has a version >= 3.4). |
| 21 | + |
| 22 | + :Glaive codefmt clang_format_executable='clang-format-3.3' |
| 23 | + % int f() { int i = 1; return 1234567890; } |
| 24 | + |
| 25 | + :FormatCode clang-format |
| 26 | + ! clang-format-3.3 --version .* |
| 27 | + $ clang-format version 3.3.0 (tags/testing) |
| 28 | + ! clang-format-3.3 -style file -lines 1:1 2>.* |
| 29 | + $ int f() { |
| 30 | + $ int i = 1; |
| 31 | + $ return 1234567890; |
| 32 | + $ } |
| 33 | + int f() { |
| 34 | + int i = 1; |
| 35 | + return 1234567890; |
| 36 | + } |
| 37 | + @end |
| 38 | + |
| 39 | + :Glaive codefmt clang_format_executable='clang-format' |
| 40 | + @clear |
| 41 | + % int f() { int i = 1; return 1234567890; } |
| 42 | + |
| 43 | + :goto 33 |
| 44 | + :echomsg getline('.')[col('.')-1] |
| 45 | + ~ 5 |
| 46 | + :FormatCode clang-format |
| 47 | + ! clang-format --version .* |
| 48 | + $ clang-format version 3.7.0 (tags/testing) |
| 49 | + ! clang-format -style file .* -cursor 32 .*2>.* |
| 50 | + $ { "Cursor": 36 } |
| 51 | + $ int f() { |
| 52 | + $ int i = 1; |
| 53 | + $ return 1234567890; |
| 54 | + $ } |
| 55 | + :echomsg getline('.')[col('.')-1] |
| 56 | + ~ 5 |
| 57 | + |
| 58 | +Some vim builds that support textprops had a bug with determining cursor |
| 59 | +position (see https://github.com/vim/vim/issues/5930), but codefmt's cursor |
| 60 | +positioning should still maintain cursor position correctly for those cases. |
| 61 | + |
| 62 | +Note: The following test scenario will skip the relevant textprops setup and run |
| 63 | +harmlessly without doing any interesting verification in vim versions that don't |
| 64 | +support textprops. |
| 65 | + |
| 66 | + @clear |
| 67 | + :function PlaceTextpropIfSupported(lnum, col, length) abort<CR> |
| 68 | + | if !has('textprops')<CR> |
| 69 | + | return<CR> |
| 70 | + | endif<CR> |
| 71 | + | call prop_type_add('keyword', {})<CR> |
| 72 | + | call prop_add(a:lnum, a:col, {'length': a:length, 'type': 'keyword'})<CR> |
| 73 | + |endfunction |
| 74 | + % int f() {<CR> |
| 75 | + | int i=1;<CR> |
| 76 | + | return 1234567890; }<CR> |
| 77 | + :call PlaceTextpropIfSupported(1, 1, 3) |
| 78 | + :call cursor(2, 10) |
| 79 | + :echomsg getline('.')[col('.')-1] |
| 80 | + ~ = |
| 81 | + :FormatCode clang-format |
| 82 | + ! clang-format -style file .* -cursor 23 .*2>.* |
| 83 | + $ { "Cursor": 18 } |
| 84 | + $ int f() { |
| 85 | + $ int i = 1; |
| 86 | + $ return 1234567890; |
| 87 | + $ } |
| 88 | + :echomsg getline('.')[col('.')-1] |
| 89 | + ~ = |
| 90 | + |
0 commit comments