1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 05:20:04 +08:00

Add autofix feature for php with phpcbf

This commit is contained in:
zhujinxuan 2018-04-22 19:18:45 -04:00
parent 9d8c4ec365
commit d19950b62e

View File

@ -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 <SID>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