diff --git a/README.md b/README.md index 2a0affa..00d8ca2 100644 --- a/README.md +++ b/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. * 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_` 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. 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. 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__. 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. 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. -* `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. For Ubuntu type `sudo apt-get install tidy` in a terminal. @@ -97,7 +100,7 @@ Then, a similar definition would look like this: ```vim 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. @@ -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`. -Todo list ---------- +Things that are not (yet) implemented +---------------------------------------------------------- * 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.) -* Create a help file. +* 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.) - -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. +Pull requests are 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 ---------- -### 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 +### December 20 2013 +* `html-beautify` is now the default for HTML since it seems to be better maintained, and seems to handle inline javascript neatly. +* The `formatters/` folder is no longer supported anymore, because it is unnecessary. +* `js-beautify` can no longer be installed as a bundle, since it only makes this plugin unnecessarily complex. -### March 10 2013 -* When no formatter is installed or defined, vim will now auto-indent the file instead. This uses the indentfile for that specific filetype. - -### March 13 2013 -* It is now possible to prevent vim-autoformat from overwriting your settings for `tabstop`, `softtabstop`, `shiftwidth` and `expandtab` in your .vimrc. +### March 27 2013 +* 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`. +* For HTML,XML and XHTML, the option `textwidth` is taken into account when formatting. +This extends the way the formatting style will match your current vim settings. ### March 16 2013 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` * `g:formatprg_args_expr_` is introduced. -### March 27 2013 -* 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`. -* For HTML,XML and XHTML, the option `textwidth` is taken into account when formatting. -This extends the way the formatting style will match your current vim settings. +### March 13 2013 +* It is now possible to prevent vim-autoformat from overwriting your settings for `tabstop`, `softtabstop`, `shiftwidth` and `expandtab` in your .vimrc. + +### March 10 2013 +* 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 diff --git a/formatters/README_formatters_dir.txt b/formatters/README_formatters_dir.txt deleted file mode 100644 index d9ef875..0000000 --- a/formatters/README_formatters_dir.txt +++ /dev/null @@ -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. diff --git a/plugin/autoformat.vim b/plugin/autoformat.vim index eea5558..4e144c3 100644 --- a/plugin/autoformat.vim +++ b/plugin/autoformat.vim @@ -1,6 +1,4 @@ -"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(""), ":p:h:h")."/formatters/" +"Function for finding and setting the formatter with the given name function! s:set_formatprg() "Get formatprg config for current filetype let s:formatprg_var = "g:formatprg_".&filetype @@ -25,14 +23,11 @@ function! s:set_formatprg() "Set correct formatprg path, if it is installed if !executable(s:formatprg) - let s:formatprg = s:formatterdir.s:formatprg - if !executable(s:formatprg) - "Configured formatprg not installed - if exists("g:autoformat_verbosemode") - echoerr "Defined formatter ".eval(s:formatprg_var)." is not executable." - endif - return 0 + "Configured formatprg not installed + if exists("g:autoformat_verbosemode") + echoerr "Defined formatter ".eval(s:formatprg_var)." is not executable." endif + return 0 endif let &formatprg = s:formatprg." ".s:formatprg_args diff --git a/plugin/defaults.vim b/plugin/defaults.vim index dfdafc8..dacfbbc 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -1,6 +1,6 @@ if !exists("g:formatprg_cs") | let g:formatprg_cs = "astyle" | endif -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")' +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")' 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 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")' 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")' endif if !exists("g:formatprg_python") | let g:formatprg_python = "autopep8" | endif -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 : "")' +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 : "")' endif if !exists("g:formatprg_xml") | let g:formatprg_xml = "tidy" | endif 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' -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' + 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_xhtml") | let g:formatprg_xhtml = "tidy" | endif -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' +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' endif -if !exists("g:formatprg_javascript") - let g:formatprg_javascript = "js-beautify" - - "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(""), ":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 +if !exists("g:formatprg_html") | let g:formatprg_html = "html-beautify" | endif +if !exists("g:formatprg_args_expr_html") && !exists("g:formatprg_args_html") + let g:formatprg_args_expr_html = '"-f -"' 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") - let g:formatprg_args_expr_javascript = '"-i -s".&shiftwidth' + let g:formatprg_args_expr_javascript = '"-f - -s".&shiftwidth' endif +