Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Python syntax support #63

Closed
ereOn opened this issue Feb 10, 2015 · 8 comments
Closed

Enhance Python syntax support #63

ereOn opened this issue Feb 10, 2015 · 8 comments

Comments

@ereOn
Copy link

ereOn commented Feb 10, 2015

The current behavior with Python does not seem to be configurable:

When using gS on a function call like:

some_function(a, b, c, d, e)

If get:

some_function(a,
              b,
              c,
              d,
              e)

Which may be fine for some people, but the default Python syntax I get when I type the line-endings manually gives me:

some_function(
    a,
    b,
    c,
    d,
    e,
)

Is there a way to use the default syntax rules configured by the user to get the output I expect ?

Thanks for the good work !

@AndrewRadev
Copy link
Owner

Thanks for the good work !

Thank you for the kind words :).

How did you set up your python indentation? On my machine, this is how the code gets indented:

some_function(a,
        b,
        c,
        d,
        e)

The indentation of b, c, and so on is simply two shiftwidths, each of which is 4 spaces. I'm not sure how your indentation ended up like that.

Also, regarding this formatting:

some_function(
    a,
    b,
    c,
    d,
    e,
)

First off, notice that there's a difference with the previous one -- there's a newline after (. More importantly, though, for me, if I select these lines in visual mode and run = (or, if I type it manually), I get:

some_function(
    a,
    b,
    c,
    d,
    e,
    )

What kind of settings do you have for python? Is it possible that you have an older version of Vim or something? Could you tell me the output of vim --version?

@ereOn
Copy link
Author

ereOn commented Feb 11, 2015

I'm having the "issue" (likely not the right word, as I feel the behavior is expected) on several platforms, with different Vim versions.

On my Windows machine, my current version is:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov 24 2014 08:07:47)

I'm using python-syntax and vim-python-pep8-indent.

Actually, after re-reading the Github page I realize the behavior I'm facing might be due to this last plugin.

It tested without it and the behavior you describe seems to happen indeed. But I'm still afraid this way of splitting a function call is not PEP8 compliant.

At this point, I'm not sure what's the best course of action: It feels to me that if splitjoin had a way of putting the first function call argument on the next line, the other plugin syntax would kick-in automatically and I would get the expected output.

Is there a way to achieve this behavior ? If you are not willing to reflect that change/option in your repository, I wouldn't mind doing the change myself, but I may need some directions.

What do you think ?

@AndrewRadev
Copy link
Owner

I don't mind adding an option to put the first argument on the next line, I'll take a look at it tomorrow.

@ereOn
Copy link
Author

ereOn commented Feb 11, 2015

I took a shot at the change and made a pull request for it (I actually made two commits but the github view only shows one for some reason).

I did not add an option or anything so you may not want to merge it as-is at it will break the current behavior.

I tested with the pep8 plugin I mentionned and it works like wonders !

Note: Your code base is really well organized and it was a breeze to change it. Kudos for that. Let me know if you plan to add the feature and if I can be of any help.

Thanks again for the hard work.

@AndrewRadev
Copy link
Owner

I've made the fixes in the master branch, I've added an option for python indentation. You'd need to put this in your vimrc:

let g:splitjoin_python_brackets_on_separate_lines = 1

This should give you the indentation you want, combined with the pep8 indent plugin. Let me know whether it works for you or not.

@ereOn
Copy link
Author

ereOn commented Feb 13, 2015

The change seems to do the trick for function calls (basically for lists, tuples, and everything similar) but it doesn't work for dicts.

I basically get the following result:

a = {1: 2, 3: 4, 5: 6}
a = {
    1: 2,
    3: 4,
    5: 6
        }

What I should get is:

a = {
    1: 2,
    3: 4,
    5: 6,
}

The thing is, PEP8 indentation actually takes care of shift left/right so no extra << or >> should be done in this case.

Thanks !

@AndrewRadev
Copy link
Owner

The problem is, if you don't have the plugin, you need the extra shifts :/. Here's the default Vim indentation if I just leave it to ==:

spam = {'spam': [1, 2, 3], 'spam, spam': 'eggs'}

spam = {
'spam': [1, 2, 3],
'spam, spam': 'eggs'
}

And putting no quotes results in (something that's technically correct):

spam = {spam: [1, 2, 3], eggs: 'eggs'}

spam = {
        spam: [1, 2, 3],
        eggs: 'eggs'
        }

The pep8 plugin might take care of both of these, but the built-in doesn't and I'd really like the plugin to work on its own, without additional extras :/. Arguably, the built-in logic might be broken/not good enough, but I'd still like to be compatible with it.

I've committed a potential fix, could you try it out? It works okay for the built-in indentation (once you shift them in, running one more == doesn't change indentation), and I think it should work just fine for the pep8-plugin one.

@AndrewRadev
Copy link
Owner

I'm hoping that my fix improved the situation, so for the time being, I'll close the issue. Feel free to reopen if you'd like to continue the discussion on how to set things up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants