Fix #13 and some cleanup.
This commit is contained in:
parent
1e20517276
commit
66995c00d1
71
README.md
71
README.md
@ -35,7 +35,6 @@ For using a custom formatprogram, read the text below *How can I change the beha
|
|||||||
If the formatprogram you want to use is installed correctly, in one of the following ways, vim automatically detects it.
|
If the formatprogram you want to use is installed correctly, in one of the following ways, vim automatically detects it.
|
||||||
* It suffices to make the formatprogram globally available, which is the case if you install it via your package manager.
|
* It suffices to make the formatprogram globally available, which is the case if you install it via your package manager.
|
||||||
* Alternatively you can point vim to the the binary by explicitly putting the absolute path in `g:formatprg_<filetype>` in your .vimrc.
|
* Alternatively you can point vim to the the binary by explicitly putting the absolute path in `g:formatprg_<filetype>` in your .vimrc.
|
||||||
* A third way to make vim detect the formatprogram, is by putting its binary (or a link to it) in the `formatters/` directory within the directory of vim-autoformat.
|
|
||||||
|
|
||||||
Remember that when no formatprogram exists for a certain filetype, vim-autoformat uses vim's indent functionality as a fallback.
|
Remember that when no formatprogram exists for a certain filetype, vim-autoformat uses vim's indent functionality as a fallback.
|
||||||
This will fix at least the indentation of your code, according to vim's indentfile for that filetype.
|
This will fix at least the indentation of your code, according to vim's indentfile for that filetype.
|
||||||
@ -62,19 +61,23 @@ It's probably in your distro's repository, so you can download it as a regular p
|
|||||||
For Ubuntu type `sudo apt-get install astyle` in a terminal.
|
For Ubuntu type `sudo apt-get install astyle` in a terminal.
|
||||||
Otherwise, download it here: http://astyle.sourceforge.net/.
|
Otherwise, download it here: http://astyle.sourceforge.net/.
|
||||||
|
|
||||||
* `jsbeautify` (the python CLI version) for __Javascript__.
|
|
||||||
This one can also be installed as a vundle package, and I recommend to do so.
|
|
||||||
Put this in your .vimrc: `Bundle "einars/js-beautify"`.
|
|
||||||
Note that we're only using the python version, so `node` doesn't have to be installed.
|
|
||||||
Here is the link to the repository: https://github.com/einars/js-beautify.
|
|
||||||
|
|
||||||
* `autopep8` for __Python__.
|
* `autopep8` for __Python__.
|
||||||
It's probably in your distro's repository, so you can download it as a regular package.
|
It's probably in your distro's repository, so you can download it as a regular package.
|
||||||
For Ubuntu type `sudo apt-get install autopep8` in a terminal.
|
For Ubuntu type `sudo apt-get install autopep8` in a terminal.
|
||||||
Here is the link to the repository: https://github.com/hhatto/autopep8.
|
Here is the link to the repository: https://github.com/hhatto/autopep8.
|
||||||
And here the link to its page on the python website: http://pypi.python.org/pypi/autopep8/0.5.2.
|
And here the link to its page on the python website: http://pypi.python.org/pypi/autopep8/0.5.2.
|
||||||
|
|
||||||
* `tidy` for __HTML__ ( __not HTML5__, tidy cannot handle the new tags sadly), __XHTML__ and __XML__.
|
* `js-beautify` for __Javascript__.
|
||||||
|
It can be installed by running `npm install -g js-beautify`.
|
||||||
|
Note that `nodejs` is needed for this to work.
|
||||||
|
Here is the link to the repository: https://github.com/einars/js-beautify.
|
||||||
|
|
||||||
|
* `html-beautify` for __HTML__.
|
||||||
|
It is shipped with `js-beautify`, which can be installed by running `npm install -g js-beautify`.
|
||||||
|
Note that `nodejs` is needed for this to work.
|
||||||
|
Here is the link to the repository: https://github.com/einars/js-beautify.
|
||||||
|
|
||||||
|
* `tidy` for __XHTML__ and __XML__.
|
||||||
It's probably in your distro's repository, so you can download it as a regular package.
|
It's probably in your distro's repository, so you can download it as a regular package.
|
||||||
For Ubuntu type `sudo apt-get install tidy` in a terminal.
|
For Ubuntu type `sudo apt-get install tidy` in a terminal.
|
||||||
|
|
||||||
@ -97,7 +100,7 @@ Then, a similar definition would look like this:
|
|||||||
|
|
||||||
```vim
|
```vim
|
||||||
let g:formatprg_cs = "astyle"
|
let g:formatprg_cs = "astyle"
|
||||||
let g:formatprg_args_expr_cs = '"--mode=cs --style=ansi -pcHs".&shiftwidth'
|
let g:formatprg_args_expr_cs = '"--mode=cs --style=ansi -pcHs".&shiftwidth'
|
||||||
```
|
```
|
||||||
|
|
||||||
Notice that `g:formatprg_args_expr_cs` now contains an expression that can be evaluated, as required.
|
Notice that `g:formatprg_args_expr_cs` now contains an expression that can be evaluated, as required.
|
||||||
@ -110,31 +113,27 @@ This means that the formatting style will match your current vim settings as muc
|
|||||||
For the exact default definitions, have a look in `vim-autoformat/plugin/defaults.vim`.
|
For the exact default definitions, have a look in `vim-autoformat/plugin/defaults.vim`.
|
||||||
|
|
||||||
|
|
||||||
Todo list
|
Things that are not (yet) implemented
|
||||||
---------
|
----------------------------------------------------------
|
||||||
* Check for windows support.
|
* Check for windows support.
|
||||||
* Option for on-the-fly code-formatting, like visual studio (If ever. When you have a clever idea about how to do this, i'd be glad to hear.)
|
* Option for on-the-fly code-formatting, like visual studio (If ever. When you have a clever idea about how to do this, I'd be glad to hear.)
|
||||||
* Create a help file.
|
|
||||||
|
|
||||||
|
Pull requests are welcome.
|
||||||
If you have any suggestions on this plugin or on this readme, if you have some nice default formatprg definition that can be added to the defaults, or if you experience problems, please contact me by creating an issue in this repository.
|
|
||||||
Any feedback is welcome.
|
Any feedback is welcome.
|
||||||
|
If you have any suggestions on this plugin or on this readme, if you have some nice default formatprg definition that can be added to the defaults, or if you experience problems, please contact me by creating an issue in this repository.
|
||||||
|
|
||||||
Change log
|
Change log
|
||||||
----------
|
----------
|
||||||
### March 9 2013
|
### December 20 2013
|
||||||
The `custom_config` branch has been merged into the master branch.
|
* `html-beautify` is now the default for HTML since it seems to be better maintained, and seems to handle inline javascript neatly.
|
||||||
* Customization of formatprograms can be done easily now, as explained above.
|
* The `formatters/` folder is no longer supported anymore, because it is unnecessary.
|
||||||
* I set the default tabwidth to 4 for all formatprograms as well as for vim itself.
|
* `js-beautify` can no longer be installed as a bundle, since it only makes this plugin unnecessarily complex.
|
||||||
* The default parameters for astyle have been slightly modified: it will wrap spaces around operators.
|
|
||||||
* phpCB has been removed from the defaults, due to code-breaking behaviour.
|
|
||||||
* XHTML default definition added
|
|
||||||
|
|
||||||
### March 10 2013
|
### March 27 2013
|
||||||
* When no formatter is installed or defined, vim will now auto-indent the file instead. This uses the indentfile for that specific filetype.
|
* The default behaviour of gq is enabled again by removing the fallback on auto-indenting.
|
||||||
|
Instead, the fallback is only used when running the command `:Autoformat`.
|
||||||
### March 13 2013
|
* For HTML,XML and XHTML, the option `textwidth` is taken into account when formatting.
|
||||||
* It is now possible to prevent vim-autoformat from overwriting your settings for `tabstop`, `softtabstop`, `shiftwidth` and `expandtab` in your .vimrc.
|
This extends the way the formatting style will match your current vim settings.
|
||||||
|
|
||||||
### March 16 2013
|
### March 16 2013
|
||||||
The `dynamic_indent_width` branch has been merged into the master branch.
|
The `dynamic_indent_width` branch has been merged into the master branch.
|
||||||
@ -142,8 +141,16 @@ The `dynamic_indent_width` branch has been merged into the master branch.
|
|||||||
* This obsoletes `g:autoformat_no_default_shiftwidth`
|
* This obsoletes `g:autoformat_no_default_shiftwidth`
|
||||||
* `g:formatprg_args_expr_<filetype>` is introduced.
|
* `g:formatprg_args_expr_<filetype>` is introduced.
|
||||||
|
|
||||||
### March 27 2013
|
### March 13 2013
|
||||||
* The default behaviour of gq is enabled again by removing the fallback on auto-indenting.
|
* It is now possible to prevent vim-autoformat from overwriting your settings for `tabstop`, `softtabstop`, `shiftwidth` and `expandtab` in your .vimrc.
|
||||||
Instead, the fallback is only used when running the command `:Autoformat`.
|
|
||||||
* For HTML,XML and XHTML, the option `textwidth` is taken into account when formatting.
|
### March 10 2013
|
||||||
This extends the way the formatting style will match your current vim settings.
|
* When no formatter is installed or defined, vim will now auto-indent the file instead. This uses the indentfile for that specific filetype.
|
||||||
|
|
||||||
|
### March 9 2013
|
||||||
|
The `custom_config` branch has been merged into the master branch.
|
||||||
|
* Customization of formatprograms can be done easily now, as explained above.
|
||||||
|
* I set the default tabwidth to 4 for all formatprograms as well as for vim itself.
|
||||||
|
* The default parameters for astyle have been slightly modified: it will wrap spaces around operators.
|
||||||
|
* phpCB has been removed from the defaults, due to code-breaking behaviour.
|
||||||
|
* XHTML default definition added
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
Formatprograms that are put here will be detected.
|
|
||||||
Note that globally available programs are also detected.
|
|
||||||
Read the general README.markdown file for more info on which formatprograms are supported.
|
|
@ -1,6 +1,4 @@
|
|||||||
"Function for finding and setting the formatter with the given name,
|
"Function for finding and setting the formatter with the given name
|
||||||
"if the formatter is installed globally or in the formatters folder
|
|
||||||
let s:formatterdir = fnamemodify(expand("<sfile>"), ":p:h:h")."/formatters/"
|
|
||||||
function! s:set_formatprg()
|
function! s:set_formatprg()
|
||||||
"Get formatprg config for current filetype
|
"Get formatprg config for current filetype
|
||||||
let s:formatprg_var = "g:formatprg_".&filetype
|
let s:formatprg_var = "g:formatprg_".&filetype
|
||||||
@ -25,14 +23,11 @@ function! s:set_formatprg()
|
|||||||
|
|
||||||
"Set correct formatprg path, if it is installed
|
"Set correct formatprg path, if it is installed
|
||||||
if !executable(s:formatprg)
|
if !executable(s:formatprg)
|
||||||
let s:formatprg = s:formatterdir.s:formatprg
|
"Configured formatprg not installed
|
||||||
if !executable(s:formatprg)
|
if exists("g:autoformat_verbosemode")
|
||||||
"Configured formatprg not installed
|
echoerr "Defined formatter ".eval(s:formatprg_var)." is not executable."
|
||||||
if exists("g:autoformat_verbosemode")
|
|
||||||
echoerr "Defined formatter ".eval(s:formatprg_var)." is not executable."
|
|
||||||
endif
|
|
||||||
return 0
|
|
||||||
endif
|
endif
|
||||||
|
return 0
|
||||||
endif
|
endif
|
||||||
let &formatprg = s:formatprg." ".s:formatprg_args
|
let &formatprg = s:formatprg." ".s:formatprg_args
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
if !exists("g:formatprg_cs") | let g:formatprg_cs = "astyle" | endif
|
if !exists("g:formatprg_cs") | let g:formatprg_cs = "astyle" | endif
|
||||||
if !exists("g:formatprg_args_expr_cs") && !exists("g:formatprg_args_cs")
|
if !exists("g:formatprg_args_expr_cs") && !exists("g:formatprg_args_cs")
|
||||||
let g:formatprg_args_expr_cs = '"--mode=cs --style=ansi --indent-namespaces -pcH".(&expandtab ? "s".&shiftwidth : "t")'
|
let g:formatprg_args_expr_cs = '"--mode=cs --style=ansi --indent-namespaces -pcH".(&expandtab ? "s".&shiftwidth : "t")'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:formatprg_c") | let g:formatprg_c = "astyle" | endif
|
if !exists("g:formatprg_c") | let g:formatprg_c = "astyle" | endif
|
||||||
@ -9,46 +9,37 @@ if !exists("g:formatprg_args_expr_c") && !exists("g:formatprg_args_c")
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:formatprg_cpp") | let g:formatprg_cpp = "astyle" | endif
|
if !exists("g:formatprg_cpp") | let g:formatprg_cpp = "astyle" | endif
|
||||||
if !exists("g:formatprg_args_expr_cpp") && !exists("g:formatprg_args_cpp")
|
if !exists("g:formatprg_args_expr_cpp") && !exists("g:formatprg_args_cpp")
|
||||||
let g:formatprg_args_expr_cpp = '"--mode=c --style=ansi -pcH".(&expandtab ? "s".&shiftwidth : "t")'
|
let g:formatprg_args_expr_cpp = '"--mode=c --style=ansi -pcH".(&expandtab ? "s".&shiftwidth : "t")'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:formatprg_java") | let g:formatprg_java = "astyle" | endif
|
if !exists("g:formatprg_java") | let g:formatprg_java = "astyle" | endif
|
||||||
if !exists("g:formatprg_args_expr_java") && !exists("g:formatprg_args_java")
|
if !exists("g:formatprg_args_expr_java") && !exists("g:formatprg_args_java")
|
||||||
let g:formatprg_args_expr_java = '"--mode=java --style=ansi -pcH".(&expandtab ? "s".&shiftwidth : "t")'
|
let g:formatprg_args_expr_java = '"--mode=java --style=ansi -pcH".(&expandtab ? "s".&shiftwidth : "t")'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:formatprg_python") | let g:formatprg_python = "autopep8" | endif
|
if !exists("g:formatprg_python") | let g:formatprg_python = "autopep8" | endif
|
||||||
if !exists("g:formatprg_args_expr_python") && !exists("g:formatprg_args_python")
|
if !exists("g:formatprg_args_expr_python") && !exists("g:formatprg_args_python")
|
||||||
let g:formatprg_args_expr_python = '"/dev/stdin ".(&textwidth ? "--max-line-length=".&textwidth : "")'
|
let g:formatprg_args_expr_python = '"/dev/stdin ".(&textwidth ? "--max-line-length=".&textwidth : "")'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:formatprg_xml") | let g:formatprg_xml = "tidy" | endif
|
if !exists("g:formatprg_xml") | let g:formatprg_xml = "tidy" | endif
|
||||||
if !exists("g:formatprg_args_expr_xml") && !exists("g:formatprg_args_xml")
|
if !exists("g:formatprg_args_expr_xml") && !exists("g:formatprg_args_xml")
|
||||||
let g:formatprg_args_expr_xml = '"-q -xml --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -wrap ".&textwidth'
|
let g:formatprg_args_expr_xml = '"-q -xml --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -wrap ".&textwidth'
|
||||||
endif
|
|
||||||
|
|
||||||
if !exists("g:formatprg_html") | let g:formatprg_html = "tidy" | endif
|
|
||||||
if !exists("g:formatprg_args_expr_html") && !exists("g:formatprg_args_html")
|
|
||||||
let g:formatprg_args_expr_html = '"-q --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -wrap ".&textwidth'
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:formatprg_xhtml") | let g:formatprg_xhtml = "tidy" | endif
|
if !exists("g:formatprg_xhtml") | let g:formatprg_xhtml = "tidy" | endif
|
||||||
if !exists("g:formatprg_args_expr_xhtml") && !exists("g:formatprg_args_xhtml")
|
if !exists("g:formatprg_args_expr_xhtml") && !exists("g:formatprg_args_xhtml")
|
||||||
let g:formatprg_args_expr_xhtml = '"-q --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -asxhtml -wrap ".&textwidth'
|
let g:formatprg_args_expr_xhtml = '"-q --show-errors 0 --show-warnings 0 --force-output --indent auto --indent-spaces ".&shiftwidth." --vertical-space yes --tidy-mark no -asxhtml -wrap ".&textwidth'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !exists("g:formatprg_javascript")
|
if !exists("g:formatprg_html") | let g:formatprg_html = "html-beautify" | endif
|
||||||
let g:formatprg_javascript = "js-beautify"
|
if !exists("g:formatprg_args_expr_html") && !exists("g:formatprg_args_html")
|
||||||
|
let g:formatprg_args_expr_html = '"-f -"'
|
||||||
"We allow an alternative path for js-beautify
|
|
||||||
"If js-beautify is installed as a bundle, we still want to detect it
|
|
||||||
let s:bundleDir = fnamemodify(expand("<sfile>"), ":h:h:h")
|
|
||||||
let s:jsbeautify_alternative = s:bundleDir."/js-beautify/python/".g:formatprg_javascript
|
|
||||||
if executable(s:jsbeautify_alternative)
|
|
||||||
let g:formatprg_javascript = s:jsbeautify_alternative
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if !exists("g:formatprg_javascript") | let g:formatprg_javascript = "js-beautify" | endif
|
||||||
if !exists("g:formatprg_args_expr_javascript") && !exists("g:formatprg_args_javascript")
|
if !exists("g:formatprg_args_expr_javascript") && !exists("g:formatprg_args_javascript")
|
||||||
let g:formatprg_args_expr_javascript = '"-i -s".&shiftwidth'
|
let g:formatprg_args_expr_javascript = '"-f - -s".&shiftwidth'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user