AndrewRadev/splitjoin.vim

Python splitting and indentation

jamespeapen opened this issue · 2 comments

I just installed the plugin and tried it on my python script, but I'm not sure if I'm getting correct splitting. The first item stays on the same line when split and indentation is off.

a = (1, 2, 3, 4)
b = {1:1, 2:2, 3:3, 4:4}
c = [1, 2, 3]
a = (1,                                                                                                
        2,                                                                          
        3,                                                                          
        4)                                                                          
b = {                                                                               
        1:1,                                                                        
        2:2,                                                                        
        3:3,                                                                        
        4:4                                                                         
        }                                                                           
                                                                                    
c = [1,                                                                             
        2,                                                                          
        3]                                                                          

It is, however, working with R.

a <- function(a, b, c) {
  b <- c(1, 2, 3)
}
a <- function(a,                                                                                       
              b,                                                                    
              c) {                                                                  
  b <- c(                                                                       
    1,                                                                              
    2,                                                                              
    3                                                                               
  )                                                                                 
}  

I'm using neovim 7.2 and tried it both with and without my other plugins.

Indentation is something that the plugin doesn't handle (with some minor exceptions) -- the code that is split is auto-indented however Vim indents the code using ==. In your examples, if you try to reindent the split code, I think it will stay as it is. If you'd like to change that, you could use a different indent expression -- This one might work as you'd expect, but I don't really use python, so I'm not sure what the "correct" way is: https://github.com/Vimjas/vim-python-pep8-indent

As for the brackets, try using this setting:

*splitjoin_python_brackets_on_separate_lines*
>
let g:splitjoin_python_brackets_on_separate_lines = 1
<
Default value: 0
If set to 1, then python will split lists and tuples so that the opening and
closing bracket are placed on separate lines. If it's 0, the first argument
will remain where it is, and the rest will be split on separate lines.
Example:
>
# let g:splitjoin_python_brackets_on_separate_lines = 1
some_method(
one,
two
)
# let g:splitjoin_python_brackets_on_separate_lines = 0
some_method(one,
two)
<
The first example might look a bit odd, but if you have the python-pep8-indent
plugin (https://github.com/hynek/vim-python-pep8-indent), it should look quite
reasonable.

That works - thanks!