braceless.vim icon indicating copy to clipboard operation
braceless.vim copied to clipboard

Incorrect auto-indenting after decorator line?

Open goodboy opened this issue 8 years ago • 4 comments

Whenever I write out a decorator line and then hit enter braceless seems to increase the indent level:

@mydecorator<ENTER>
    def myfunc(...

This seems wrong; there should be not indent added - maybe I'm also wrong in guessing this is braceless's doing?
It seems to go away when I disable the plugin though...

goodboy avatar Feb 14 '17 00:02 goodboy

Yeah, this is due to a bit of goofiness in the way block matching works. Decorators are seen as part of the function, so it's correctly (questionable) indenting what it thinks is the function body. It should autocorrect the indent when you complete the function signature with ):, though.

tweekmonster avatar Feb 15 '17 03:02 tweekmonster

@tweekmonster yeah I'm not sure I follow.

so it's correctly (questionable) indenting what it thinks is the function body.

@ syntax does not necessarily mean the next line will be a def line let alone a function body? In fact this same problem exists if you try to stack decorator lines:

@pytest.fixture<ENTER>
    |  # <- that's the cursor...
@classmethod
def my_func(cls):
    pass

A decorator is more like a function call no?

def decorator(**kwargs):
    def wrapper(*args):
        func(*args, **kwargs)
    return wrapper

decorator()<ENTER>

will take you to the next line as expected. It seems that only when a @ is present is the needless indentation done?

@decorator(doggy='dirty')<ENTER>
    def...

Decorators are seen as part of the function

Yeah that just seems confusing to me because why should they be seen that way? Decorator syntax is language specific sugar - I don't think it should have anything to do with block detection? In fact I would argue that since braceless is attempting to be non-Python specific then this especially shouldn't happen.

You're right though the def line does fix it self once you right the terminating : I still find it unexpected/un-intuitive.

goodboy avatar Feb 15 '17 16:02 goodboy

What I meant by it being questionably correct is that a decorator is part of the function's block (as far as braceless is concerned). If you type vaP, just the function is selected. If you add an additional aP, the selection will be extended to the decorator. Block selection is a bit detached from autoindent, however.

It is unintuitive. But, I don't have time to dig deep into it right now. If you want to delve into it, you'll want to look at s:indent_handler.block in autoload/braceless/python.vim or s:handle_blocks in autoload/braceless/indent.vim.

Something else I noticed is that if you press == on the incorrectly indented line, it will be corrected.

A little off topic: I'm hoping that this progresses into something that'll allow me to create a much simpler version of braceless: https://github.com/neovim/neovim/issues/6052. But, it most likely won't find it's way upstream to Vim.

tweekmonster avatar Feb 15 '17 17:02 tweekmonster

@tweekmonster cool sounds good. Not sure if I'll be able to dig any sooner then you but I appreciate at least getting this on the backlog :+1:

goodboy avatar Feb 15 '17 18:02 goodboy