diff options
| author | Mitermayer Reis <mitermayer.reis@gmail.com> | 2020-04-10 21:24:57 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-10 21:24:57 +1000 |
| commit | 6b1adeb54910aaac47d6ab9ecc6d54ffe2f68360 (patch) | |
| tree | 8af5603b0aacad06a86f2363e7a245f4ad0873a5 | |
| parent | b016b933523b428c664d7a02a69c9b499c600abb (diff) | |
| parent | 62ea1dc2110ff760af167633c71a6e469011b9c6 (diff) | |
| download | vim-prettier-6b1adeb54910aaac47d6ab9ecc6d54ffe2f68360.tar.xz | |
Merge pull request #234 from cjlarose/reevaluate-autoformat
Force reevaluation of autoformat settings at buffer write time
| -rw-r--r-- | autoload/prettier.vim | 12 | ||||
| -rw-r--r-- | ftplugin/css.vim | 4 | ||||
| -rw-r--r-- | ftplugin/graphql.vim | 4 | ||||
| -rw-r--r-- | ftplugin/html.vim | 4 | ||||
| -rw-r--r-- | ftplugin/javascript.vim | 4 | ||||
| -rw-r--r-- | ftplugin/json.vim | 4 | ||||
| -rw-r--r-- | ftplugin/less.vim | 4 | ||||
| -rw-r--r-- | ftplugin/lua.vim | 4 | ||||
| -rw-r--r-- | ftplugin/markdown.vim | 4 | ||||
| -rw-r--r-- | ftplugin/php.vim | 4 | ||||
| -rw-r--r-- | ftplugin/ruby.vim | 4 | ||||
| -rw-r--r-- | ftplugin/scss.vim | 4 | ||||
| -rw-r--r-- | ftplugin/typescript.vim | 4 | ||||
| -rw-r--r-- | ftplugin/vue.vim | 4 | ||||
| -rw-r--r-- | ftplugin/xml.vim | 4 | ||||
| -rw-r--r-- | ftplugin/yaml.vim | 4 | ||||
| -rw-r--r-- | plugin/prettier.vim | 12 |
17 files changed, 25 insertions, 59 deletions
diff --git a/autoload/prettier.vim b/autoload/prettier.vim index ebe6abd..a9533f4 100644 --- a/autoload/prettier.vim +++ b/autoload/prettier.vim @@ -36,9 +36,15 @@ endfunction " Allows @format and @prettier pragma support upon saving function! prettier#Autoformat(...) abort - call prettier#Prettier(1, 1, line('$'), 0, { - \ 'requirePragma': g:prettier#autoformat_require_pragma ? 'true' : 'false' - \ }) + let l:autoformat = g:prettier#autoformat_config_present ? + \ prettier#IsConfigPresent(g:prettier#autoformat_config_files) : + \ g:prettier#autoformat + + if l:autoformat + call prettier#Prettier(1, 1, line('$'), 0, { + \ 'requirePragma': g:prettier#autoformat_require_pragma ? 'true' : 'false' + \ }) + endif endfunction " Main prettier command diff --git a/ftplugin/css.vim b/ftplugin/css.vim index 53881ca..ad63926 100644 --- a/ftplugin/css.vim +++ b/ftplugin/css.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.css call prettier#Autoformat() - endif + autocmd BufWritePre *.css call prettier#Autoformat() augroup end diff --git a/ftplugin/graphql.vim b/ftplugin/graphql.vim index 5e63e3f..414f0bb 100644 --- a/ftplugin/graphql.vim +++ b/ftplugin/graphql.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.graphql,*.gql call prettier#Autoformat() - endif + autocmd BufWritePre *.graphql,*.gql call prettier#Autoformat() augroup end diff --git a/ftplugin/html.vim b/ftplugin/html.vim index 5de2453..0134d33 100644 --- a/ftplugin/html.vim +++ b/ftplugin/html.vim @@ -8,7 +8,5 @@ endif augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.html call prettier#Autoformat() - endif + autocmd BufWritePre *.html call prettier#Autoformat() augroup end diff --git a/ftplugin/javascript.vim b/ftplugin/javascript.vim index dbe0694..b744c94 100644 --- a/ftplugin/javascript.vim +++ b/ftplugin/javascript.vim @@ -1,6 +1,4 @@ augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.js,*.jsx,*.mjs call prettier#Autoformat() - endif + autocmd BufWritePre *.js,*.jsx,*.mjs call prettier#Autoformat() augroup end diff --git a/ftplugin/json.vim b/ftplugin/json.vim index 1c5ef7d..d19b7ee 100644 --- a/ftplugin/json.vim +++ b/ftplugin/json.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.json call prettier#Autoformat() - endif + autocmd BufWritePre *.json call prettier#Autoformat() augroup end diff --git a/ftplugin/less.vim b/ftplugin/less.vim index e1f18ce..6f64192 100644 --- a/ftplugin/less.vim +++ b/ftplugin/less.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.less call prettier#Autoformat() - endif + autocmd BufWritePre *.less call prettier#Autoformat() augroup end diff --git a/ftplugin/lua.vim b/ftplugin/lua.vim index e363f6b..17f937c 100644 --- a/ftplugin/lua.vim +++ b/ftplugin/lua.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.lua call prettier#Autoformat() - endif + autocmd BufWritePre *.lua call prettier#Autoformat() augroup end diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index 94dbe0e..277b22a 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.markdown,*.md,*.mdown,*.mkd,*.mkdn call prettier#Autoformat() - endif + autocmd BufWritePre *.markdown,*.md,*.mdown,*.mkd,*.mkdn call prettier#Autoformat() augroup end diff --git a/ftplugin/php.vim b/ftplugin/php.vim index 8413ded..a3ad43b 100644 --- a/ftplugin/php.vim +++ b/ftplugin/php.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.php call prettier#Autoformat() - endif + autocmd BufWritePre *.php call prettier#Autoformat() augroup end diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index c5f62fc..f93997d 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.ruby call prettier#Autoformat() - endif + autocmd BufWritePre *.ruby call prettier#Autoformat() augroup end diff --git a/ftplugin/scss.vim b/ftplugin/scss.vim index 04cd8e8..f371604 100644 --- a/ftplugin/scss.vim +++ b/ftplugin/scss.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.scss call prettier#Autoformat() - endif + autocmd BufWritePre *.scss call prettier#Autoformat() augroup end diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim index f023d43..bb7fc09 100644 --- a/ftplugin/typescript.vim +++ b/ftplugin/typescript.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.ts,*.tsx call prettier#Autoformat() - endif + autocmd BufWritePre *.ts,*.tsx call prettier#Autoformat() augroup end diff --git a/ftplugin/vue.vim b/ftplugin/vue.vim index cc9c4fd..6dfa47f 100644 --- a/ftplugin/vue.vim +++ b/ftplugin/vue.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.vue call prettier#Autoformat() - endif + autocmd BufWritePre *.vue call prettier#Autoformat() augroup end diff --git a/ftplugin/xml.vim b/ftplugin/xml.vim index dc7d908..649bfb1 100644 --- a/ftplugin/xml.vim +++ b/ftplugin/xml.vim @@ -8,7 +8,5 @@ endif augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.xml call prettier#Autoformat() - endif + autocmd BufWritePre *.xml call prettier#Autoformat() augroup end diff --git a/ftplugin/yaml.vim b/ftplugin/yaml.vim index 23944c7..2d0564d 100644 --- a/ftplugin/yaml.vim +++ b/ftplugin/yaml.vim @@ -4,7 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - if get(g:, 'prettier#autoformat') - autocmd BufWritePre *.yaml call prettier#Autoformat() - endif + autocmd BufWritePre *.yaml call prettier#Autoformat() augroup end diff --git a/plugin/prettier.vim b/plugin/prettier.vim index 01eb098..f7818dc 100644 --- a/plugin/prettier.vim +++ b/plugin/prettier.vim @@ -155,15 +155,5 @@ nnoremap <silent> <Plug>(PrettierCliPath) :PrettierCliPath<CR> augroup Prettier autocmd! - if g:prettier#autoformat_config_present - if prettier#IsConfigPresent(g:prettier#autoformat_config_files) - let g:prettier#autoformat = 1 - else - let g:prettier#autoformat = 0 - endif - endif - - if g:prettier#autoformat - autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html noautocmd | call prettier#Autoformat() - endif + autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html noautocmd | call prettier#Autoformat() augroup end |
