0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

Merge 51327677ac79241919d0ca367cfadc7a6df25e93 into a494ce1c64a2637719a5c1339abf19ec7c48089c

This commit is contained in:
Enno 2025-07-04 11:10:32 +02:00 committed by GitHub
commit e54500bf62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 0 deletions

View File

@ -794,6 +794,13 @@ To enable the recognition of Markdown comments each time after removing
re-source "javaformat.vim" for Vim versions greater than `8.2.1397`: >
runtime autoload/javaformat.vim
<
JAVASCRIPT *ft-javascript-plugin*
To enable prettier formatting of JavaScript files, set the following variable
in your vimrc: >
let g:javascript_formatter = 'prettier'
JSON-FORMAT *ft-json-plugin*
JSON filetype can be extended to use 'formatexpr' and "json.FormatExpr()"

View File

@ -7452,6 +7452,7 @@ ft-inform-syntax syntax.txt /*ft-inform-syntax*
ft-java-plugin filetype.txt /*ft-java-plugin*
ft-java-syntax syntax.txt /*ft-java-syntax*
ft-javascript-omni insert.txt /*ft-javascript-omni*
ft-javascript-plugin filetype.txt /*ft-javascript-plugin*
ft-jq-syntax syntax.txt /*ft-jq-syntax*
ft-json-plugin filetype.txt /*ft-json-plugin*
ft-json-syntax syntax.txt /*ft-json-syntax*

View File

@ -70,8 +70,23 @@ let &l:define =
\ .. '\|^\s*\(export\s\+\|export\s\+default\s\+\)*\(var\|let\|const\|function\|class\)'
\ .. '\|\<as\>'
if !empty(get(g:,'javascript_formatprg', ''))
augroup formatprgsJavaScript
autocmd! * <buffer>
autocmd ShellFilterPost <buffer> if v:shell_error | execute 'echom "shell filter returned error " . v:shell_error . ", undoing changes"' | undo | endif
if g:javascript_formatprg ==# 'prettier'
autocmd BufWinEnter <buffer> ++once let &l:formatprg =
\ executable('prettier') ? 'prettier' : 'npx prettier' .
\ ' --stdin-filepath=%:S --parser=javascript ' .
\ (&textwidth > 0 ? '--print-width=' . &textwidth : '') .
\ ' --tab-width=' . &l:shiftwidth . (&expandtab ? '' : '--use-tabs') . ' --'
endif
augroup END
endif
let b:undo_ftplugin =
\ "setl fo< ofu< com< cms< sua< su< def< pa<"
\ .. !empty(g:javascript_formatprg) ? " fp<" : ""
\ .. "| unlet! b:browsefilter b:match_ignorecase b:match_words"
let &cpo = s:cpo_save