tweekmonster / braceless.vim

:snake: Text objects, folding, and more for Python and other indented languages.
395 stars 13 forks source link

Is it possible to tune dedenting by Enter key? #28

Closed 9seconds closed 8 years ago

9seconds commented 8 years ago

Hi!

braceless works great but I want to tune it a bit for my own need. Is it possible to dedent if I press Enter 2 times, not 1?

An example: usually I write functions like this, with blocks, separated by 1 empty lines:

def unique(elements):
    already_met = set()
    items = []

    for element in elements:
        if element not in already_met:
            items.append(element)
            already_met.add(element)

    return items

If I type items = [] then it is not possible to press Enter 2 times to input for elements in elements, because, well, after first keypress I dedent. But as a workaround, if I enter return at the start, it works as expected.

Do I need to set anything in my vimrc to support such behavior? Or how can I tune braceless to work as I want?

Thanks!

tweekmonster commented 8 years ago

This is not configurable. I can't decide whether or not I like it now that I've been using it for a while. It was originally 2 lines, but that felt too far to go to dedent in some cases. I wanted to be able to maintain momentum while coding, but I guess that'll be hard to achieve without braces.

Perhaps it should be left so that the indent stays with the block body's indent level, but only dedent when there's clear call for it, like right after a return. What do you think?

I can't think of any off the top of my head, but can you think of any other cases where a blank line from the user should almost always dedent?

9seconds commented 8 years ago

Dedenting after return is going to work in my case but I think that it might break other people usecases where there is no explicit return statement (function returns None implicitly): in such cases current behavior works really well.

Is it possible to add option like g:braceless_dedent_after_return_only with default 0? What do you think?

tweekmonster commented 8 years ago

@9seconds Sorry for the delayed response. I think an option to tune or turn off auto-dedent is a good idea. I'll work on adding it when I find some spare time today.

It also might be a good idea to point out the use of insert mode <c-i> and <c-d> in the docs since tabs is so important to Python dev.

tweekmonster commented 8 years ago

@9seconds Added g:braceless_auto_dedent_gap. Set it to 0 to disable or some other number to define the blank line gap before dedent. It can use the b: prefix if you want it to be per-buffer.