Skip to content

Commit 44c987d

Browse files
committed
Update neoformat
1 parent 56f9e02 commit 44c987d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+957
-75
lines changed

plugins/iceberg.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 866f9f4ac9ff9a0ae33de96253c359c68ab556b4

plugins/neoformat/.kodiak.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version = 1
2+
3+
[merge.message]
4+
title = "pull_request_title"
5+
body = "pull_request_body"

plugins/neoformat/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# contributing
22

33
If you are looking to add or update a formatter, please be sure to update both
4-
`docs/neoformat.txt` as well as `README.md`. Thanks!
4+
[`doc/neoformat.txt`](./doc/neoformat.txt) as well as [`README.md`](./README.md). Thanks!

plugins/neoformat/README.md

Lines changed: 125 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Or specify a certain formatter (must be defined for the current filetype)
3131

3232
Or format a visual selection of code in a different filetype
3333

34-
__Note:__ you must use a ! and pass the filetype of the selection
34+
**Note:** you must use a ! and pass the filetype of the selection
3535

3636
```viml
3737
:Neoformat! python
@@ -58,7 +58,7 @@ The `undojoin` command will put changes made by Neoformat into the same
5858

5959
## Install
6060

61-
[vim-plug](https://github.com/junegunn/vim-plug)
61+
The best way to install Neoformat is with your favorite plugin manager for Vim, such as [vim-plug](https://github.com/junegunn/vim-plug):
6262

6363
```viml
6464
Plug 'sbdchd/neoformat'
@@ -76,16 +76,17 @@ Define custom formatters.
7676

7777
Options:
7878

79-
| name | description | default | optional / required |
80-
| ------------------ | ----------------------------------------------------------------------------------------------------------------- | ------- | ------------------- |
81-
| `exe` | the name the formatter executable in the path | n/a | **required** |
82-
| `args` | list of arguments | \[] | optional |
83-
| `replace` | overwrite the file, instead of updating the buffer | 0 | optional |
84-
| `stdin` | send data to the stdin of the formatter | 0 | optional |
85-
| `stderr` | capture stderr output from formatter | 0 | optional |
86-
| `no_append` | do not append the `path` of the file to the formatter command, used when the `path` is in the middle of a command | 0 | optional |
87-
| `env` | list of environment variable definitions to be prepended to the formatter command | \[] | optional |
88-
| `valid_exit_codes` | list of valid exit codes for formatters who do not respect common unix practices | \[0] | optional |
79+
| name | description | default | optional / required |
80+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------------------- |
81+
| `exe` | the name the formatter executable in the path | n/a | **required** |
82+
| `args` | list of arguments | \[] | optional |
83+
| `replace` | overwrite the file, instead of updating the buffer | 0 | optional |
84+
| `stdin` | send data to the stdin of the formatter | 0 | optional |
85+
| `stderr` | capture stderr output from formatter | 0 | optional |
86+
| `no_append` | do not append the `path` of the file to the formatter command, used when the `path` is in the middle of a command | 0 | optional |
87+
| `env` | list of environment variable definitions to be prepended to the formatter command | \[] | optional |
88+
| `valid_exit_codes` | list of valid exit codes for formatters who do not respect common unix practices | \[0] | optional |
89+
| `try_node_exe` | attempt to find `exe` in a `node_modules/.bin` directory in the current working directory or one of its parents (requires setting `g:neoformat_try_node_exe`) | 0 | optional |
8990

9091
Example:
9192

