vim-codefmt icon indicating copy to clipboard operation
vim-codefmt copied to clipboard

Allow configuring indent size, etc. for autopep8

Open dbarnett opened this issue 10 years ago • 13 comments

autopep8 allows configuring the indent-size and max-line-length to use as well as listing error codes to be ignored like --ignore=E226,E302,E41. It's currently possible to configure those via pep8 config files by putting something like the following in ~/.config/pep8 or a per-project setup.cfg or tox.ini:

[pep8]
indent-size = 2
max-line-length = 100
ignore = E226,E302,E41

Config files work pretty well in most cases, but it still would be nice to be able to configure via vimscript for some cases. I'm thinking there should be a flag and/or buffer-local variable that can be used to pass config to autopep8.

In particular, since vim already has settings that correspond to indent size and max line length, it would be great to have an option to hook those up to automatically match vim's 'shiftwidth' and 'textwidth' settings, since I've already configured formatting settings once and shouldn't be forced to repeat myself.

dbarnett avatar Jan 29 '15 06:01 dbarnett

@actionless FYI

dbarnett avatar Jan 29 '15 06:01 dbarnett

I'm wondering if it would make sense to generalize the flags rather than creating an explosion of flags per formatter. One option would be to have a single dict flag per "topic", like formatter_args, and then configure e.g.,

Glaive codefmt formatter_args[autopep8]=`['--indent-size=2', '--ignore=E226,E302,E41']`

and similarly for executable, etc. Of course, it would kind of make more sense for the formatter to be the top-level thing and the "topic" to be under that, like autopep8_config[executable], but then we have complex type rules we have to describe, like "the type of this flag is a dict with an optional 'executable' key that's a string, an optional 'args' key that's a list of strings…".

Anyway, I'm staring to think in this case global config is pretty redundant with ~/.config/pep8 and we should just suggest using that instead of adding a flag for global autopep8 config, but still a buffer-local variable has some appeal so you can control it via autocmds.

Also the configuration to respect 'shiftwidth' and 'textwidth' don't have to be formatter-specific, although not every formatter will support them. There could be a single global + buffer-local setting for all formatters.

dbarnett avatar Jan 29 '15 06:01 dbarnett

Also the configuration to respect 'shiftwidth' and 'textwidth' don't have to be formatter-specific

that would be a killer-feature

but i don't think it's possible to make all the options global across the formatters, so lists of arguments per formatter seems ok to me

actionless avatar Jan 29 '15 08:01 actionless

also mb it's possible to get use of this http://editorconfig.org/ ?

If we can forward vim's indent settings to formatters, we pretty much have made use of editorconfig, because configuration will go from editorconfig to vim settings and from there to the formatters.

I think we could pass common formatting options to formatters pretty easily and then they could each implement support if it's available. Max line length and indent size are pretty central to codefmt's purpose, so I think it's worth extending the API. Still have to flesh out the actual API for it and figure out how to extend the API while maintaining backwards compatibility, though.

dbarnett avatar Jan 29 '15 16:01 dbarnett

so i deleted that comment after realizing that it have very limited number of parameters to configure, i posted it too fast :)

actionless avatar Jan 29 '15 18:01 actionless

Filed the proposal to inherit vim's 'shiftwidth' and 'textwidth' settings as #27. For this issue, it's still worth considering some kind of support for custom autopep8 args.

dbarnett avatar Jan 31 '15 08:01 dbarnett

what is the main question here, in which "format" to store the settings?

i think, best of the possible options are or stick to your proposal:

formatter_args[autopep8]=['--indent-size=2', '--ignore=E226,E302,E41']`)

or to just go with the flat settings

autopep8_executable_arguments=['--indent-size=2', '--ignore=E226,E302,E41']

or, mb just store arguments in the same place where executable itself, like

autopep8_executable=['autopep8', '--indent-size=2', '--ignore=E226,E302,E41']

last case seems to me most compact but mb it have some unobvious cons

actionless avatar Jan 31 '15 09:01 actionless

Going with formatter_args[] sounds good to me. We will want a non-global version since it can vary project-to-project which args you want. Probably still keyed off the formatter name, like b:formatter_args['autopep8'] = ['something'], so that you don't invoke formatter B and end up sending it invalid args intended for formatter A.

If we had a buffer-local setting, would we still want a global setting? autopep8 at least has its own global config (~/.config/pep8), and in general you could always use an autocmd to configure buffer-local settings everywhere, so it would mean 2–3 redundant ways to configure each formatter. But I'm not opposed to a global flag too if there's an obvious reason to.

dbarnett avatar Feb 01 '15 18:02 dbarnett

yup, that sounds reasonable

actionless avatar Feb 01 '15 20:02 actionless

Has there been any progress on this?

Edit: I personally was having issues with js-beautify's default indent, but ended up configuring it in ~/.jsbeautifyrc for now.

achalddave avatar Nov 17 '15 03:11 achalddave

Yeah, no progress yet. =(

dbarnett avatar Nov 17 '15 06:11 dbarnett

+1

mindej avatar Aug 14 '19 12:08 mindej

The best way I could find as a workaround is add E1 (everything that corresponds to indentation checking according to https://readthedocs.org/projects/pycodestyle/downloads/pdf/stable/) to my config!

like this:

[pycodestyle]
ignore = E1,E302,E501

tbrodbeck avatar Jul 02 '20 10:07 tbrodbeck