diff --git a/autoload/SpaceVim/layers/lang/php.vim b/autoload/SpaceVim/layers/lang/php.vim index 2fc9a0483..e78ea3407 100644 --- a/autoload/SpaceVim/layers/lang/php.vim +++ b/autoload/SpaceVim/layers/lang/php.vim @@ -38,6 +38,12 @@ function! SpaceVim#layers#lang#php#plugins() abort return plugins endfunction +let s:auto_fix = 0 + +function! SpaceVim#layers#lang#php#set_variable(var) abort + let s:auto_fix = get(a:var, 'auto_fix', 0) +endfunction + function! SpaceVim#layers#lang#php#config() abort call SpaceVim#plugins#runner#reg_runner('php', 'php %s') call SpaceVim#mapping#space#regesit_lang_mappings('php', @@ -47,6 +53,14 @@ function! SpaceVim#layers#lang#php#config() abort \ function('SpaceVim#lsp#go_to_def')) endif + if s:auto_fix + augroup SpaceVim_lang_php + autocmd! + autocmd User NeomakeJobInit call phpBeautify() + autocmd FocusGained * checktime + augroup END + endif + endfunction function! s:on_ft() abort @@ -62,3 +76,22 @@ function! s:on_ft() abort \ 'call SpaceVim#plugins#runner#open()', \ 'execute current file', 1) endfunction + +function! s:phpBeautify() abort + if (&filetype ==# 'php') + let l:args = [] + if exists('g:neomake_php_phpcs_args_standard') + call add(l:args, '--standard=' . expand(g:neomake_php_phpcs_args_standard)) + endif + let l:lhs = expand('%') + let l:command = printf( + \ 'phpcbf %s %s', + \ join(l:args, ' '), + \ shellescape(fnameescape(l:lhs)) + \ ) + try + let l:result = system(l:command) + checktime + endtry + endif +endfunction