Code Monkey home page Code Monkey logo

Comments (8)

AndrewRadev avatar AndrewRadev commented on June 8, 2024

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?

from splitjoin.vim.

ereOn avatar ereOn commented on June 8, 2024

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 ?

from splitjoin.vim.

AndrewRadev avatar AndrewRadev commented on June 8, 2024

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

from splitjoin.vim.

ereOn avatar ereOn commented on June 8, 2024

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.

from splitjoin.vim.

AndrewRadev avatar AndrewRadev commented on June 8, 2024

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.

from splitjoin.vim.

ereOn avatar ereOn commented on June 8, 2024

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 !

from splitjoin.vim.

AndrewRadev avatar AndrewRadev commented on June 8, 2024

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.

from splitjoin.vim.

AndrewRadev avatar AndrewRadev commented on June 8, 2024

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.

from splitjoin.vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.