language-python icon indicating copy to clipboard operation
language-python copied to clipboard

Python, docstring and folding

Open projetmbc opened this issue 10 years ago • 8 comments

Hello.

The following docstring is not managed because its content is not indented (this is a legal use of triple quotes).

class MyClass:
    """
Here is a docstring  : bla,
bla,
bla...
    """
    def __init__(self):
        ...

projetmbc avatar Jun 09 '15 20:06 projetmbc

Here is another example showing a problem with indentation. Just try this to see that example can be folded.

    """
example
    bla, bla, bla....

bla, bla, bla....
    """

projetmbc avatar Jun 10 '15 18:06 projetmbc

Furthermore, since folding is indent-based without regards to the code flow, some methods are simply not foldable. A codebase I work on (external framework, so we're not at liberty to fix up coding style as it would make future merges difficult) is full of examples where the authors comment out lines of code in the middle of methods by putting the '#' on the first column. See attached screenshot for one such example.

odoo_code_folding_impossible

I'm unfamiliar with the way Atom handles folding. Is it possible even to ignore unindents if they're part of a docstring or comment?

jrial avatar Jan 07 '16 12:01 jrial

Atom folds purely based on indentation right now unfortunately. Sorry about that.

winstliu avatar Jan 07 '16 12:01 winstliu

Ah, I see, it's an issue in Atom itself, and there already exists an issue for that: atom/atom#3442 so essentially this is blocked until that one's resolved.

Still worth keeping this one open, as the case with Python is a bit more difficult given that the language is indent-based, as opposed to say C++ or PHP.

jrial avatar Jan 07 '16 13:01 jrial

Works fine for me now, using the new tree-sitter parser. Wouldn't close this issue until it becomes enabled by default, but for those visiting this issue in the meantime: in Settings => Core, enable "Use Tree Sitter Parsers".

jrial avatar Mar 23 '18 10:03 jrial

It doesn't work for me with Use Tree Sitter Parsers. https://github.com/atom/atom/issues/20128

boogiefromzk avatar Nov 16 '19 12:11 boogiefromzk

@boogiefromzk I see that issue is about PHP and not Python. And PHP apparently doesn't use the tree-sitter parsers.

@projetmbc Can you please verify that your issue has been resolved, and close this?

jrial avatar Nov 18 '19 11:11 jrial

Is it normal that the docstrings are not foldable ?

If it is wanted, I can close this issue. If not I will close this issue and open another.

projetmbc avatar Nov 18 '19 16:11 projetmbc