@@ -157,6 +158,14 @@ let g:neoformat_verbose = 1 " only affects the verbosity of Neoformat
157158
let &verbose = 1 " also increases verbosity of the editor as a whole
158159
```
159160

161+
Have Neoformat look for a formatter executable in the `node_modules/.bin`
162+
directory in the current working directory or one of its parents (only applies
163+
to formatters with `try_node_exe` set to `1`):
164+
165+
```viml
166+
let g:neoformat_try_node_exe = 1
167+
```
168+
160169
## Adding a New Formatter
161170

162171
Note: you should replace everything `{{ }}` accordingly
@@ -218,17 +227,24 @@ that caused Neoformat to be invoked.
218227
- [`asmfmt`](https://github.com/klauspost/asmfmt)
219228
- Bazel
220229
- [`buildifier`](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md)
230+
- Beancount
231+
- [`bean-format`](https://beancount.github.io/docs/running_beancount_and_generating_reports.html#bean-format)
232+
- Bib
233+
- [bibclean](https://github.com/tobywf/bibclean)
221234
- C
222235
- [`uncrustify`](http://uncrustify.sourceforge.net),
223236
[`clang-format`](http://clang.llvm.org/docs/ClangFormat.html),
224237
[`astyle`](http://astyle.sourceforge.net)
225238
- C#
226239
- [`uncrustify`](http://uncrustify.sourceforge.net),
227-
[`astyle`](http://astyle.sourceforge.net)
240+
[`astyle`](http://astyle.sourceforge.net),
241+
[`clang-format`](http://clang.llvm.org/docs/ClangFormat.html)
228242
- C++
229243
- [`uncrustify`](http://uncrustify.sourceforge.net),
230244
[`clang-format`](http://clang.llvm.org/docs/ClangFormat.html),
231245
[`astyle`](http://astyle.sourceforge.net)
246+
- Cabal
247+
- [`cabal-fmt`](https://github.com/phadej/cabal-fmt)
232248
- CMake
233249
- [`cmake_format`](https://github.com/cheshirekow/cmake_format)
234250
- Crystal
@@ -242,33 +258,73 @@ that caused Neoformat to be invoked.
242258
[`prettier`](https://github.com/prettier/prettier)
243259
- CSV
244260
- [`prettydiff`](https://github.com/prettydiff/prettydiff)
261+
- Cue
262+
- [`cue fmt`](https://cuelang.org/)
245263
- D
246264
- [`uncrustify`](http://uncrustify.sourceforge.net),
247265
[`dfmt`](https://github.com/Hackerpilot/dfmt)
248266
- Dart
249267
- [`dartfmt`](https://www.dartlang.org/tools/)
268+
- [`dart format`](https://dart.dev/tools/dart-format)
250269
- Dhall
251270
- [`dhall format`](https://dhall-lang.org)
252271
- dune
253272
- [`dune format`](https://github.com/ocaml/dune)
273+
- Ebuild
274+
- [`shfmt`](https://github.com/mvdan/sh)
275+
```vim
276+
let g:shfmt_opt="-ci"
277+
```
254278
- Elixir
255279
- [`mix format`](https://hexdocs.pm/mix/master/Mix.Tasks.Format.html)
256280
- Elm
257281
- [`elm-format`](https://github.com/avh4/elm-format)
282+
- Erlang
283+
- [`erlfmt`](https://github.com/WhatsApp/erlfmt)
258284
- Fish
259285
- [`fish_indent`](http://fishshell.com)
286+
- Fortran
287+
- [`fprettify`](https://github.com/pseewald/fprettify)
288+
- F#
289+
- [`fantomas`](https://github.com/fsprojects/fantomas)
290+
- GDScript
291+
- [`gdformat`](https://github.com/Scony/godot-gdscript-toolkit)
292+
- Gleam
293+
- [`gleam format`](https://github.com/gleam-lang/gleam/)
260294
- Go
261295
- [`gofmt`](https://golang.org/cmd/gofmt/),
262-
[`goimports`](https://godoc.org/golang.org/x/tools/cmd/goimports)
296+
[`goimports`](https://godoc.org/golang.org/x/tools/cmd/goimports),
297+
[`gofumpt`](https://github.com/mvdan/gofumpt),
298+
[`gofumports`](https://github.com/mvdan/gofumpt)
299+
- GLSL
300+
- [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html)
263301
- GraphQL
264302
- [`prettier`](https://github.com/prettier/prettier)
265303
- Haskell
266-
- [`stylish-haskell`](https://github.com/jaspervdj/stylish-haskell),
304+
- [`stylishhaskell`](https://github.com/jaspervdj/stylish-haskell),
267305
[`hindent`](https://github.com/chrisdone/hindent),
268306
[`hfmt`](https://github.com/danstiner/hfmt),
269307
[`brittany`](https://github.com/lspitzner/brittany),
270-
[`sort-imports`](https://github.com/evanrelf/sort-imports),
308+
[`sortimports`](https://github.com/evanrelf/sort-imports),
271309
[`floskell`](https://github.com/ennocramer/floskell)
310+
[`ormolu`](https://github.com/tweag/ormolu)
311+
```vim
312+
let g:ormolu_ghc_opt=["TypeApplications", "RankNTypes"]
313+
```
314+
- You must use formatter's name without "`-`"
315+
```vim
316+
" right
317+
let g:neoformat_enabled_haskell = ['sortimports', 'stylishhaskell']
318+
" wrong
319+
let g:neoformat_enabled_haskell = ['sort-imports', 'stylish-haskell']
320+
```
321+
- Toml
322+
- [`taplo`](https://taplo.tamasfe.dev/cli)
323+
- Puppet
324+
- [`puppet-lint`](https://github.com/rodjek/puppet-lint)
325+
- PureScript
326+
- [`purs-tidy`](https://github.com/natefaubion/purescript-tidy)
327+
- [`purty`](https://gitlab.com/joneshf/purty)
272328
- HTML
273329
- `html-beautify` (ships with [`js-beautify`](https://github.com/beautify-web/js-beautify)),
274330
[`prettier`](https://github.com/prettier/prettier),
@@ -277,24 +333,32 @@ that caused Neoformat to be invoked.
277333
- [`pug-beautifier`](https://github.com/vingorius/pug-beautifier)
278334
- Java
279335
- [`uncrustify`](http://uncrustify.sourceforge.net),
280-
[`astyle`](http://astyle.sourceforge.net)
281-
- Javascript
336+
[`astyle`](http://astyle.sourceforge.net),
337+
[`prettier`](https://github.com/prettier/prettier)
338+
- JavaScript
282339
- [`js-beautify`](https://github.com/beautify-web/js-beautify),
283340
[`prettier`](https://github.com/prettier/prettier),
284341
[`prettydiff`](https://github.com/prettydiff/prettydiff),
285342
[`clang-format`](http://clang.llvm.org/docs/ClangFormat.html),
286343
[`esformatter`](https://github.com/millermedeiros/esformatter/),
287344
[`prettier-eslint`](https://github.com/kentcdodds/prettier-eslint-cli),
288-
[`eslint_d`](https://github.com/mantoni/eslint_d.js)
289-
[`standard`](https://standardjs.com/)
345+
[`eslint_d`](https://github.com/mantoni/eslint_d.js),
346+
[`standard`](https://standardjs.com/),
347+
[`semistandard`](https://github.com/standard/semistandard),
348+
[`deno fmt`](https://deno.land/manual/tools/formatter)
290349
- JSON
291350
- [`js-beautify`](https://github.com/beautify-web/js-beautify),
292351
[`prettydiff`](https://github.com/prettydiff/prettydiff),
293352
[`prettier`](https://github.com/prettier/prettier),
294353
[`jq`](https://stedolan.github.io/jq/),
295354
[`fixjson`](https://github.com/rhysd/fixjson)
355+
[`deno fmt`](https://deno.land/manual/tools/formatter)
356+
- JSONC (JSON with comments)
357+
- [`prettier`](https://github.com/prettier/prettier)
358+
[`deno fmt`](https://deno.land/manual/tools/formatter)
296359
- Kotlin
297-
- [`ktlint`](https://github.com/shyiko/ktlint)
360+
- [`ktlint`](https://github.com/shyiko/ktlint),
361+
[`prettier`](https://github.com/prettier/prettier)
298362
- LaTeX
299363
- [`latexindent`](https://github.com/cmhughes/latexindent.pl)
300364
- Less
@@ -304,11 +368,22 @@ that caused Neoformat to be invoked.
304368
[`stylelint`](https://stylelint.io/)
305369
- Lua
306370
- [`luaformatter`](https://github.com/LuaDevelopmentTools/luaformatter)
371+
- [`lua-fmt`](https://github.com/trixnz/lua-fmt)
372+
- [`lua-format`](https://github.com/Koihik/LuaFormatter)
373+
- [`stylua`](https://github.com/JohnnyMorganz/StyLua)
307374
- Markdown
308375
- [`remark`](https://github.com/wooorm/remark)
309376
[`prettier`](https://github.com/prettier/prettier)
377+
[`deno fmt`](https://deno.land/manual/tools/formatter)
378+
- Matlab
379+
- [`matlab-formatter-vscode`](https://github.com/affenwiesel/matlab-formatter-vscode)
380+
- Nginx
381+
- [nginxbeautifier](https://github.com/vasilevich/nginxbeautifier)
310382
- Nim
311383
- `nimpretty` (ships with [`nim`](https://nim-lang.org/))
384+
- Nix
385+
- [`nixfmt`](https://github.com/serokell/nixfmt)
386+
- [`nixpkgs-fmt`](https://github.com/nix-community/nixpkgs-fmt)
312387
- Objective-C
313388
- [`uncrustify`](http://uncrustify.sourceforge.net),
314389
[`clang-format`](http://clang.llvm.org/docs/ClangFormat.html),
@@ -326,14 +401,17 @@ that caused Neoformat to be invoked.
326401
- [`php_beautifier`](http://pear.php.net/package/PHP_Beautifier),
327402
[`php-cs-fixer`](http://cs.sensiolabs.org/),
328403
[`phpcbf`](https://github.com/squizlabs/PHP_CodeSniffer)
404+
- PowerShell
405+
- [`PSScriptAnalyzer`](https://github.com/PowerShell/PSScriptAnalyzer),
406+
[`PowerShell-Beautifier`](https://github.com/DTW-DanWard/PowerShell-Beautifier)
329407
- Proto
330408
- [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html)
331409
- Pug (formally Jade)
332410
- [`pug-beautifier`](https://github.com/vingorius/pug-beautifier)
333411
- Python
334412
- [`yapf`](https://github.com/google/yapf),
335413
[`autopep8`](https://github.com/hhatto/autopep8),
336-
[`black`](https://github.com/ambv/black),
414+
[`black`](https://github.com/psf/black),
337415
[`pydevf`](https://github.com/fabioz/PyDev.Formatter),
338416
[`isort`](https://github.com/timothycrosley/isort),
339417
[`docformatter`](https://github.com/myint/docformatter),
@@ -343,6 +421,7 @@ that caused Neoformat to be invoked.
343421
[`formatR`](https://github.com/yihui/formatR)
344422
- Reason
345423
- [`refmt`](https://github.com/facebook/reason)
424+
- [`bsrefmt`](https://github.com/bucklescript/bucklescript)
346425
- Ruby
347426
- [`rufo`](https://github.com/ruby-formatter/rufo),
348427
[`ruby-beautify`](https://github.com/erniebrodeur/ruby-beautify),
@@ -367,18 +446,31 @@ that caused Neoformat to be invoked.
367446
[`prettier`](https://github.com/prettier/prettier)
368447
- Shell
369448
- [`shfmt`](https://github.com/mvdan/sh)
449+
```vim
450+
let g:shfmt_opt="-ci"
451+
```
370452
- SQL
371453
- [`sqlfmt`](https://github.com/jackc/sqlfmt),
372454
`sqlformat` (ships with [sqlparse](https://github.com/andialbrecht/sqlparse)),
373455
`pg_format` (ships with [pgFormatter](https://github.com/darold/pgFormatter))
456+
- Starlark
457+
- [`buildifier`](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md)
458+
- Svelte
459+
- [`prettier-plugin-svelte`](https://github.com/UnwrittenFun/prettier-plugin-svelte)
374460
- Swift
375461
- [`Swiftformat`](https://github.com/nicklockwood/SwiftFormat)
376462
- Terraform
377463
- [`terraform`](https://www.terraform.io/docs/commands/fmt.html),
378-
- Typescript
464+
- TypeScript
379465
- [`tsfmt`](https://github.com/vvakame/typescript-formatter),
380466
[`prettier`](https://github.com/prettier/prettier),
381-
[`tslint`](https://palantir.github.io/tslint)
467+
[`prettier-eslint`](https://github.com/kentcdodds/prettier-eslint-cli),
468+
[`tslint`](https://palantir.github.io/tslint),
469+
[`eslint_d`](https://github.com/mantoni/eslint_d.js),
470+
[`clang-format`](http://clang.llvm.org/docs/ClangFormat.html),
471+
[`deno fmt`](https://deno.land/manual/tools/formatter)
472+
- V
473+
- `v fmt` (ships with [`v`](https://vlang.io))
382474
- VALA
383475
- [`uncrustify`](http://uncrustify.sourceforge.net)
384476
- Vue
@@ -388,7 +480,15 @@ that caused Neoformat to be invoked.
388480
[`prettydiff`](https://github.com/prettydiff/prettydiff)
389481
- XML
390482
- [`tidy`](http://www.html-tidy.org),
391-
[`prettydiff`](https://github.com/prettydiff/prettydiff)
483+
[`prettydiff`](https://github.com/prettydiff/prettydiff),
484+
[`prettier`](https://github.com/prettier/prettier)
392485
- YAML
393486
- [`pyaml`](https://pypi.python.org/pypi/pyaml),
394487
[`prettier`](https://github.com/prettier/prettier)
488+
- zig
489+
- [`zig fmt`](https://github.com/ziglang/zig)
490+
- zsh
491+
- [`shfmt`](https://github.com/mvdan/sh)
492+
```vim
493+
let g:shfmt_opt="-ci"
494+
```

plugins/neoformat/autoload/neoformat.vim

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
" Set global flag to allow checking in custom user config
2+
let g:neoformat = 1
3+
14
function! neoformat#Neoformat(bang, user_input, start_line, end_line) abort
2-
let search = @/
35
let view = winsaveview()
6+
let search = @/
47
let original_filetype = &filetype
58

69
call s:neoformat(a:bang, a:user_input, a:start_line, a:end_line)
710

11+
" Setting &filetype might destroy existing folds, so only do that
12+
" if the filetype got changed (which can only be possible when
13+
" invoking with a bang)
14+
if a:bang && &filetype != original_filetype
15+
let &filetype = original_filetype
16+
endif
817
let @/ = search
918
call winrestview(view)
10-
let &filetype = original_filetype
1119
endfunction
1220

1321
function! s:neoformat(bang, user_input, start_line, end_line) abort
@@ -102,7 +110,7 @@ function! s:neoformat(bang, user_input, start_line, end_line) abort
102110
call neoformat#utils#log(v:shell_error)
103111

104112
let process_ran_succesfully = index(cmd.valid_exit_codes, v:shell_error) != -1
105-
113+
106114
if cmd.stderr_log != ''
107115
call neoformat#utils#log('stderr output redirected to file' . cmd.stderr_log)
108116
call neoformat#utils#log_file_content(cmd.stderr_log)
@@ -215,13 +223,34 @@ function! s:split_filetypes(filetype) abort
215223
return split(a:filetype, '\.')[0]
216224
endfunction
217225

226+
function! s:get_node_exe(exe) abort
227+
let node_exe = findfile('node_modules/.bin/' . a:exe, getcwd() . ';')
228+
if !empty(node_exe) && executable(node_exe)
229+
return node_exe
230+
endif
231+
232+
return a:exe
233+
endfunction
234+
218235
function! s:generate_cmd(definition, filetype) abort
219236
let executable = get(a:definition, 'exe', '')
220237
if executable == ''
221238
call neoformat#utils#log('no exe field in definition')
222239
return {}
223240
endif
224-
if !executable(executable)
241+
242+
if exists('g:neoformat_try_node_exe')
243+
\ && g:neoformat_try_node_exe
244+
\ && get(a:definition, 'try_node_exe', 0)
245+
let executable = s:get_node_exe(executable)
246+
endif
247+
248+
if &shell =~ '\v%(powershell|pwsh)'
249+
if system('[bool](Get-Command ' . executable . ' -ErrorAction SilentlyContinue)') !~ 'True'
250+
call neoformat#utils#log('executable: ' . executable . ' is not a cmdlet, function, script file, or an executable program')
251+
return {}
252+
endif
253+
elseif !executable(executable)
225254
call neoformat#utils#log('executable: ' . executable . ' is not an executable')
226255
return {}
227256
endif
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function! neoformat#formatters#beancount#enabled() abort
2+
return ['beanformat']
3+
endfunction
4+
5+
function! neoformat#formatters#beancount#beanformat() abort
6+
return {
7+
\ 'exe': 'bean-format',
8+
\ 'stdin': 1,
9+
\ }
10+
endfunction

0 commit comments

Comments
 (0)