diff --git a/vim/bundle/neoformat/.editorconfig b/vim/bundle/neoformat/.editorconfig new file mode 100644 index 0000000..e95a293 --- /dev/null +++ b/vim/bundle/neoformat/.editorconfig @@ -0,0 +1,13 @@ +[*] +indent_style = space +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.vim] +indent_size = 4 +tab_width = 4 + +[*.vader] +indent_size = 2 diff --git a/vim/bundle/neoformat/.gitignore b/vim/bundle/neoformat/.gitignore new file mode 100644 index 0000000..523e87e --- /dev/null +++ b/vim/bundle/neoformat/.gitignore @@ -0,0 +1,4 @@ +test/$VADER_OUTPUT_FILE +node_modules/ +.cache +doc/tags diff --git a/vim/bundle/neoformat/.nvmrc b/vim/bundle/neoformat/.nvmrc new file mode 100644 index 0000000..32447ce --- /dev/null +++ b/vim/bundle/neoformat/.nvmrc @@ -0,0 +1 @@ +5.11.1 diff --git a/vim/bundle/neoformat/.travis.yml b/vim/bundle/neoformat/.travis.yml new file mode 100644 index 0000000..00718fd --- /dev/null +++ b/vim/bundle/neoformat/.travis.yml @@ -0,0 +1,23 @@ +language: python + +sudo: required + +cache: + - pip + - npm + +env: + - PATH="$PATH:/home/travis/build/sbdchd/neoformat/test/bin" + +python: + - "3.6" + +before_install: + - nvm install $NODE_VERSION + +install: + - ./test/install.sh + - pip install -r test/requirements.txt + +script: + - cd test && pytest -v test.py diff --git a/vim/bundle/neoformat/.vintrc.yaml b/vim/bundle/neoformat/.vintrc.yaml new file mode 100644 index 0000000..05b6299 --- /dev/null +++ b/vim/bundle/neoformat/.vintrc.yaml @@ -0,0 +1,13 @@ +cmdargs: + severity: error + +env: + neovim: true + +policies: + ProhibitSetNoCompatible: + enabled: false + ProhibitImplicitScopeVariable: + enabled: false + ProhibitEqualTildeOperator: + enabled: false diff --git a/vim/bundle/neoformat/CONTRIBUTING.md b/vim/bundle/neoformat/CONTRIBUTING.md new file mode 100644 index 0000000..52837df --- /dev/null +++ b/vim/bundle/neoformat/CONTRIBUTING.md @@ -0,0 +1,4 @@ +# contributing + +If you are looking to add or update a formatter, please be sure to update both +`docs/neoformat.txt` as well as `README.md`. Thanks! diff --git a/vim/bundle/neoformat/LICENSE b/vim/bundle/neoformat/LICENSE new file mode 100644 index 0000000..6c9cb59 --- /dev/null +++ b/vim/bundle/neoformat/LICENSE @@ -0,0 +1,23 @@ +Copyright (c) 2016, Steve Dignam +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vim/bundle/neoformat/Makefile b/vim/bundle/neoformat/Makefile new file mode 100644 index 0000000..1083cd7 --- /dev/null +++ b/vim/bundle/neoformat/Makefile @@ -0,0 +1,5 @@ +all: + +.PHONY: test +test: + ./test/test.sh diff --git a/vim/bundle/neoformat/README.md b/vim/bundle/neoformat/README.md new file mode 100644 index 0000000..e2930d6 --- /dev/null +++ b/vim/bundle/neoformat/README.md @@ -0,0 +1,356 @@ +# Neoformat [![Build Status](https://travis-ci.org/sbdchd/neoformat.svg?branch=master)](https://travis-ci.org/sbdchd/neoformat) + +A (Neo)vim plugin for formatting code. + +Neoformat uses a variety of formatters for many filetypes. Currently, Neoformat +will run a formatter using the current buffer data, and on success it will +update the current buffer with the formatted text. On a formatter failure, +Neoformat will try the next formatter defined for the filetype. + +By using `getbufline()` to read from the current buffer instead of file, +Neoformat is able to format your buffer without you having to `:w` your file first. +Also, by using `setline()`, marks, jumps, etc. are all maintained after formatting. + +Neoformat supports both sending buffer data to formatters via stdin, and also +writing buffer data to `/tmp/` for formatters to read that do not support input +via stdin. + +## Basic Usage + +Format the entire buffer, or visual selection of the buffer + +```viml +:Neoformat +``` + +Or specify a certain formatter (must be defined for the current filetype) + +```viml +:Neoformat jsbeautify +``` + +Or format a visual selection of code in a different filetype + +__Note:__ you must use a ! and pass the filetype of the selection + +```viml +:Neoformat! python +``` + +You can also pass a formatter to use + +```viml +:Neoformat! python yapf +``` + +Or perhaps run a formatter on save + +```viml +augroup fmt + autocmd! + autocmd BufWritePre * undojoin | Neoformat +augroup END +``` + +The `undojoin` command will put changes made by Neoformat into the same +`undo-block` with the latest preceding change. See +[Managing Undo History](#managing-undo-history). + +## Install + +[vim-plug](https://github.com/junegunn/vim-plug) + +```viml +Plug 'sbdchd/neoformat' +``` + +## Current Limitation(s) + +If a formatter is either not configured to use `stdin`, or is not able to read +from `stdin`, then buffer data will be written to a file in `/tmp/neoformat/`, +where the formatter will then read from + +## Config [Optional] + +Define custom formatters. + +Options: + +| name | description | default | optional / required | +| ------------------ | ----------------------------------------------------------------------------------------------------------------- | ------- | ------------------- | +| `exe` | the name the formatter executable in the path | n/a | **required** | +| `args` | list of arguments | \[] | optional | +| `replace` | overwrite the file, instead of updating the buffer | 0 | optional | +| `stdin` | send data to the stdin of the formatter | 0 | optional | +| `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 | +| `env` | list of environment variable definitions to be prepended to the formatter command | \[] | optional | +| `valid_exit_codes` | list of valid exit codes for formatters who do not respect common unix practices | \[0] | optional | + +Example: + +```viml +let g:neoformat_python_autopep8 = { + \ 'exe': 'autopep8', + \ 'args': ['-s 4', '-E'], + \ 'replace': 1 " replace the file, instead of updating buffer (default: 0), + \ 'stdin': 1, " send data to stdin of formatter (default: 0) + \ 'env': ["DEBUG=1"], " prepend environment variables to formatter command + \ 'valid_exit_codes': [0, 23], + \ 'no_append': 1, + \ } + +let g:neoformat_enabled_python = ['autopep8'] +``` + +Configure enabled formatters. + +```viml +let g:neoformat_enabled_python = ['autopep8', 'yapf', 'docformatter'] +``` + +Have Neoformat use &formatprg as a formatter + +```viml +let g:neoformat_try_formatprg = 1 +``` + +Enable basic formatting when a filetype is not found. Disabled by default. + +```viml +" Enable alignment +let g:neoformat_basic_format_align = 1 + +" Enable tab to spaces conversion +let g:neoformat_basic_format_retab = 1 + +" Enable trimmming of trailing whitespace +let g:neoformat_basic_format_trim = 1 +``` + +Run all enabled formatters (by default Neoformat stops after the first formatter +succeeds) + +```viml +let g:neoformat_run_all_formatters = 1 +``` + +Have Neoformat only msg when there is an error + +```viml +let g:neoformat_only_msg_on_error = 1 +``` + +When debugging, you can enable either of following variables for extra logging. + +```viml +let g:neoformat_verbose = 1 " only affects the verbosity of Neoformat +" Or +let &verbose = 1 " also increases verbosity of the editor as a whole +``` + +## Adding a New Formatter + +Note: you should replace everything `{{ }}` accordingly + +1. Create a file in `autoload/neoformat/formatters/{{ filetype }}.vim` if it does not + already exist for your filetype. + +2. Follow the following format + +See Config above for options + +```viml +function! neoformat#formatters#{{ filetype }}#enabled() abort + return ['{{ formatter name }}', '{{ other formatter name for filetype }}'] +endfunction + +function! neoformat#formatters#{{ filetype }}#{{ formatter name }}() abort + return { + \ 'exe': '{{ formatter name }}', + \ 'args': ['-s 4', '-q'], + \ 'stdin': 1 + \ } +endfunction + +function! neoformat#formatters#{{ filetype }}#{{ other formatter name }}() abort + return {'exe': {{ other formatter name }} +endfunction +``` + +## Managing Undo History + +If you use an `autocmd` to run Neoformat on save, and you have your editor +configured to save automatically on `CursorHold` then you might run into +problems reverting changes. Pressing `u` will undo the last change made by +Neoformat instead of the change that you made yourself - and then Neoformat +will run again redoing the change that you just reverted. To avoid this +problem you can run Neoformat with the Vim `undojoin` command to put changes +made by Neoformat into the same `undo-block` with the preceding change. For +example: + +```viml +augroup fmt + autocmd! + autocmd BufWritePre * undojoin | Neoformat +augroup END +``` + +When `undojoin` is used this way pressing `u` will "skip over" the Neoformat +changes - it will revert both the changes made by Neoformat and the change +that caused Neoformat to be invoked. + +## Supported Filetypes + +- Arduino + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html), + [`astyle`](http://astyle.sourceforge.net) +- Bazel + - [`buildifier`](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md) +- C + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html), + [`astyle`](http://astyle.sourceforge.net) +- C# + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`astyle`](http://astyle.sourceforge.net) +- C++ + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html), + [`astyle`](http://astyle.sourceforge.net) +- CMake + - [`cmake_format`](https://github.com/cheshirekow/cmake_format) +- Crystal + - `crystal tool format` (ships with [`crystal`](http://crystal-lang.org)) +- CSS + - `css-beautify` (ships with [`js-beautify`](https://github.com/beautify-web/js-beautify)), + [`prettydiff`](https://github.com/prettydiff/prettydiff), + [`stylefmt`](https://github.com/morishitter/stylefmt), + [`csscomb`](http://csscomb.com), + [`prettier`](https://github.com/prettier/prettier) +- CSV + - [`prettydiff`](https://github.com/prettydiff/prettydiff) +- D + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`dfmt`](https://github.com/Hackerpilot/dfmt) +- Dart + - [`dartfmt`](https://www.dartlang.org/tools/) +- Elixir + - [`mix format`](https://hexdocs.pm/mix/master/Mix.Tasks.Format.html) +- Elm + - [`elm-format`](https://github.com/avh4/elm-format) +- Fish + - [`fish_indent`](http://fishshell.com) +- Go + - [`gofmt`](https://golang.org/cmd/gofmt/), + [`goimports`](https://godoc.org/golang.org/x/tools/cmd/goimports) +- GraphQL + - [`prettier`](https://github.com/prettier/prettier) +- Haskell + - [`stylish-haskell`](https://github.com/jaspervdj/stylish-haskell) + - [`hindent`](https://github.com/chrisdone/hindent) + - [`hfmt`](https://github.com/danstiner/hfmt) + - [`brittany`](https://github.com/lspitzner/brittany) +- HTML + - `html-beautify` (ships with [`js-beautify`](https://github.com/beautify-web/js-beautify)), + [`prettydiff`](https://github.com/prettydiff/prettydiff) +- Jade + - [`pug-beautifier`](https://github.com/vingorius/pug-beautifier) +- Java + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`astyle`](http://astyle.sourceforge.net) +- Javascript + - [`js-beautify`](https://github.com/beautify-web/js-beautify), + [`prettier`](https://github.com/prettier/prettier), + [`prettydiff`](https://github.com/prettydiff/prettydiff), + [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html), + [`esformatter`](https://github.com/millermedeiros/esformatter/), + [`prettier-eslint`](https://github.com/kentcdodds/prettier-eslint-cli), + [`eslint_d`](https://github.com/mantoni/eslint_d.js) + [`standard`](https://standardjs.com/) +- JSON + - [`js-beautify`](https://github.com/beautify-web/js-beautify), + [`prettydiff`](https://github.com/prettydiff/prettydiff), + [`prettier`](https://github.com/prettier/prettier), + [`jq`](https://stedolan.github.io/jq/), + [`fixjson`](https://github.com/rhysd/fixjson) +- Kotlin + - [`ktlint`](https://github.com/shyiko/ktlint) +- LaTeX + - [`latexindent`](https://github.com/cmhughes/latexindent.pl) +- Less + - [`csscomb`](http://csscomb.com), + [`prettydiff`](https://github.com/prettydiff/prettydiff), + [`prettier`](https://github.com/prettier/prettier) +- Lua + - [`luaformatter`](https://github.com/LuaDevelopmentTools/luaformatter) +- Markdown + - [`remark`](https://github.com/wooorm/remark) + [`prettier`](https://github.com/prettier/prettier) +- Objective-C + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html), + [`astyle`](http://astyle.sourceforge.net) +- OCaml + - [`ocp-indent`](http://www.typerex.org/ocp-indent.html) + - [`ocamlformat`](https://github.com/ocaml-ppx/ocamlformat) +- Pandoc Markdown + - [`pandoc`](https://pandoc.org/MANUAL.html) +- Pawn + - [`uncrustify`](http://uncrustify.sourceforge.net) +- Perl + - [`perltidy`](http://perltidy.sourceforge.net) +- PHP + - [`php_beautifier`](http://pear.php.net/package/PHP_Beautifier) + - [`php-cs-fixer`](http://cs.sensiolabs.org/) +- Proto + - [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html) +- Pug (formally Jade) + - [`pug-beautifier`](https://github.com/vingorius/pug-beautifier) +- Python + - [`yapf`](https://github.com/google/yapf), + [`autopep8`](https://github.com/hhatto/autopep8), + [`black`](https://github.com/ambv/black) + - [`isort`](https://github.com/timothycrosley/isort) + - [`docformatter`](https://github.com/myint/docformatter) +- Reason + - [`refmt`](https://github.com/facebook/reason) +- Ruby + - [`rufo`](https://github.com/ruby-formatter/rufo), + - [`ruby-beautify`](https://github.com/erniebrodeur/ruby-beautify), + [`rubocop`](https://github.com/bbatsov/rubocop) +- Rust + - [`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) +- Sass + - [`sass-convert`](http://sass-lang.com/documentation/#executables), + [`csscomb`](http://csscomb.com) +- Scala + - [`scalariform`](https://github.com/scala-ide/scalariform), + [`scalafmt`](http://scalameta.org/scalafmt/) +- SCSS + - [`sass-convert`](http://sass-lang.com/documentation/#executables), + [`stylefmt`](https://github.com/morishitter/stylefmt), + [`prettydiff`](https://github.com/prettydiff/prettydiff), + [`csscomb`](http://csscomb.com), + [`prettier`](https://github.com/prettier/prettier) +- Shell + - [`shfmt`](https://github.com/mvdan/sh) +- SQL + - `sqlformat` (ships with [sqlparse](https://github.com/andialbrecht/sqlparse)) +- Terraform + - [`terraform`](https://www.terraform.io/docs/commands/fmt.html), +- Typescript + - [`tsfmt`](https://github.com/vvakame/typescript-formatter), + [`prettier`](https://github.com/prettier/prettier) +- VALA + - [`uncrustify`](http://uncrustify.sourceforge.net) +- Vue + - [`prettier`](https://github.com/prettier/prettier) +- XHTML + - [`tidy`](http://www.html-tidy.org), + [`prettydiff`](https://github.com/prettydiff/prettydiff) +- XML + - [`tidy`](http://www.html-tidy.org), + [`prettydiff`](https://github.com/prettydiff/prettydiff) +- YAML + - [`pyaml`](https://pypi.python.org/pypi/pyaml) diff --git a/vim/bundle/neoformat/autoload/neoformat.vim b/vim/bundle/neoformat/autoload/neoformat.vim new file mode 100644 index 0000000..467fe24 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat.vim @@ -0,0 +1,303 @@ +function! neoformat#Neoformat(bang, user_input, start_line, end_line) abort + let search = @/ + let view = winsaveview() + let original_filetype = &filetype + + call s:neoformat(a:bang, a:user_input, a:start_line, a:end_line) + + let @/ = search + call winrestview(view) + let &filetype = original_filetype +endfunction + +function! s:neoformat(bang, user_input, start_line, end_line) abort + + if !&modifiable + return neoformat#utils#warn('buffer not modifiable') + endif + + let using_visual_selection = a:start_line != 1 || a:end_line != line('$') + + let inputs = split(a:user_input) + if a:bang + let &filetype = len(inputs) > 1 ? inputs[0] : a:user_input + endif + + let filetype = s:split_filetypes(&filetype) + + let using_user_passed_formatter = (!empty(a:user_input) && !a:bang) + \ || (len(inputs) > 1 && a:bang) + + if using_user_passed_formatter + let formatters = len(inputs) > 1 ? [inputs[1]] : [a:user_input] + else + let formatters = s:get_enabled_formatters(filetype) + if formatters == [] + call neoformat#utils#msg('formatter not defined for ' . filetype . ' filetype') + return s:basic_format() + endif + endif + + let formatters_failed = [] + let formatters_changed = [] + for formatter in formatters + + if &formatprg != '' && split(&formatprg)[0] ==# formatter + \ && get(g:, 'neoformat_try_formatprg', 0) + call neoformat#utils#log('using formatprg') + let fmt_prg_def = split(&formatprg) + let definition = { + \ 'exe': fmt_prg_def[0], + \ 'args': fmt_prg_def[1:], + \ 'stdin': 1, + \ } + elseif exists('b:neoformat_' . filetype . '_' . formatter) + let definition = b:neoformat_{filetype}_{formatter} + elseif exists('g:neoformat_' . filetype . '_' . formatter) + let definition = g:neoformat_{filetype}_{formatter} + elseif s:autoload_func_exists('neoformat#formatters#' . filetype . '#' . formatter) + let definition = neoformat#formatters#{filetype}#{formatter}() + else + call neoformat#utils#log('definition not found for formatter: ' . formatter) + if using_user_passed_formatter + call neoformat#utils#msg('formatter definition for ' . a:user_input . ' not found') + + return s:basic_format() + endif + continue + endif + + let cmd = s:generate_cmd(definition, filetype) + if cmd == {} + if using_user_passed_formatter + return neoformat#utils#warn('formatter ' . a:user_input . ' failed') + endif + continue + endif + + let stdin = getbufline(bufnr('%'), a:start_line, a:end_line) + let original_buffer = getbufline(bufnr('%'), 1, '$') + + call neoformat#utils#log(stdin) + + call neoformat#utils#log(cmd.exe) + if cmd.stdin + call neoformat#utils#log('using stdin') + let stdin_str = join(stdin, "\n") + let stdout = split(system(cmd.exe, stdin_str), '\n') + else + call neoformat#utils#log('using tmp file') + call writefile(stdin, cmd.tmp_file_path) + let stdout = split(system(cmd.exe), '\n') + endif + + " read from /tmp file if formatter replaces file on format + if cmd.replace + let stdout = readfile(cmd.tmp_file_path) + endif + + call neoformat#utils#log(stdout) + + call neoformat#utils#log(cmd.valid_exit_codes) + call neoformat#utils#log(v:shell_error) + + let process_ran_succesfully = index(cmd.valid_exit_codes, v:shell_error) != -1 + if process_ran_succesfully + " 1. append the lines that are before and after the formatterd content + let lines_after = getbufline(bufnr('%'), a:end_line + 1, '$') + let lines_before = getbufline(bufnr('%'), 1, a:start_line - 1) + + let new_buffer = lines_before + stdout + lines_after + if new_buffer !=# original_buffer + + call s:deletelines(len(new_buffer), line('$')) + + call setline(1, new_buffer) + + call add(formatters_changed, cmd.name) + let endmsg = cmd.name . ' formatted buffer' + else + + let endmsg = 'no change necessary with ' . cmd.name + endif + if !get(g:, 'neoformat_run_all_formatters', 0) + return neoformat#utils#msg(endmsg) + endif + call neoformat#utils#log('running next formatter') + else + call add(formatters_failed, cmd.name) + call neoformat#utils#log(v:shell_error) + call neoformat#utils#log('trying next formatter') + endif + endfor + if len(formatters_failed) > 0 + call neoformat#utils#msg('formatters ' . join(formatters_failed, ", ") . ' failed to run') + endif + if len(formatters_changed) > 0 + call neoformat#utils#msg(join(formatters_changed, ", ") . ' formatted buffer') + elseif len(formatters_failed) == 0 + call neoformat#utils#msg('no change necessary') + endif +endfunction + +function! s:get_enabled_formatters(filetype) abort + if &formatprg != '' && get(g:, 'neoformat_try_formatprg', 0) + call neoformat#utils#log('adding formatprg to enabled formatters') + let format_prg_exe = [split(&formatprg)[0]] + else + let format_prg_exe = [] + endif + + " Note: we append format_prg_exe to ever return as it will either be + " [], or it will be a formatter that we want to try first + + if exists('b:neoformat_enabled_' . a:filetype) + return format_prg_exe + b:neoformat_enabled_{a:filetype} + elseif exists('g:neoformat_enabled_' . a:filetype) + return format_prg_exe + g:neoformat_enabled_{a:filetype} + elseif s:autoload_func_exists('neoformat#formatters#' . a:filetype . '#enabled') + return format_prg_exe + neoformat#formatters#{a:filetype}#enabled() + endif + return format_prg_exe +endfunction + +function! s:deletelines(start, end) abort + silent! execute a:start . ',' . a:end . 'delete _' +endfunction + +function! neoformat#CompleteFormatters(ArgLead, CmdLine, CursorPos) abort + if a:CmdLine =~ '!' + " 1. user inputting formatter :Neoformat! css + if a:CmdLine =~# 'Neoformat! \S*\s' + let filetype = split(a:CmdLine)[1] + return filter(s:get_enabled_formatters(filetype), + \ "v:val =~? '^" . a:ArgLead ."'") + endif + + " 2. user inputting filetype :Neoformat! + " https://github.com/junegunn/fzf.vim/pull/110 + " 1. globpath (find) all filetype files in neoformat + " 2. split at new lines + " 3. map ~/.config/nvim/plugged/neoformat/autoload/neoformat/formatters/xml.vim --> xml + " 4. sort & uniq to eliminate dupes + " 5. filter for input + return filter(uniq(sort(map(split(globpath(&runtimepath, + \ 'plugged/neoformat/autoload/neoformat/formatters/*.vim'), '\n'), + \ "fnamemodify(v:val, ':t:r')"))), + \ "v:val =~? '^" . a:ArgLead . "'") + endif + if a:ArgLead =~ '[^A-Za-z0-9]' + return [] + endif + let filetype = s:split_filetypes(&filetype) + return filter(s:get_enabled_formatters(filetype), + \ "v:val =~? '^" . a:ArgLead ."'") +endfunction + +function! s:autoload_func_exists(func_name) abort + try + call eval(a:func_name . '()') + catch /^Vim\%((\a\+)\)\=:E/ + return 0 + endtry + return 1 +endfunction + +function! s:split_filetypes(filetype) abort + if a:filetype == '' + return '' + endif + return split(a:filetype, '\.')[0] +endfunction + +function! s:generate_cmd(definition, filetype) abort + let executable = get(a:definition, 'exe', '') + if executable == '' + call neoformat#utils#log('no exe field in definition') + return {} + endif + if !executable(executable) + call neoformat#utils#log('executable: ' . executable . ' is not an executable') + return {} + endif + + let args = get(a:definition, 'args', []) + let args_expanded = [] + for a in args + let args_expanded = add(args_expanded, s:expand_fully(a)) + endfor + + let no_append = get(a:definition, 'no_append', 0) + let using_stdin = get(a:definition, 'stdin', 0) + + let filename = expand('%:t') + + let tmp_dir = has('win32') ? expand('$TEMP/neoformat') : + \ exists('$TMPDIR') ? expand('$TMPDIR/neoformat') : + \ '/tmp/neoformat' + + if !isdirectory(tmp_dir) + call mkdir(tmp_dir, 'p') + endif + + if get(a:definition, 'replace', 0) + let path = !using_stdin ? expand(tmp_dir . '/' . fnameescape(filename)) : '' + else + let path = !using_stdin ? tempname() : '' + endif + + let inline_environment = get(a:definition, 'env', []) + let _fullcmd = join(inline_environment, ' ') . ' ' . executable . ' ' . join(args_expanded) . ' ' . (no_append ? '' : path) + " make sure there aren't any double spaces in the cmd + let fullcmd = join(split(_fullcmd)) + + return { + \ 'exe': fullcmd, + \ 'stdin': using_stdin, + \ 'name': a:definition.exe, + \ 'replace': get(a:definition, 'replace', 0), + \ 'tmp_file_path': path, + \ 'valid_exit_codes': get(a:definition, 'valid_exit_codes', [0]), + \ } +endfunction + +function! s:expand_fully(string) abort + return substitute(a:string, '%\(:[a-z]\)*', '\=expand(submatch(0))', 'g') +endfunction + +function! s:basic_format() abort + call neoformat#utils#log('running basic format') + if !exists('g:neoformat_basic_format_align') + let g:neoformat_basic_format_align = 0 + endif + + if !exists('g:neoformat_basic_format_retab') + let g:neoformat_basic_format_retab = 0 + endif + + if !exists('g:neoformat_basic_format_trim') + let g:neoformat_basic_format_trim = 0 + endif + + if g:neoformat_basic_format_align + call neoformat#utils#log('aligning with basic formatter') + let v = winsaveview() + silent! execute 'normal gg=G' + call winrestview(v) + endif + if g:neoformat_basic_format_retab + call neoformat#utils#log('converting tabs with basic formatter') + retab + endif + if g:neoformat_basic_format_trim + call neoformat#utils#log('trimming whitespace with basic formatter') + " http://stackoverflow.com/q/356126 + let search = @/ + let view = winsaveview() + " vint: -ProhibitCommandRelyOnUser -ProhibitCommandWithUnintendedSideEffect + silent! %s/\s\+$//e + " vint: +ProhibitCommandRelyOnUser +ProhibitCommandWithUnintendedSideEffect + let @/=search + call winrestview(view) + endif +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/arduino.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/arduino.vim new file mode 100644 index 0000000..c3901b9 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/arduino.vim @@ -0,0 +1,15 @@ +function! neoformat#formatters#arduino#enabled() abort + return ['uncrustify', 'clangformat', 'astyle'] +endfunction + +function! neoformat#formatters#arduino#uncrustify() abort + return neoformat#formatters#cpp#uncrustify() +endfunction + +function! neoformat#formatters#arduino#clangformat() abort + return neoformat#formatters#c#clangformat() +endfunction + +function! neoformat#formatters#arduino#astyle() abort + return neoformat#formatters#c#astyle() +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/bzl.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/bzl.vim new file mode 100644 index 0000000..6895686 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/bzl.vim @@ -0,0 +1,10 @@ +function! neoformat#formatters#bzl#enabled() abort + return ['buildifier'] +endfunction + +function! neoformat#formatters#bzl#buildifier() abort + return { + \ 'exe': 'buildifier', + \ 'stdin': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/c.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/c.vim new file mode 100644 index 0000000..dd694d3 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/c.vim @@ -0,0 +1,26 @@ +function! neoformat#formatters#c#enabled() abort + return ['uncrustify', 'clangformat', 'astyle'] +endfunction + +function! neoformat#formatters#c#uncrustify() abort + return { + \ 'exe': 'uncrustify', + \ 'args': ['-q', '-l C'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#c#clangformat() abort + return { + \ 'exe': 'clang-format', + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#c#astyle() abort + return { + \ 'exe': 'astyle', + \ 'args': ['--mode=c'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/cmake.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/cmake.vim new file mode 100644 index 0000000..aec99b5 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/cmake.vim @@ -0,0 +1,9 @@ +function! neoformat#formatters#cmake#enabled() abort + return ['cmakeformat'] +endfunction + +function! neoformat#formatters#cmake#cmakeformat() abort + return { + \ 'exe': 'cmake-format' + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/cpp.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/cpp.vim new file mode 100644 index 0000000..c6263f7 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/cpp.vim @@ -0,0 +1,20 @@ +function! neoformat#formatters#cpp#enabled() abort + return ['uncrustify', 'clangformat', 'astyle'] +endfunction + +function! neoformat#formatters#cpp#uncrustify() abort + return { + \ 'exe': 'uncrustify', + \ 'args': ['-q', '-l CPP'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#cpp#clangformat() abort + return neoformat#formatters#c#clangformat() +endfunction + +function! neoformat#formatters#cpp#astyle() abort + return neoformat#formatters#c#astyle() +endfunction + diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/crystal.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/crystal.vim new file mode 100644 index 0000000..d8c9099 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/crystal.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#crystal#enabled() abort + return ['crystalformat'] +endfunction + +function! neoformat#formatters#crystal#crystalformat() abort + return { + \ 'exe': 'crystal', + \ 'args': ['tool', 'format'], + \ 'replace': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/cs.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/cs.vim new file mode 100644 index 0000000..7827a48 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/cs.vim @@ -0,0 +1,19 @@ +function! neoformat#formatters#cs#enabled() abort + return ['uncrustify', 'astyle'] +endfunction + +function! neoformat#formatters#cs#uncrustify() abort + return { + \ 'exe': 'uncrustify', + \ 'args': ['-q', '-l CS'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#cs#astyle() abort + return { + \ 'exe': 'astyle', + \ 'args': ['--mode=cs'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/css.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/css.vim new file mode 100644 index 0000000..a563136 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/css.vim @@ -0,0 +1,46 @@ +function! neoformat#formatters#css#enabled() abort + return ['stylefmt', 'prettier', 'cssbeautify', 'prettydiff', 'csscomb'] +endfunction + +function! neoformat#formatters#css#cssbeautify() abort + return { + \ 'exe': 'css-beautify', + \ 'args': ['--indent-size ' .shiftwidth()], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#css#csscomb() abort + return { + \ 'exe': 'csscomb', + \ 'replace': 1 + \ } +endfunction + +function! neoformat#formatters#css#prettydiff() abort + return { + \ 'exe': 'prettydiff', + \ 'args': ['mode:"beautify"', + \ 'lang:"css"', + \ 'insize:' .shiftwidth(), + \ 'readmethod:"filescreen"', + \ 'endquietly:"quiet"', + \ 'source:"%:p"'], + \ 'no_append': 1 + \ } +endfunction + +function! neoformat#formatters#css#stylefmt() abort + return { + \ 'exe': 'stylefmt', + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#css#prettier() abort + return { + \ 'exe': 'prettier', + \ 'args': ['--stdin', '--parser', 'css'], + \ 'stdin': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/csv.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/csv.vim new file mode 100644 index 0000000..57a2f0b --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/csv.vim @@ -0,0 +1,15 @@ +function! neoformat#formatters#csv#enabled() abort + return ['prettydiff'] +endfunction + +function! neoformat#formatters#csv#prettydiff() abort + return { + \ 'exe': 'prettydiff', + \ 'args': ['mode:"beautify"', + \ 'lang:"csv"', + \ 'readmethod:"filescreen"', + \ 'endquietly:"quiet"', + \ 'source:"%:p"'], + \ 'no_append': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/d.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/d.vim new file mode 100644 index 0000000..e841302 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/d.vim @@ -0,0 +1,18 @@ +function! neoformat#formatters#d#enabled() abort + return ['uncrustify', 'dfmt'] +endfunction + +function! neoformat#formatters#d#dfmt() abort + return { + \ 'exe': 'dfmt', + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#d#uncrustify() abort + return { + \ 'exe': 'uncrustify', + \ 'args': ['-q', '-l D'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/dart.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/dart.vim new file mode 100644 index 0000000..0f32faf --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/dart.vim @@ -0,0 +1,10 @@ +function! neoformat#formatters#dart#enabled() abort + return ['dartfmt'] +endfunction + +function! neoformat#formatters#dart#dartfmt() abort + return { + \ 'exe': 'dartfmt', + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/elixir.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/elixir.vim new file mode 100644 index 0000000..575e279 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/elixir.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#elixir#enabled() abort + return ['mixformat'] +endfunction + +function! neoformat#formatters#elixir#mixformat() abort + return { + \ 'exe': 'mix', + \ 'args': ['format', "-"], + \ 'stdin': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/elm.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/elm.vim new file mode 100644 index 0000000..f443595 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/elm.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#elm#enabled() abort + return ['elmformat'] +endfunction + +function! neoformat#formatters#elm#elmformat() abort + return { + \ 'exe': 'elm-format', + \ 'args': ['--stdin'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/fish.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/fish.vim new file mode 100644 index 0000000..63989a1 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/fish.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#fish#enabled() abort + return ['fish_indent'] +endfunction + +function! neoformat#formatters#fish#fish_indent() abort + return { + \ 'exe': 'fish_indent', + \ 'stdin': 1, + \ } +endfunction + diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/go.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/go.vim new file mode 100644 index 0000000..33387ff --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/go.vim @@ -0,0 +1,18 @@ +function! neoformat#formatters#go#enabled() abort + return ['goimports', 'gofmt'] +endfunction + +function! neoformat#formatters#go#gofmt() abort + return { + \ 'exe': 'gofmt', + \ 'stdin': 1, + \ } + endfunction + +function! neoformat#formatters#go#goimports() abort + return { + \ 'exe': 'goimports', + \ 'stdin': 1, + \ } +endfunction + diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/graphql.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/graphql.vim new file mode 100644 index 0000000..29dc9d7 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/graphql.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#graphql#enabled() abort + return ['prettier'] +endfunction + +function! neoformat#formatters#graphql#prettier() abort + return { + \ 'exe': 'prettier', + \ 'args': ['--stdin', '--parser', 'graphql'], + \ 'stdin': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/haskell.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/haskell.vim new file mode 100644 index 0000000..b0692ce --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/haskell.vim @@ -0,0 +1,34 @@ +function! neoformat#formatters#haskell#enabled() abort + return ['hindent', 'stylishhaskell', 'hfmt', 'brittany'] +endfunction + +function! neoformat#formatters#haskell#hindent() abort + return { + \ 'exe' : 'hindent', + \ 'args': ['--indent-size ' . shiftwidth(), '--line-length 80'], + \ 'stdin' : 1, + \ } +endfunction + +function! neoformat#formatters#haskell#stylishhaskell() abort + return { + \ 'exe': 'stylish-haskell', + \ 'args': ['2>/dev/null'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#haskell#hfmt() abort + return { + \ 'exe': 'hfmt', + \ 'args': ['-'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#haskell#brittany() abort + return { + \ 'exe': 'brittany', + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/html.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/html.vim new file mode 100644 index 0000000..c14a68e --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/html.vim @@ -0,0 +1,36 @@ +function! neoformat#formatters#html#enabled() abort + return ['htmlbeautify', 'tidy', 'prettydiff'] +endfunction + +function! neoformat#formatters#html#tidy() abort + return { + \ 'exe': 'tidy', + \ 'args': ['-quiet', + \ '--indent auto', + \ '--indent-spaces ' . shiftwidth(), + \ '--vertical-space yes', + \ '--tidy-mark no', + \ '-wrap ' . &textwidth + \ ] + \ } +endfunction + +function! neoformat#formatters#html#htmlbeautify() abort + return { + \ 'exe': 'html-beautify', + \ 'args': ['--indent-size ' .shiftwidth()], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#html#prettydiff() abort + return { + \ 'exe': 'prettydiff', + \ 'args': ['mode:"beautify"', + \ 'lang:"html"', + \ 'readmethod:"filescreen"', + \ 'endquietly:"quiet"', + \ 'source:"%:p"'], + \ 'no_append': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/jade.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/jade.vim new file mode 100644 index 0000000..083b21c --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/jade.vim @@ -0,0 +1,7 @@ +function! neoformat#formatters#jade#enabled() abort + return ['pugbeautifier'] +endfunction + +function! neoformat#formatters#jade#pugbeautifier() abort + return neoformat#formatters#pug#pugbeautifier() +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/java.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/java.vim new file mode 100644 index 0000000..bf3f396 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/java.vim @@ -0,0 +1,30 @@ +function! neoformat#formatters#java#enabled() abort + return ['uncrustify', 'astyle', 'clang-format'] +endfunction + +function! neoformat#formatters#java#uncrustify() abort + return { + \ 'exe': 'uncrustify', + \ 'args': ['-q', '-l JAVA'], + \ 'stdin': 1, + \ } +endfunction + + +function! neoformat#formatters#java#astyle() abort + return { + \ 'exe': 'astyle', + \ 'args': ['--mode=java'], + \ 'stdin': 1, + \ } +endfunction + + +function! neoformat#formatters#java#clangformat() abort + return { + \ 'exe': 'clang-format', + \ 'stdin': 1, + \ } +endfunction + + diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/javascript.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/javascript.vim new file mode 100644 index 0000000..bbcfa18 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/javascript.vim @@ -0,0 +1,69 @@ +function! neoformat#formatters#javascript#enabled() abort + return ['jsbeautify', 'standard', 'prettier', 'prettydiff', 'clangformat', 'esformatter', 'prettiereslint', 'eslint_d'] +endfunction + +function! neoformat#formatters#javascript#jsbeautify() abort + return { + \ 'exe': 'js-beautify', + \ 'args': ['--indent-size ' .shiftwidth()], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#javascript#clangformat() abort + return { + \ 'exe': 'clang-format', + \ 'stdin': 1 + \ } +endfunction + +function! neoformat#formatters#javascript#prettydiff() abort + return { + \ 'exe': 'prettydiff', + \ 'args': ['mode:"beautify"', + \ 'lang:"javascript"', + \ 'readmethod:"filescreen"', + \ 'endquietly:"quiet"', + \ 'source:"%:p"'], + \ 'no_append': 1 + \ } +endfunction + +function! neoformat#formatters#javascript#esformatter() abort + return { + \ 'exe': 'esformatter', + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#javascript#prettier() abort + return { + \ 'exe': 'prettier', + \ 'args': ['--stdin', '--stdin-filepath', '%:p'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#javascript#prettiereslint() abort + return { + \ 'exe': 'prettier-eslint', + \ 'args': ['--stdin', '--stdin-filepath', '%:p'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#javascript#eslint_d() abort + return { + \ 'exe': 'eslint_d', + \ 'args': ['--stdin','--fix-to-stdout'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#javascript#standard() abort + return { + \ 'exe': 'standard', + \ 'args': ['--stdin','--fix'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/jinja.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/jinja.vim new file mode 100644 index 0000000..caf0a16 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/jinja.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#jinja#enabled() abort + return ['prettydiff', 'htmlbeautify'] +endfunction + +function! neoformat#formatters#jinja#htmlbeautify() abort + return neoformat#formatters#html#htmlbeautify() +endfunction + +function! neoformat#formatters#jinja#prettydiff() abort + return neoformat#formatters#html#prettydiff() +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/json.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/json.vim new file mode 100644 index 0000000..3c3511e --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/json.vim @@ -0,0 +1,35 @@ +function! neoformat#formatters#json#enabled() abort + return ['jsbeautify', 'prettydiff', 'jq', 'prettier'] +endfunction + +function! neoformat#formatters#json#jsbeautify() abort + return neoformat#formatters#javascript#jsbeautify() +endfunction + +function! neoformat#formatters#json#prettydiff() abort + return neoformat#formatters#javascript#prettydiff() +endfunction + +function! neoformat#formatters#json#jq() abort + return { + \ 'exe': 'jq', + \ 'args': ['.'], + \ } +endfunction + +function! neoformat#formatters#json#prettier() abort + return { + \ 'exe': 'prettier', + \ 'args': ['--stdin', '--parser', 'json'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#json#fixjson() abort + let l:filename = fnamemodify(bufname('%'), ':t') + return { + \ 'exe': 'fixjson', + \ 'args': ['--stdin-filename', l:filename], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/kotlin.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/kotlin.vim new file mode 100644 index 0000000..c2fd000 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/kotlin.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#kotlin#enabled() abort + return ['ktlint'] +endfunction + +function! neoformat#formatters#kotlin#ktlint() abort + return { + \ 'exe': 'ktlint', + \ 'args': ['-F'], + \ 'replace': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/less.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/less.vim new file mode 100644 index 0000000..ad18447 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/less.vim @@ -0,0 +1,15 @@ +function! neoformat#formatters#less#enabled() abort + return ['prettier', 'csscomb', 'prettydiff'] +endfunction + +function! neoformat#formatters#less#csscomb() abort + return neoformat#formatters#css#csscomb() +endfunction + +function! neoformat#formatters#less#prettydiff() abort + return neoformat#formatters#css#prettydiff() +endfunction + +function! neoformat#formatters#less#prettier() abort + return neoformat#formatters#css#prettier() +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/lua.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/lua.vim new file mode 100644 index 0000000..744bdcc --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/lua.vim @@ -0,0 +1,9 @@ +function! neoformat#formatters#lua#enabled() abort + return ['luaformatter'] +endfunction + +function! neoformat#formatters#lua#luaformatter() abort + return { + \ 'exe': 'luaformatter' + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/markdown.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/markdown.vim new file mode 100644 index 0000000..dba0584 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/markdown.vim @@ -0,0 +1,19 @@ +function! neoformat#formatters#markdown#enabled() abort + return ['remark', 'prettier'] +endfunction + +function! neoformat#formatters#markdown#prettier() abort + return { + \ 'exe': 'prettier', + \ 'args': ['--stdin', '--stdin-filepath', '%:p'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#markdown#remark() abort + return { + \ 'exe': 'remark', + \ 'args': ['--no-color', '--silent'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/objc.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/objc.vim new file mode 100644 index 0000000..2075abd --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/objc.vim @@ -0,0 +1,20 @@ +function! neoformat#formatters#objc#enabled() abort + return ['uncrustify', 'clangformat', 'astyle'] +endfunction + +function! neoformat#formatters#objc#uncrustify() abort + return { + \ 'exe': 'uncrustify', + \ 'args': ['-q', '-l OC+'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#objc#clangformat() abort + return neoformat#formatters#c#clangformat() +endfunction + +function! neoformat#formatters#objc#astyle() abort + return neoformat#formatters#c#astyle() +endfunction + diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/ocaml.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/ocaml.vim new file mode 100644 index 0000000..34da781 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/ocaml.vim @@ -0,0 +1,16 @@ +function! neoformat#formatters#ocaml#enabled() abort + return ['ocamlformat', 'ocpindent'] +endfunction + +function! neoformat#formatters#ocaml#ocpindent() abort + return { + \ 'exe': 'ocp-indent', + \ } +endfunction + +function! neoformat#formatters#ocaml#ocamlformat() abort + return { + \ 'exe': 'ocamlformat', + \ 'args': ['--name', '%:p'] + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/pandoc.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/pandoc.vim new file mode 100644 index 0000000..d27fa41 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/pandoc.vim @@ -0,0 +1,39 @@ +function! neoformat#formatters#pandoc#enabled() abort + return ['pandoc'] +endfunction + +function! neoformat#formatters#pandoc#pandoc() abort + let l:input_flags = ['markdown', + \ '+abbreviations', + \ '+autolink_bare_uris', + \ '+markdown_attribute', + \ '+mmd_header_identifiers', + \ '+mmd_link_attributes', + \ '+tex_math_double_backslash', + \ '+emoji', + \ ] + + let l:target_flags = ['markdown', + \ '+raw_tex', + \ '-native_spans', + \ '-simple_tables', + \ '-multiline_tables', + \ '+emoji', + \ ] + + " The sed is to make checkboxes not get escaped. + return { + \ 'exe': 'pandoc', + \ 'args': ['-f' , + \ join(l:input_flags,''), + \ '-t', + \ join(l:target_flags,''), + \ '-s', + \ '--wrap=auto', + \ '--atx-headers', + \ '|', + \ "sed -e 's/\\\\\\[/[/g'", "-e 's/\\\\\\]/]/g'",], + \ 'stdin': 1, + \ } +endfunction + diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/pawn.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/pawn.vim new file mode 100644 index 0000000..051a823 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/pawn.vim @@ -0,0 +1,12 @@ +function! neoformat#formatters#pawn#enabled() abort + return ['uncrustify'] +endfunction + +function! neoformat#formatters#pawn#uncrustify() abort + return { + \ 'exe': 'uncrustify', + \ 'args': ['-q', '-l PAWN'], + \ 'stdin': 1, + \ } +endfunction + diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/perl.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/perl.vim new file mode 100644 index 0000000..953bfeb --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/perl.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#perl#enabled() abort + return ['perltidy'] +endfunction + +function! neoformat#formatters#perl#perltidy() abort + return { + \ 'exe': 'perltidy', + \ 'args': ['-q'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/php.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/php.vim new file mode 100644 index 0000000..6451cfe --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/php.vim @@ -0,0 +1,17 @@ +function! neoformat#formatters#php#enabled() abort + return ['phpbeautifier', 'phpcsfixer'] +endfunction + +function! neoformat#formatters#php#phpbeautifier() abort + return { + \ 'exe': 'php_beautifier', + \ } +endfunction + +function! neoformat#formatters#php#phpcsfixer() abort + return { + \ 'exe': 'php-cs-fixer', + \ 'args': ['fix', '-q'], + \ 'replace': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/proto.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/proto.vim new file mode 100644 index 0000000..0339066 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/proto.vim @@ -0,0 +1,7 @@ +function! neoformat#formatters#proto#enabled() abort + return ['clangformat'] +endfunction + +function! neoformat#formatters#proto#clangformat() abort + return neoformat#formatters#c#clangformat() +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/pug.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/pug.vim new file mode 100644 index 0000000..1bfebd0 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/pug.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#pug#enabled() abort + return ['pugbeautifier'] +endfunction + +function! neoformat#formatters#pug#pugbeautifier() abort + return { + \ 'exe': 'pug-beautifier', + \ 'args': ['-s 2'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/python.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/python.vim new file mode 100644 index 0000000..7d8cd1f --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/python.vim @@ -0,0 +1,44 @@ +function! neoformat#formatters#python#enabled() abort + return ['yapf', 'autopep8', 'black', 'isort', 'docformatter'] +endfunction + +function! neoformat#formatters#python#yapf() abort + return { + \ 'exe': 'yapf', + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#python#autopep8() abort + return { + \ 'exe': 'autopep8', + \ 'args': ['-'], + \ 'stdin': 1, + \ } +endfunction + + +function! neoformat#formatters#python#isort() abort + return { + \ 'exe': 'isort', + \ 'args': ['-', '--quiet'], + \ 'stdin': 1, + \ } +endfunction + + +function! neoformat#formatters#python#docformatter() abort + return { + \ 'exe': 'docformatter', + \ 'args': ['-',], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#python#black() abort + return { + \ 'exe': 'black', + \ 'stdin': 1, + \ 'args': ['-', '2>/dev/null'], + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/reason.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/reason.vim new file mode 100644 index 0000000..24f0d0a --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/reason.vim @@ -0,0 +1,10 @@ +function! neoformat#formatters#reason#enabled() abort + return ['refmt'] +endfunction + +function! neoformat#formatters#reason#refmt() abort + return { + \ 'exe': 'refmt', + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/ruby.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/ruby.vim new file mode 100644 index 0000000..86ed4f8 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/ruby.vim @@ -0,0 +1,26 @@ +function! neoformat#formatters#ruby#enabled() abort + return ['rufo', 'rubybeautify', 'rubocop'] +endfunction + +function! neoformat#formatters#ruby#rufo() abort + return { + \ 'exe': 'rufo', + \ 'stdin': 1, + \ 'valid_exit_codes': [0, 3] + \ } +endfunction + +function! neoformat#formatters#ruby#rubybeautify() abort + return { + \ 'exe': 'ruby-beautify', + \ 'args': ['--spaces', '-c ' . shiftwidth()], + \ } +endfunction + +function! neoformat#formatters#ruby#rubocop() abort + return { + \ 'exe': 'rubocop', + \ 'args': ['--auto-correct', '--stdin', '%:p', '2>/dev/null', '|', 'sed "1,/^====================$/d"'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/rust.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/rust.vim new file mode 100644 index 0000000..7625423 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/rust.vim @@ -0,0 +1,10 @@ +function! neoformat#formatters#rust#enabled() abort + return ['rustfmt'] +endfunction + +function! neoformat#formatters#rust#rustfmt() abort + return { + \ 'exe': 'rustfmt', + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/sass.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/sass.vim new file mode 100644 index 0000000..4d4e915 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/sass.vim @@ -0,0 +1,16 @@ +function! neoformat#formatters#sass#enabled() abort + return ['sassconvert', 'csscomb'] +endfunction + +function! neoformat#formatters#sass#sassconvert() abort + return { + \ 'exe': 'sass-convert', + \ 'args': ['-F sass', '-T sass', '-s'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#sass#csscomb() abort + return neoformat#formatters#css#csscomb() +endfunction + diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/scala.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/scala.vim new file mode 100644 index 0000000..d547d82 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/scala.vim @@ -0,0 +1,19 @@ +function! neoformat#formatters#scala#enabled() abort + return ['scalariform', 'scalafmt'] +endfunction + +function! neoformat#formatters#scala#scalariform() abort + return { + \ 'exe': 'scalariform', + \ 'args': ['--stdin'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#scala#scalafmt() abort + return { + \ 'exe': 'scalafmt', + \ 'args': ['--stdin'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/scss.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/scss.vim new file mode 100644 index 0000000..9a96334 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/scss.vim @@ -0,0 +1,27 @@ +function! neoformat#formatters#scss#enabled() abort + return ['sassconvert', 'stylefmt', 'prettier', 'prettydiff', 'csscomb'] +endfunction + +function! neoformat#formatters#scss#sassconvert() abort + return { + \ 'exe': 'sass-convert', + \ 'args': ['-F scss', '-T scss', '--indent ' . (&expandtab ? shiftwidth() : 't')], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#scss#csscomb() abort + return neoformat#formatters#css#csscomb() +endfunction + +function! neoformat#formatters#scss#prettydiff() abort + return neoformat#formatters#css#prettydiff() +endfunction + +function! neoformat#formatters#scss#stylefmt() abort + return neoformat#formatters#css#stylefmt() +endfunction + +function! neoformat#formatters#scss#prettier() abort + return neoformat#formatters#css#prettier() +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/sh.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/sh.vim new file mode 100644 index 0000000..6999613 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/sh.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#sh#enabled() abort + return ['shfmt'] +endfunction + +function! neoformat#formatters#sh#shfmt() abort + return { + \ 'exe': 'shfmt', + \ 'args': ['-i ' . shiftwidth()], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/sql.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/sql.vim new file mode 100644 index 0000000..4197764 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/sql.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#sql#enabled() abort + return ['sqlformat'] +endfunction + +function! neoformat#formatters#sql#sqlformat() abort + return { + \ 'exe': 'sqlformat', + \ 'args': ['--reindent', '-'], + \ 'stdin': 1, + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/terraform.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/terraform.vim new file mode 100644 index 0000000..7ee6a73 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/terraform.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#terraform#enabled() abort + return ['terraform'] +endfunction + +function! neoformat#formatters#terraform#terraform() abort + return { + \ 'exe': 'terraform', + \ 'args': ['fmt', '-write', '-'], + \ 'stdin': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/tex.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/tex.vim new file mode 100644 index 0000000..2422336 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/tex.vim @@ -0,0 +1,12 @@ +function! neoformat#formatters#tex#enabled() abort + return ['latexindent'] +endfunction + +function! neoformat#formatters#tex#latexindent() abort + return { + \ 'exe': 'latexindent', + \ 'args': ['-l', '-w'], + \ 'stdin': 0, + \ 'replace': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/typescript.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/typescript.vim new file mode 100644 index 0000000..87cbd84 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/typescript.vim @@ -0,0 +1,19 @@ +function! neoformat#formatters#typescript#enabled() abort + return ['tsfmt', 'prettier'] +endfunction + +function! neoformat#formatters#typescript#tsfmt() abort + return { + \ 'exe': 'tsfmt', + \ 'args': ['--stdin', '%:p'], + \ 'stdin': 1 + \ } +endfunction + +function! neoformat#formatters#typescript#prettier() abort + return { + \ 'exe': 'prettier', + \ 'args': ['--stdin', '--parser', 'typescript'], + \ 'stdin': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/vala.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/vala.vim new file mode 100644 index 0000000..dfb7e85 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/vala.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#vala#uncrustify() abort + return { + \ 'exe': 'uncrustify', + \ 'args': ['-q', '-l VALA'], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#vala#enabled() abort + return ['uncrustify'] +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/vue.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/vue.vim new file mode 100644 index 0000000..bdd47ef --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/vue.vim @@ -0,0 +1,11 @@ +function! neoformat#formatters#vue#enabled() abort + return ['prettier'] +endfunction + +function! neoformat#formatters#vue#prettier() abort + return { + \ 'exe': 'prettier', + \ 'args': ['--stdin', '--parser', 'vue'], + \ 'stdin': 1 + \ } +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/xhtml.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/xhtml.vim new file mode 100644 index 0000000..885e884 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/xhtml.vim @@ -0,0 +1,21 @@ +function! neoformat#formatters#xhtml#enabled() abort + return ['tidy', 'prettydiff'] +endfunction + +function! neoformat#formatters#xhtml#tidy() abort + return { + \ 'exe': 'tidy', + \ 'args': ['-quiet', + \ '-asxhtml', + \ '--indent auto', + \ '--indent-spaces '. shiftwidth(), + \ '--vertical-space yes', + \ '--tidy-mark no' + \ ], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#xhtml#prettydiff() abort + return neoformat#formatters#html#prettydiff() +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/xml.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/xml.vim new file mode 100644 index 0000000..8ea018a --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/xml.vim @@ -0,0 +1,21 @@ +function! neoformat#formatters#xml#enabled() abort + return ['tidy', 'prettydiff'] +endfunction + +function! neoformat#formatters#xml#tidy() abort + return { + \ 'exe': 'tidy', + \ 'args': ['-quiet', + \ '-xml', + \ '--indent auto', + \ '--indent-spaces ' . shiftwidth(), + \ '--vertical-space yes', + \ '--tidy-mark no' + \ ], + \ 'stdin': 1, + \ } +endfunction + +function! neoformat#formatters#xml#prettydiff() abort + return neoformat#formatters#html#prettydiff() +endfunction diff --git a/vim/bundle/neoformat/autoload/neoformat/formatters/yaml.vim b/vim/bundle/neoformat/autoload/neoformat/formatters/yaml.vim new file mode 100644 index 0000000..617f902 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/formatters/yaml.vim @@ -0,0 +1,12 @@ +function! neoformat#formatters#yaml#enabled() abort + return ['pyaml'] +endfunction + +function! neoformat#formatters#yaml#pyaml() abort + return { + \ 'exe': 'python3', + \ 'args': ['-m', 'pyaml'], + \ 'stdin': 1, + \ } +endfunction + diff --git a/vim/bundle/neoformat/autoload/neoformat/utils.vim b/vim/bundle/neoformat/autoload/neoformat/utils.vim new file mode 100644 index 0000000..416efa7 --- /dev/null +++ b/vim/bundle/neoformat/autoload/neoformat/utils.vim @@ -0,0 +1,27 @@ +function! neoformat#utils#log(msg) abort + if !exists('g:neoformat_verbose') + let g:neoformat_verbose = 0 + endif + if &verbose || g:neoformat_verbose + return s:better_echo(a:msg) + endif +endfunction + +function! neoformat#utils#warn(msg) abort + echohl WarningMsg | call s:better_echo(a:msg) | echohl NONE +endfunction + +function! neoformat#utils#msg(msg) abort + if exists('g:neoformat_only_msg_on_error') && g:neoformat_only_msg_on_error + return + endif + return s:better_echo(a:msg) +endfunction + +function! s:better_echo(msg) abort + if type(a:msg) != type('') + echom 'Neoformat: ' . string(a:msg) + else + echom 'Neoformat: ' . a:msg + endif +endfunction diff --git a/vim/bundle/neoformat/doc/neoformat.txt b/vim/bundle/neoformat/doc/neoformat.txt new file mode 100644 index 0000000..d6587b5 --- /dev/null +++ b/vim/bundle/neoformat/doc/neoformat.txt @@ -0,0 +1,351 @@ +*neoformat.txt* A Neovim plugin for formatting. + +CONTENTS *neoformat-contents* + +Introduction |neoformat-introduction| +Install |neoformat-install| +Usage |neoformat-usage| +Managing Undo History |neoformat-managing-undo-history| +Supported Filetypes |neoformat-supported-filetypes| + +============================================================================== +INTRODUCTION *neoformat-introduction* + +A [Neovim](https://neovim.io) and Vim8 plugin for formatting code. + +*Neoformat* uses a variety of formatters for many filetypes. Currently, Neoformat +will run a formatter using the current buffer data, and on success it will +update the current buffer with the formatted text. On a formatter failure, +Neoformat will try the next formatter defined for the filetype. + +By using `getbufline()` to read from the current buffer instead of file, +Neoformat is able to format your buffer without you having to `:w` your file first. +Also, by using `setline()`, marks, jumps, etc. are all maintained after formatting. + +Neoformat supports both sending buffer data to formatters via stdin, and also +writing buffer data to `/tmp/` for formatters to read that do not support input +via stdin. + +============================================================================== +INSTALL *neoformat-install* + +Install with [vim-plug](https://github.com/junegunn/vim-plug) +> + Plug 'sbdchd/neoformat' +< +============================================================================== +USAGE *neoformat-usage* + +Format the entire buffer, or visual selection of the buffer +> + :Neoformat + + + :Neoformat jsbeautify + +Or format a visual selection of code in a different filetype + +*Note:* you must use a ! and pass the filetype of the selection + +> + :Neoformat! python +> +You can also pass a formatter to use + +> + :Neoformat! python yapf +< + +Or perhaps run a formatter on save + +> + augroup fmt + autocmd! + autocmd BufWritePre * undojoin | Neoformat + augroup END +< + +The |undojoin| command will put changes made by Neoformat into the same +|undo-block| with the latest preceding change. See +|neoformat-managing-undo-history|. + + +============================================================================== +CURRENT LIMITATION(S) *neoformat-limitations* + +If a formatter is either not configured to use `stdin`, or is not able to read +from `stdin`, then buffer data will be written to a file in `/tmp/neoformat/`, +where the formatter will then read from + +============================================================================== +CONFIG *neoformat-config* + +Define custom formatters. + +Options: + +| `exe` | the name the formatter executable in the path | required +| `args` | list of arguments | default: [] | optional +| `replace` | overwrite the file, instead of updating the buffer | default: 0 | optional +| `stdin` | send data to the stdin of the formatter | default 0 | optional +| `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 | default: 0 | + optional +| `env` | list of environment variables to prepend to the command | default: [] | optional + +| `valid_exit_codes` | list of valid exit codes for formatters who do not respect common unix practices | \[0] | optional + +Example: + +Define custom formatters. +> + let g:neoformat_python_autopep8 = { + \ 'exe': 'autopep8', + \ 'args': ['-s 4', '-E'], + \ 'replace': 1 " replace the file, instead of updating buffer (default: 0), + \ 'stdin': 1, " send data to stdin of formatter (default: 0) + \ 'valid_exit_codes': [0, 23], + \ 'no_append': 1, + \ } + + let g:neoformat_enabled_python = ['autopep8'] +< +Have Neoformat use &formatprg as a formatter +> + let g:neoformat_try_formatprg = 1 +< +Enable basic formatting when a filetype is not found. Disabled by default. +> + " Enable alignment + let g:neoformat_basic_format_align = 1 + + " Enable tab to spaces conversion + let g:neoformat_basic_format_retab = 1 + + " Enable trimmming of trailing whitespace + let g:neoformat_basic_format_trim = 1 + +Run all enabled formatters (by default Neoformat stops after the first +formatter succeeds) + + let g:neoformat_run_all_formatters = 1 + +Have Neoformat only msg when there is an error +> + let g:neoformat_only_msg_on_error = 1 +< +When debugging, you can enable either of following variables for extra logging. +> + let g:neoformat_verbose = 1 " only affects the verbosity of Neoformat + " Or + let &verbose = 1 " also increases verbosity of the editor as a whole +< +============================================================================== +ADDING A NEW FORMATTER *neoformat-adding-new-formatter* + +Note: you should replace everything `{{ }}` accordingly + +1. Create a file in `autoload/neoformat/formatters/{{ filetype }}.vim` if it does not + already exist for your filetype. + +2. Follow the following format + +See Config above for options +> + function! neoformat#formatters#{{ filetype }}#enabled() abort + return ['{{ formatter name }}', '{{ other formatter name for filetype }}'] + endfunction + + function! neoformat#formatters#{{ filetype }}#{{ formatter name }}() abort + return { + \ 'exe': '{{ formatter name }}', + \ 'args': ['-s 4', '-q'], + \ 'stdin': 1 + \ } + endfunction + + function! neoformat#formatters#{{ filetype }}#{{ other formatter name }}() abort + return {'exe': {{ other formatter name }} + endfunction +< + +============================================================================== +MANAGING UNDO HISTORY *neoformat-managing-undo-history* + +If you use an |autocmd| to run Neoformat on save, and you have your editor +configured to save automatically on |CursorHold| then you might run into +problems reverting changes. Pressing |u| will undo the last change made by +Neoformat instead of the change that you made yourself - and then Neoformat +will run again redoing the change that you just reverted. To avoid this +problem you can run Neoformat with the Vim |undojoin| command to put changes +made by Neoformat into the same |undo-block| with the preceding change. For +example: + +> + augroup fmt + autocmd! + autocmd BufWritePre * undojoin | Neoformat + augroup END +< + +When |undojoin| is used this way pressing |u| will "skip over" the Neoformat +changes - it will revert both the changes made by Neoformat and the change +that caused Neoformat to be invoked. + +============================================================================== +SUPPORTED FILETYPES *neoformat-supported-filetypes* + +- Arduino + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html), + [`astyle`](http://astyle.sourceforge.net) +- Bazel + - [`buildifier`](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md) +- C + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html), + [`astyle`](http://astyle.sourceforge.net) +- C# + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`astyle`](http://astyle.sourceforge.net) +- C++ + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html), + [`astyle`](http://astyle.sourceforge.net) +- CMake + - [`cmake_format`](https://github.com/cheshirekow/cmake_format) +- Crystal + - `crystal tool format` (ships with [`crystal`](http://crystal-lang.org)) +- CSS + - `css-beautify` (ships with [`js-beautify`](https://github.com/beautify-web/js-beautify)), + [`prettier`](https://github.com/prettier/prettier), + [`prettydiff`](https://github.com/prettydiff/prettydiff), + [`stylefmt`](https://github.com/morishitter/stylefmt), + [`csscomb`](http://csscomb.com) +- CSV + - [`prettydiff`](https://github.com/prettydiff/prettydiff) +- D + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`dfmt`](https://github.com/Hackerpilot/dfmt) +- Dart + - [`dartfmt`](https://www.dartlang.org/tools/) +- Elixir + - [mix format](https://hexdocs.pm/mix/master/Mix.Tasks.Format.html) +- Elm + - [`elm-format`](https://github.com/avh4/elm-format) +- Fish + - [`fish_indent`](http://fishshell.com) +- Go + - [`gofmt`](https://golang.org/cmd/gofmt/), + [`goimports`](https://godoc.org/golang.org/x/tools/cmd/goimports) +- GraphQL + - [`prettier`](https://github.com/prettier/prettier) +- Haskell + - [`stylish-haskell`](https://github.com/jaspervdj/stylish-haskell) + - [`hindent`](https://github.com/chrisdone/hindent) + - [`hfmt`](https://github.com/danstiner/hfmt) + - [`brittany`](https://github.com/lspitzner/brittany) +- HTML + - `html-beautify` (ships with [`js-beautify`](https://github.com/beautify-web/js-beautify)), + [`prettydiff`](https://github.com/prettydiff/prettydiff) +- Jade + - [`pug-beautifier`](https://github.com/vingorius/pug-beautifier) +- Java + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`astyle`](http://astyle.sourceforge.net) +- Javascript + - [`js-beautify`](https://github.com/beautify-web/js-beautify), + [`prettier`](https://github.com/jlongster/prettier), + [`prettydiff`](https://github.com/prettydiff/prettydiff), + [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html), + [`esformatter`](https://github.com/millermedeiros/esformatter/), + [`prettier-eslint`](https://github.com/kentcdodds/prettier-eslint-cli), + [`standard`](https://standardjs.com/) +- JSON + - [`js-beautify`](https://github.com/beautify-web/js-beautify), + [`prettydiff`](https://github.com/prettydiff/prettydiff), + [`prettier`](https://github.com/prettier/prettier), + [`jq`](https://stedolan.github.io/jq/), + [`fixjson`](https://github.com/rhysd/fixjson) +- Kotlin + - [`ktlint`](https://github.com/shyiko/ktlint) +- LaTeX + - [`latexindent`](https://github.com/cmhughes/latexindent.pl) +- Less + - [`csscomb`](http://csscomb.com), + [`prettier`](https://github.com/prettier/prettier), + [`prettydiff`](https://github.com/prettydiff/prettydiff) +- Lua + - [`luaformatter`](https://github.com/LuaDevelopmentTools/luaformatter) +- Markdown + - [`remark`](https://github.com/wooorm/remark) + [`prettier`](https://github.com/prettier/prettier), +- Objective-C + - [`uncrustify`](http://uncrustify.sourceforge.net), + [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html), + [`astyle`](http://astyle.sourceforge.net) +- OCaml + - [`ocp-indent`](http://www.typerex.org/ocp-indent.html) + - [`ocamlformat`](https://github.com/ocaml-ppx/ocamlformat) +- Pandoc Markdown + - [`pandoc`](https://pandoc.org/MANUAL.html) +- Pawn + - [`uncrustify`](http://uncrustify.sourceforge.net) +- Perl + - [`perltidy`](http://perltidy.sourceforge.net) +- PHP + - [`php_beautifier`](http://pear.php.net/package/PHP_Beautifier) + - [`php-cs-fixer`](http://cs.sensiolabs.org/) +- Proto + - [`clang-format`](http://clang.llvm.org/docs/ClangFormat.html) +- Pug (formally Jade) + - [`pug-beautifier`](https://github.com/vingorius/pug-beautifier) +- Python + - [`yapf`](https://github.com/google/yapf), + [`autopep8`](https://github.com/hhatto/autopep8), + [`black`](https://github.com/ambv/black) + [isort](https://github.com/timothycrosley/isort) + [docformatter](https://github.com/myint/docformatter) +- Reason + - [`refmt`](https://github.com/facebook/reason) +- Ruby + - [rufo](https://github.com/asterite/rufo) + - [`ruby-beautify`](https://github.com/erniebrodeur/ruby-beautify) + - [`rubocop`](https://github.com/bbatsov/rubocop) +- Rust + - [`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) +- Sass + - [`sass-convert`](http://sass-lang.com/documentation/#executables), + [`csscomb`](http://csscomb.com) +- Scala + - [`scalariform`](https://github.com/scala-ide/scalariform) +- SCSS + - [`sass-convert`](http://sass-lang.com/documentation/#executables), + [`stylefmt`](https://github.com/morishitter/stylefmt), + [`prettier`](https://github.com/prettier/prettier), + [`prettydiff`](https://github.com/prettydiff/prettydiff), + [`csscomb`](http://csscomb.com) +- Shell + - [`shfmt`](https://github.com/mvdan/sh) +- SQL + - `sqlformat` (ships with [sqlparse](https://github.com/andialbrecht/sqlparse)) +- Terraform + - [`terraform`](https://www.terraform.io/docs/commands/fmt.html) +- Typescript + - [`tsfmt`](https://github.com/vvakame/typescript-formatter) +- VALA + - [`uncrustify`](http://uncrustify.sourceforge.net) +- Vue + - [`prettier`](https://github.com/prettier/prettier) +- XHTML + - [`tidy`](http://www.html-tidy.org), + [`prettydiff`](https://github.com/prettydiff/prettydiff) +- XML + - [`tidy`](http://www.html-tidy.org), + [`prettydiff`](https://github.com/prettydiff/prettydiff) +- YAML + - [`pyaml`](https://pypi.python.org/pypi/pyaml) + +============================================================================== +vim:tw=78:ts=8:ft=help:norl:noet:fen:noet: diff --git a/vim/bundle/neoformat/plugin/neoformat.vim b/vim/bundle/neoformat/plugin/neoformat.vim new file mode 100644 index 0000000..a2baae6 --- /dev/null +++ b/vim/bundle/neoformat/plugin/neoformat.vim @@ -0,0 +1,2 @@ +command! -nargs=? -bar -range=% -bang -complete=customlist,neoformat#CompleteFormatters Neoformat + \ call neoformat#Neoformat(0, , , ) diff --git a/vim/bundle/neoformat/test/.gitignore b/vim/bundle/neoformat/test/.gitignore new file mode 100644 index 0000000..f7275bb --- /dev/null +++ b/vim/bundle/neoformat/test/.gitignore @@ -0,0 +1 @@ +venv/ diff --git a/vim/bundle/neoformat/test/README.md b/vim/bundle/neoformat/test/README.md new file mode 100644 index 0000000..7d95db7 --- /dev/null +++ b/vim/bundle/neoformat/test/README.md @@ -0,0 +1,14 @@ +# Neoformat Tests + +Running tests + +```bash +# inside test/ + +./install.sh + +python3 -m virtualenv venv +pip install -r requirements.txt + +pytest -v test.py +``` diff --git a/vim/bundle/neoformat/test/after/cp.cp b/vim/bundle/neoformat/test/after/cp.cp new file mode 100644 index 0000000..e69de29 diff --git a/vim/bundle/neoformat/test/after/cssbeautify-indent-6.css b/vim/bundle/neoformat/test/after/cssbeautify-indent-6.css new file mode 100644 index 0000000..42170fe --- /dev/null +++ b/vim/bundle/neoformat/test/after/cssbeautify-indent-6.css @@ -0,0 +1,3 @@ +.body { + color: red; +} diff --git a/vim/bundle/neoformat/test/after/cssbeautify.css b/vim/bundle/neoformat/test/after/cssbeautify.css new file mode 100644 index 0000000..b4197b1 --- /dev/null +++ b/vim/bundle/neoformat/test/after/cssbeautify.css @@ -0,0 +1,3 @@ +.body { + color: red; +} diff --git a/vim/bundle/neoformat/test/after/csscomb.css b/vim/bundle/neoformat/test/after/csscomb.css new file mode 100644 index 0000000..f1d0ccb --- /dev/null +++ b/vim/bundle/neoformat/test/after/csscomb.css @@ -0,0 +1,4 @@ +.body +{ + color: red; +} diff --git a/vim/bundle/neoformat/test/after/prettydiff.css b/vim/bundle/neoformat/test/after/prettydiff.css new file mode 100644 index 0000000..f44498d --- /dev/null +++ b/vim/bundle/neoformat/test/after/prettydiff.css @@ -0,0 +1,4 @@ +.body { + color: red; +} + diff --git a/vim/bundle/neoformat/test/after/tsfmt.ts b/vim/bundle/neoformat/test/after/tsfmt.ts new file mode 100644 index 0000000..fe71c9b --- /dev/null +++ b/vim/bundle/neoformat/test/after/tsfmt.ts @@ -0,0 +1,13 @@ +module Geometry { + export class Square { + constructor(public sideLength: number = 0) { + } + area() { + return Math.pow(this.sideLength, 2); + } + } +} + +class Tuple { + constructor(public item1: T1, public item2: T2) { } +} diff --git a/vim/bundle/neoformat/test/after/yapf.py b/vim/bundle/neoformat/test/after/yapf.py new file mode 100644 index 0000000..336e825 --- /dev/null +++ b/vim/bundle/neoformat/test/after/yapf.py @@ -0,0 +1,2 @@ +def main(): + pass diff --git a/vim/bundle/neoformat/test/autocomplete_test.vim b/vim/bundle/neoformat/test/autocomplete_test.vim new file mode 100644 index 0000000..d4d1e31 --- /dev/null +++ b/vim/bundle/neoformat/test/autocomplete_test.vim @@ -0,0 +1,65 @@ +let s:tests = {} +" Utilities +function! s:Run(function) + let o = &filetype + " let output = call(a:function, ['']) + " call function(a:function) + let output = call(a:function, []) + let &filetype = o + " expecting output to either be a 1 or 0 + let s:tests[a:function[2:]] = output + return output +endfunction + +function! s:Cleanup() + let error = 0 + for test in keys(s:tests) + if !s:tests[test] + let error = 1 + endif + echom test . ' : ' . s:tests[test] + endfor + + if error + " make vim exit with a non-zero value + cquit! + else + qall! + endif +endfunction + +" Test Definitions +function! s:valid_option() + let &filetype = 'python' + + let g:neoformat_python_enabled = ['autopep8', 'yapf'] + let out = neoformat#CompleteFormatters('auto','', 0) + + return ['autopep8'] == out +endfunction + +function! s:invalid_option() + let &filetype = 'javascript' + + let g:neoformat_python_enabled = ['autopep8'] + let out = neoformat#CompleteFormatters('autopep8', '', 0) + + return [] == out +endfunction + +function! s:formtprg_option() + let &filetype = 'javascript' + let &formatprg = 'testing' + let out = neoformat#CompleteFormatters('test', '', 0) + + return [] == out +endfunction + +" Run Tests +call s:Run('s:valid_option') +call s:Run('s:invalid_option') +call s:Run('s:formtprg_option') + + +" Check the outputs +call s:Cleanup() diff --git a/vim/bundle/neoformat/test/before/cp.cp b/vim/bundle/neoformat/test/before/cp.cp new file mode 100644 index 0000000..9d40dd8 --- /dev/null +++ b/vim/bundle/neoformat/test/before/cp.cp @@ -0,0 +1 @@ +'test' diff --git a/vim/bundle/neoformat/test/before/cssbeautify.css b/vim/bundle/neoformat/test/before/cssbeautify.css new file mode 100644 index 0000000..6874830 --- /dev/null +++ b/vim/bundle/neoformat/test/before/cssbeautify.css @@ -0,0 +1,3 @@ +.body { +color: red; +} diff --git a/vim/bundle/neoformat/test/before/csscomb.css b/vim/bundle/neoformat/test/before/csscomb.css new file mode 100644 index 0000000..6874830 --- /dev/null +++ b/vim/bundle/neoformat/test/before/csscomb.css @@ -0,0 +1,3 @@ +.body { +color: red; +} diff --git a/vim/bundle/neoformat/test/before/prettydiff.css b/vim/bundle/neoformat/test/before/prettydiff.css new file mode 100644 index 0000000..6874830 --- /dev/null +++ b/vim/bundle/neoformat/test/before/prettydiff.css @@ -0,0 +1,3 @@ +.body { +color: red; +} diff --git a/vim/bundle/neoformat/test/before/tsfmt.ts b/vim/bundle/neoformat/test/before/tsfmt.ts new file mode 100644 index 0000000..0dd234a --- /dev/null +++ b/vim/bundle/neoformat/test/before/tsfmt.ts @@ -0,0 +1,13 @@ + module Geometry { +export class Square { +constructor(public sideLength: number = 0) { +} + area() { + return Math.pow(this.sideLength, 2); + } +} +} + +class Tuple { + constructor(public item1: T1, public item2: T2) { } +} diff --git a/vim/bundle/neoformat/test/before/yapf.py b/vim/bundle/neoformat/test/before/yapf.py new file mode 100644 index 0000000..66135be --- /dev/null +++ b/vim/bundle/neoformat/test/before/yapf.py @@ -0,0 +1,2 @@ +def main(): + pass diff --git a/vim/bundle/neoformat/test/bin/exit64 b/vim/bundle/neoformat/test/bin/exit64 new file mode 100755 index 0000000..b1800a8 --- /dev/null +++ b/vim/bundle/neoformat/test/bin/exit64 @@ -0,0 +1 @@ +exit 64 diff --git a/vim/bundle/neoformat/test/install.sh b/vim/bundle/neoformat/test/install.sh new file mode 100755 index 0000000..c9304fe --- /dev/null +++ b/vim/bundle/neoformat/test/install.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +if [[ $OSTYPE == darwin* ]]; then + OS='mac' +elif [[ $OSTYPE == linux-gnu* ]]; then + OS='linux' +else + OS='unknown' +fi + +# Formatters +npm install -g csscomb@3.1.7 +npm install -g prettydiff@99.0.1 +npm install -g js-beautify@1.6.2 # for css-beautify +npm install -g typescript@2.0.6 +npm install -g typescript-formatter@4.0.1 +pip install yapf==0.14.0 + +# Linter(s) +if ! hash vint 2>/dev/null; then + pip3 install vim-vint +fi + +# Make sure neovim is installed +if ! hash nvim 2>/dev/null; then + echo "installing neovim" + if [[ $OS == 'linux' ]]; then + echo "installing nvim on linux" + sudo add-apt-repository -y ppa:neovim-ppa/unstable + sudo apt-get update + sudo apt-get install -y neovim + elif [[ $OS == 'mac' ]]; then + echo "install nvim on mac" + brew install neovim + fi +else + echo "neovim already installed" +fi + +# Vader +if [ ! -d "$HOME/.vim/plugged/vader.vim" ]; then + git clone https://github.com/junegunn/vader.vim.git ~/.vim/plugged/vader.vim +fi + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +export PATH=$PATH:"$DIR"/bin +echo $PATH diff --git a/vim/bundle/neoformat/test/neoformat.vader b/vim/bundle/neoformat/test/neoformat.vader new file mode 100644 index 0000000..6212a56 --- /dev/null +++ b/vim/bundle/neoformat/test/neoformat.vader @@ -0,0 +1,43 @@ +Before: + function! g:CmdOutput(cmd) + redir => out + silent exe a:cmd + redir END + return out[1:] + endfunction + +Execute (empty filetype): + let &filetype = '' + let out = g:CmdOutput('Neoformat') + AssertEqual 'Neoformat: formatter not defined for filetype', out + +Execute (filetype without defined formatter): + let &filetype = 'not_real_filetype' + let out = g:CmdOutput('Neoformat') + + AssertEqual 'Neoformat: formatter not defined for ' . &filetype . ' filetype', out + +Execute (formatter defined for other filetype, but is called via user cmd): + let &filetype = 'javascript' + let out = g:CmdOutput('Neoformat autopep8') + + AssertEqual 'Neoformat: formatter definition for autopep8 not found', out + +Execute (user disabled all formatters for current (python) filetype): + let g:neoformat_enabled_python= [] + let &filetype = 'python' + let out = g:CmdOutput('Neoformat') + + AssertEqual 'Neoformat: formatter not defined for ' . &filetype . ' filetype', out + +Execute (user disabled all formatters for current (python) filetype): + let g:neoformat_enabled_python= ['not_real_formatter'] + let &filetype = 'python' + let out = g:CmdOutput('Neoformat') + + AssertEqual 'Neoformat: no change necessary', out + +Execute (invalid user cmd: formatter not defined): + let out = g:CmdOutput('Neoformat not_a_real_formatter') + + AssertEqual 'Neoformat: formatter definition for not_a_real_formatter not found', out diff --git a/vim/bundle/neoformat/test/requirements.txt b/vim/bundle/neoformat/test/requirements.txt new file mode 100644 index 0000000..ae190bf --- /dev/null +++ b/vim/bundle/neoformat/test/requirements.txt @@ -0,0 +1,2 @@ +py==1.4.32 +pytest==3.0.5 diff --git a/vim/bundle/neoformat/test/test.py b/vim/bundle/neoformat/test/test.py new file mode 100644 index 0000000..f5c42ee --- /dev/null +++ b/vim/bundle/neoformat/test/test.py @@ -0,0 +1,138 @@ +#!/usr/bin/env python3.6 + +import subprocess + +from os import listdir +from shutil import copyfile + +def run_vim_cmd(cmd, filename=''): + cmd = f'nvim -u vimrc -c "set verbose=1 | {cmd} | wq " --headless {filename}' + return run_cmd(cmd) + + +def run_cmd(cmd): + return subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True).wait() + + +def readlines(filename): + with open(filename) as f: + return f.readlines() + + +def test_formatters(): + ''' + run formatters on entire buffer + ''' + for filename in listdir('before'): + output_file = '/tmp/neoformat_' + filename + formatter = filename.split('.')[0] + cmd = f'nvim -u vimrc -c "set verbose=1 | Neoformat {formatter} | w! {output_file} | q! " --headless ./before/{filename}' + run_cmd(cmd) + before = readlines(output_file) + after = readlines('./after/' + filename) + assert before == after + + +def test_visual_selection_multi_filetype(): + ''' + Format different filetypes in one file + ''' + filename_before = 'visual_selection_before.txt' + output_file = '/tmp/neoformat_' + filename_before + copyfile(filename_before, output_file) + + for test in [('python', 4, 7), ('css', 9, 9), ('css', 14, 15)]: + (filetype, start_line, end_line) = test + print(start_line) + vim_cmd = f'{start_line},{end_line}Neoformat! {filetype}' + cmd = f'nvim -u vimrc -c "set verbose=1 | {vim_cmd} | wq " --headless {output_file}' + run_cmd(cmd) + + before = readlines(output_file) + after = readlines('visual_selection_after.txt') + assert before == after + + +def test_visual_selection_with_filetype_and_formatter(): + ''' + Test that passing filetype and formatter to Neoformat! works + ''' + dir_before = 'visual_before/' + dir_after = 'visual_after/' + for filename in listdir(dir_before): + (filetype, formatter, start_line, end_line) = filename.split('_') + output_file = '/tmp/neoformat_' + filename + cmd = f'nvim -u vimrc -c "set verbose=1 | {start_line},{end_line}Neoformat! {filetype} {formatter} | w! {output_file} | q! " --headless {dir_before + filename}' + run_cmd(cmd) + before = readlines(output_file) + after = readlines(dir_after + filename) + assert before == after + + +def test_formatprg_with_neoformat(): + ''' + Test that formatprg is processed by neoformat + ''' + + dir_before = 'before/' + filename = 'cssbeautify.css' + output_file = '/tmp/neoformat_fmt_prg_' + filename + viml = ''' + let &formatprg = 'css-beautify -s 6 -n' + let g:neoformat_try_formatprg = 1 + ''' + cmd = f'nvim -u vimrc -c "set verbose=1 | {viml} | Neoformat | w! {output_file} | q! " --headless {dir_before + filename}' + run_cmd(cmd) + before = readlines(output_file) + after = readlines('./after/cssbeautify-indent-6.css') + assert before == after + + +def test_formatprg_without_enable(): + ''' + Test that formatprg isn't use when not enabled + ''' + + dir_before = 'before/' + filename = 'cssbeautify.css' + output_file = '/tmp/neoformat_fmtprg_not_enabled' + filename + viml = ''' + let &formatprg = 'css-beautify -s 6 -n' + ''' + cmd = f'nvim -u vimrc -c "set verbose=1 | {viml} | Neoformat | w! {output_file} | q! " --headless {dir_before + filename}' + run_cmd(cmd) + before = readlines(output_file) + after = readlines('./after/cssbeautify.css') + assert before == after + + +def test_vader(): + ''' + run *.vader tests + ''' + cmd = f'nvim -u vimrc -c "Vader! *.vader" --headless' + exit_code = run_cmd(cmd) + assert exit_code == 0 + + +def test_autocompletion(): + ''' + run the vim autocompletion tests + ''' + cmd = f'nvim -u vimrc -c "source autocomplete_test.vim" --headless' + exit_code = run_cmd(cmd) + assert exit_code == 0 + + +def test_viml_syntax(): + ''' + run vint to check vim syntax + ''' + exit_code = run_cmd('vint ../') + assert exit_code == 0 + + +if __name__ == '__main__': + # run all functions with names in the form of 'test_...' + [func() for func in (val for key, val in vars().items() + if key.startswith('test_'))] diff --git a/vim/bundle/neoformat/test/utils.vader b/vim/bundle/neoformat/test/utils.vader new file mode 100644 index 0000000..ccf4ce3 --- /dev/null +++ b/vim/bundle/neoformat/test/utils.vader @@ -0,0 +1,56 @@ +Before: + function! g:CmdOutput(cmd) + redir => out + silent exe 'call ' . a:cmd + redir END + return out[1:] + endfunction + +Execute (test log util): + let g:neoformat_verbose = 1 + let out = g:CmdOutput('neoformat#utils#log("test")') + + let g:neoformat_verbose = 0 + AssertEqual 'Neoformat: test', out + +Execute (test msg util): + let g:neoformat_verbose = 0 + " vader persists g: variables between tests so we need to make sure it is zero + let g:neoformat_only_msg_on_error = 0 + let out = g:CmdOutput('neoformat#utils#msg("test")') + + AssertEqual 'Neoformat: test', out + +Execute (test warn util): + let g:neoformat_verbose = 0 + let out = g:CmdOutput('neoformat#utils#warn("test")') + + AssertEqual 'Neoformat: test', out + +Execute (msg when g:neoformat_only_msg_on_error is false): + let g:neoformat_only_msg_on_error = 0 + + let out = g:CmdOutput('neoformat#utils#msg("test")') + + AssertEqual 'Neoformat: test', out + +Execute (msg when g:neoformat_only_msg_on_error is true): + let g:neoformat_only_msg_on_error = 1 + + let out = g:CmdOutput('neoformat#utils#msg("test")') + + AssertEqual '', out + +Execute (msg when g:neoformat_only_msg_on_error is false): + let g:neoformat_only_msg_on_error = 0 + + let out = g:CmdOutput('neoformat#utils#warn("test")') + + AssertEqual 'Neoformat: test', out + +Execute (warn when g:neoformat_only_msg_on_error is true): + let g:neoformat_only_msg_on_error = 1 + + let out = g:CmdOutput('neoformat#utils#warn("test")') + + AssertEqual 'Neoformat: test', out diff --git a/vim/bundle/neoformat/test/vimrc b/vim/bundle/neoformat/test/vimrc new file mode 100644 index 0000000..21b8c7e --- /dev/null +++ b/vim/bundle/neoformat/test/vimrc @@ -0,0 +1,18 @@ +filetype off +set runtimepath+=$HOME/.vim/plugged/vader.vim +set runtimepath+=../ +filetype plugin indent on +syntax enable +autocmd! filetype css set shiftwidth=2 +autocmd! filetype python set shiftwidth=4 +autocmd! filetype javascript set shiftwidth=4 +autocmd! BufRead *.ts set filetype=typescript +autocmd! BufRead *.cp set filetype=copy +set nocompatible +set noswapfile + +" seems like cp doesn't have standard exit codes +let g:neoformat_copy_cp = { + \ 'exe': 'exit64', + \ 'valid_exit_codes': [1, 64], + \ } diff --git a/vim/bundle/neoformat/test/visual_after/css_cssbeautify_3_4 b/vim/bundle/neoformat/test/visual_after/css_cssbeautify_3_4 new file mode 100644 index 0000000..619d181 --- /dev/null +++ b/vim/bundle/neoformat/test/visual_after/css_cssbeautify_3_4 @@ -0,0 +1,8 @@ + + +.test { + color: blue; + border: none; +} + + diff --git a/vim/bundle/neoformat/test/visual_after/javascript_jsbeautify_3_4 b/vim/bundle/neoformat/test/visual_after/javascript_jsbeautify_3_4 new file mode 100644 index 0000000..468df3c --- /dev/null +++ b/vim/bundle/neoformat/test/visual_after/javascript_jsbeautify_3_4 @@ -0,0 +1,5 @@ + + +function main() { + console.log('test') +} diff --git a/vim/bundle/neoformat/test/visual_before/css_cssbeautify_3_4 b/vim/bundle/neoformat/test/visual_before/css_cssbeautify_3_4 new file mode 100644 index 0000000..28ec6cb --- /dev/null +++ b/vim/bundle/neoformat/test/visual_before/css_cssbeautify_3_4 @@ -0,0 +1,6 @@ + + +.test{color:blue; +border:none;} + + diff --git a/vim/bundle/neoformat/test/visual_before/javascript_jsbeautify_3_4 b/vim/bundle/neoformat/test/visual_before/javascript_jsbeautify_3_4 new file mode 100644 index 0000000..ed9f897 --- /dev/null +++ b/vim/bundle/neoformat/test/visual_before/javascript_jsbeautify_3_4 @@ -0,0 +1,4 @@ + + +function main(){ +console.log('test')} diff --git a/vim/bundle/neoformat/test/visual_selection_after.txt b/vim/bundle/neoformat/test/visual_selection_after.txt new file mode 100644 index 0000000..095304e --- /dev/null +++ b/vim/bundle/neoformat/test/visual_selection_after.txt @@ -0,0 +1,16 @@ + + + +def main(): + + pass + + +.body { + color: red; +} + + +.textleft { + text-align: left; +} diff --git a/vim/bundle/neoformat/test/visual_selection_before.txt b/vim/bundle/neoformat/test/visual_selection_before.txt new file mode 100644 index 0000000..b8d715b --- /dev/null +++ b/vim/bundle/neoformat/test/visual_selection_before.txt @@ -0,0 +1,14 @@ + + + +def main(): + + + pass + + +.body{color:red;} + + +.textleft{ +text-align:left;} diff --git a/vimrc b/vimrc index 3c73e89..1e22c46 100644 --- a/vimrc +++ b/vimrc @@ -257,6 +257,9 @@ let g:neomake_javascript_enabled_makers = ['eslint', 'flow'] let g:neomake_open_list = 2 call neomake#configure#automake('rw') +" neoformat +autocmd BufWritePre,InsertLeave *.js* Neoformat + " Haskell let hs_highlight_boolean = 1 let hs_highlight_types = 1