Fix #13 and some cleanup.

This commit is contained in:
Chiel92 2013-12-20 20:34:38 +01:00
parent 1e20517276
commit 66995c00d1
4 changed files with 60 additions and 70 deletions

View File

@ -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.
@ -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

View File

@ -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.

View File

@ -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
@ -24,8 +22,6 @@ function! s:set_formatprg()
endif endif
"Set correct formatprg path, if it is installed "Set correct formatprg path, if it is installed
if !executable(s:formatprg)
let s:formatprg = s:formatterdir.s:formatprg
if !executable(s:formatprg) if !executable(s:formatprg)
"Configured formatprg not installed "Configured formatprg not installed
if exists("g:autoformat_verbosemode") if exists("g:autoformat_verbosemode")
@ -33,7 +29,6 @@ function! s:set_formatprg()
endif endif
return 0 return 0
endif endif
endif
let &formatprg = s:formatprg." ".s:formatprg_args let &formatprg = s:formatprg." ".s:formatprg_args
return 1 return 1

View File

@ -28,27 +28,18 @@ 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 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
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 -"'
endif
"We allow an alternative path for js-beautify if !exists("g:formatprg_javascript") | let g:formatprg_javascript = "js-beautify" | endif
"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
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