|
| 1 | +function! s:dealWithFunctionDeclaration(container) abort " {{{ |
| 2 | + if a:container.suffix !~ '\v^\)' |
| 3 | + return 0 |
| 4 | + endif |
| 5 | + |
| 6 | + " Take anonymous and arrow functions into account |
| 7 | + if a:container.prefix !~? '\v(function|fn)\s*\S*\s*\($' |
| 8 | + return 0 |
| 9 | + endif |
| 10 | + |
| 11 | + return 1 |
| 12 | +endfunction " }}} |
| 13 | + |
| 14 | +function! argwrap#hooks#filetype#php#200_remove_tail_comma_function_declaration#pre_wrap(range, container, arguments) abort " {{{ |
| 15 | + " Do nothing but prevent the file to be loaded more than once |
| 16 | + " When calling an autoload function that is not define the script that |
| 17 | + " should contain it is sourced every time the function is called |
| 18 | +endfunction " }}} |
| 19 | + |
| 20 | +function! argwrap#hooks#filetype#php#200_remove_tail_comma_function_declaration#pre_unwrap(range, container, arguments) abort " {{{ |
| 21 | + " Do nothing but prevent the file to be loaded more than once |
| 22 | + " When calling an autoload function that is not define the script that |
| 23 | + " should contain it is sourced every time the function is called |
| 24 | +endfunction " }}} |
| 25 | + |
| 26 | +function! argwrap#hooks#filetype#php#200_remove_tail_comma_function_declaration#post_wrap(range, container, arguments) abort " {{{ |
| 27 | + " Don't do anything if the user want a tail comma for function declaration |
| 28 | + if 0 == argwrap#getSetting('php_remove_tail_comma_function_declaration') |
| 29 | + return |
| 30 | + endif |
| 31 | + |
| 32 | + let l:tailComma = argwrap#getSetting('tail_comma') |
| 33 | + let l:tailCommaForFunctionDeclaration = argwrap#getSetting('tail_comma_braces') =~ '(' |
| 34 | + |
| 35 | + " Don't do anything if the tail comma feature is disabled |
| 36 | + if !l:tailComma && !l:tailCommaForFunctionDeclaration |
| 37 | + return |
| 38 | + endif |
| 39 | + |
| 40 | + " Don't do anything if it's not a function declaration |
| 41 | + if !s:dealWithFunctionDeclaration(a:container) |
| 42 | + return |
| 43 | + endif |
| 44 | + |
| 45 | + let l:lineEnd = a:range.lineEnd + len(a:arguments) |
| 46 | + |
| 47 | + if getline(l:lineEnd) =~ '\v,\s*$' |
| 48 | + call setline(l:lineEnd, substitute(getline(l:lineEnd), '\s*,\s*$', '', '')) |
| 49 | + endif |
| 50 | +endfunction " }}} |
| 51 | + |
| 52 | +function! argwrap#hooks#filetype#php#200_remove_tail_comma_function_declaration#post_unwrap(range, container, arguments) abort " {{{ |
| 53 | + " Do nothing but prevent the file to be loaded more than once |
| 54 | + " When calling an autoload function that is not define the script that |
| 55 | + " should contain it is sourced every time the function is called |
| 56 | +endfunction " }}} |
| 57 | + |
| 58 | +" vim: ts=2 sw=2 et fdm=marker |
0 commit comments