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

Fold decorators in with the code they affect #86

Open
kylemacfarlane opened this issue Mar 5, 2017 · 8 comments
Open

Fold decorators in with the code they affect #86

kylemacfarlane opened this issue Mar 5, 2017 · 8 comments

Comments

@kylemacfarlane
Copy link

With the following block:

@property
def test(self):
    pass

This plugin folds it like:

@property
+---  2 lines def test(self):---------------

But python-mode folds it like:

def test(self): ------------------------- 3-

Would it be possible to fold in the decorators like python-mode?

@nfnty
Copy link
Collaborator

nfnty commented Mar 5, 2017

It's possible with backtracking, but it would break docstrings as currently implemented. I don't see why you'd want to as it greatly decreases readability and predictability of folds. I vote against including this functionality, even as an option.

@kylemacfarlane
Copy link
Author

I don't see how it would affect readability. Maybe in a class it would make it harder to distinguish properties/getters/setters but in things like Django where you use decorators to check permissions, control caching, CSRF, transactions, etc I'm sometimes seeing almost as much code left outside of folds as inside.

@tmhedberg
Copy link
Owner

Personally, I can see the usefulness of this, but it would require major changes to the code to support it without introducing bugs. For now, it's probably not worth it for the relatively minor improvement.

@idahogray
Copy link

I realize this issue is a little dated but I would like to log my support for implementing it. Something like this could be really useful for projects that use flask, click, or a similar API. Once thing to keep in mind is that decorators can be multiple lines.

I would offer my support but I don't know anything about vimscript. I can offer some example code to be folded, if that would be helpful.

@disconsis
Copy link

disconsis commented Jun 28, 2018

+1 for decorator folding
As to the readability issue, adding an option like the ones for docstrings can help. IMO it makes sense for a lot of projects and people, since decorators are essentially part of the function as well.
I do agree it reduces the predictability, but the foldstring could possibly be modified to show that decorators have been folded - something like

+-- 2 lines: @ def test(self): ----------------------------

Don't really know how feasible that is though.

@TheLocehiliosan
Copy link

I'd like to register another vote for including decorators in folds. I like the idea of including the @ in the folded text to indicate there is a folded decorator present.

@lordmauve
Copy link

I found SimpylFold while looking for a fold plugin that folds decorators, so am disappointed it doesn't.

I like the idea of @ def - could be @@ def if there are two decorators?

To add my 2c, I'd like to see built-in decorators property, staticmethod and classmethod displayed in the fold text in place of def:

+--  2 lines: classmethod setUpClass(cls): ----------------------------

This would not be dissimilar to how Sphinx renders these (example).

Of course it's not possible to know whether the decorator is genuinely the known one or a different decorator of the same name, but practically I would think matching by name is reliable enough.

Some well-known decorators in the standard library would also be useful - specifically those that change the type of a function rather than just enhancing its behaviour

  • contextlib.contextmanager
  • asyncio.coroutine/types.coroutine
  • abc.abstractmethod/abc.abstractproperty

For example

@contextlib.contextmanager
def redirect_output(stream):

could fold as

+--  9 lines: contextmanager redirect_output(stream): ----------------------------

@fleetingbytes
Copy link

I would also like to seethe decorator folding feature implemented.

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

No branches or pull requests

8 participants