Wednesday, February 11, 2015

Re: Can someone recommend a plugin to fold python long dict spanning over many lines?



2015-02-11 19:02 GMT+03:00 Ben Fritz <fritzophrenic@gmail.com>:
On Wednesday, February 11, 2015 at 12:52:12 AM UTC-6, Bao Niu wrote:
> No, sorry for this abrupt assertion but indentation is no good in this case. That's why there are many plugins based on expr. Folding is simply too rigid for this job.
>
> I just want to write a wrapper function to fold those long ducts. Any thoughts?
>

Sorry for my blunder earlier, I'll try to make it up.

It looks like Python does not provide syntax folding. As Tim suggests, "indent" folding is normally recommended since Python indentation is semantic.

I have no idea who may ever want indentation folding. Usually in any case indentation matters indented code looks like

    start of block
        indented block
    [end of block]

and you want `start of block` be folded with indented block and displayed in a fold text because it is usually a block header. *Not* just fold out the indented block and display rather meaningless first line of indented block. And also include end of block as well if it is there.

Things become more complicated if `start of block` spans on multiple lines, but simple indentation folding is not convenient here as well because it can partly fold `start of block`.
 

But others have tried making plugins for better folding, I don't know how good they are (and there may be more, these are from http://vim.wikia.com/wiki/Syntax_folding_of_Python_files#Plugins):

http://www.vim.org/scripts/script.php?script_id=2527
http://www.vim.org/scripts/script.php?script_id=515

If you write your own, you probably can use the indent() function to use the indentation of a line, except for in certain circumstances which you define. Take a look at :help fold-expr for how to write a function that defines the folding, then do a :setl foldmethod=expr foldexpr=MyPythonFoldFunction() to use it.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: