Skip to content

Commit ab87fe7

Browse files
committed
Show an information if no verbose
1 parent dd19bb0 commit ab87fe7

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@ let g:php_cs_fixer_php_path = "php" " Path to PHP
1515
let g:php_cs_fixer_fixers_list = "" " List of fixers
1616
let g:php_cs_fixer_default_mapping = 1 " Enable the mapping by default (<leader>pcd)
1717
let g:php_cs_fixer_dry_run = 0 " Call command with dry-run option
18+
let g:php_cs_fixer_verbose = 0 " Return the output of command if 1, else an inline information.
1819
```
1920

2021
Default mapping is `<leader>pcd`
2122

2223
If you want to change it:
2324

2425
```viml
25-
map <leader>pcd :call PhpCsFixerFixDirectory()<CR>
26-
map <leader>pcf :call PhpCsFixerFixFile()<CR>
26+
nnoremap <silent><leader>pcd :call PhpCsFixerFixDirectory()<CR>
27+
nnoremap <silent><leader>pcf :call PhpCsFixerFixFile()<CR>
2728
```
2829

2930
# Installation
@@ -37,3 +38,7 @@ Bundle 'stephpy/vim-php-cs-fixer'
3738
To see how to install `php-cs-fixer`, look at [php-cs-fixer](https://github.com/fabpot/PHP-CS-Fixer) repository.
3839

3940
If you see any improvement or question, contribute or create an issue
41+
42+
# Todo
43+
44+
- If `dry-run` option, ask to user if he wants to launch command without dry-run after he launchs command.

plugin/php-cs-fixer.vim

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ call s:initVariable("g:php_cs_fixer_php_path", "php")
1414
call s:initVariable("g:php_cs_fixer_fixers_list", "")
1515
call s:initVariable("g:php_cs_fixer_default_mapping", 1)
1616
call s:initVariable("g:php_cs_fixer_dry_run", 0)
17+
call s:initVariable("g:php_cs_fixer_verbose", 0)
1718

1819
let g:php_cs_fixer_command = g:php_cs_fixer_php_path.' '.g:php_cs_fixer_path.' fix --config='.g:php_cs_fixer_config
1920

@@ -28,12 +29,26 @@ fun! PhpCsFixerFix(path)
2829
let command = command.' --fixers='.g:php_cs_fixer_fixers_list
2930
endif
3031

31-
let output = system(command)
32+
let s:output = system(command)
3233
if v:shell_error
33-
echohl Error | echo output | echohl None
34+
echohl Error | echo s:output | echohl None
3435
else
35-
" todo, count how many files have been updated
36-
echohl Title | echo output | echohl None
36+
let s:nbLines = len(split(s:output, '\n'))
37+
let s:nbFilesModified = (s:nbLines - 1)
38+
39+
if(g:php_cs_fixer_verbose == 1)
40+
" @todo, if dry-run, purpose to user to launch command without
41+
" dry-run
42+
echohl Title | echo s:output | echohl None
43+
else
44+
if(s:nbFilesModified > 0)
45+
" @todo, if dry-run, purpose to user to launch command without
46+
" dry-run
47+
echohl Title | echo "There is ".s:nbFilesModified." file(s) modified(s)" | echohl None
48+
else
49+
echohl Title | echo "There is no cs to fix" | echohl None
50+
endif
51+
endif
3752
endif
3853
endfun
3954

@@ -46,6 +61,6 @@ fun! PhpCsFixerFixFile()
4661
endfun
4762

4863
if(g:php_cs_fixer_default_mapping == 1)
49-
map <leader>pcd :call PhpCsFixerFixDirectory()<CR>
50-
map <leader>pcf :call PhpCsFixerFixFile()<CR>
64+
nnoremap <silent><leader>pcd :call PhpCsFixerFixDirectory()<CR>
65+
nnoremap <silent><leader>pcf :call PhpCsFixerFixFile()<CR>
5166
endif

0 commit comments

Comments
 (0)