|
| 1 | +if !exists('g:puppet_align_classes') |
| 2 | + let g:puppet_align_classes = 1 |
| 3 | +endif |
| 4 | + |
| 5 | +if exists(':AddTabularPipeline') && g:puppet_align_classes |
| 6 | + " The unction is filtering definition by '$' symbol, then applies tabular to |
| 7 | + " payload and join again. Source for this taken from |
| 8 | + " https://unix.stackexchange.com/questions/35787/indent-the-middle-of-multiple-lines |
| 9 | + function! AlignPuppetClass(lines) |
| 10 | + " List of payload, should contain '$' AND not contain '=>' |
| 11 | + let attributes = map(copy(a:lines), '(v:val =~ "[$]" && v:val !~ "=>") ? v:val : ""') |
| 12 | + " List of noise, may be without '$' or with '=>' |
| 13 | + let noise = map(copy(a:lines), '(v:val !~ "[$]" || v:val =~ "=>") ? v:val : ""') |
| 14 | + " Splitting only by first '$attribute' |
| 15 | + call tabular#TabularizeStrings(attributes, '^[^$]*\zs\s\+\$\w\+\>', 'l0l1') |
| 16 | + call map(a:lines, 'remove(attributes, 0) . remove(noise, 0)') |
| 17 | + endfunction |
| 18 | + |
| 19 | + " The class definition could be interrupted with enum's multiline, selectors |
| 20 | + " or whatever else, so tabular will search for any of `${['",#` symbols and |
| 21 | + " pass them into AlignPuppetClass function |
| 22 | + au FileType puppet AddTabularPipeline! puppet_class /[${['",#]/ AlignPuppetClass(a:lines) |
| 23 | + au FileType puppet inoremap <buffer> <silent> ,<CR> ,<Esc>:Tabularize puppet_class<CR>o |
| 24 | + " A comma should be at the last position in the line that's why 'norm A' |
| 25 | + " is enough in this case |
| 26 | + au FileType puppet inoremap <buffer> <silent> ,, ,<Esc>:Tabularize puppet_class<CR>A |
| 27 | +endif |
0 commit comments