pseewald / vim-anyfold

Language agnostic vim plugin for folding and motion based on indentation.
MIT License
268 stars 11 forks source link

python fold on continuous comment fail #17

Closed yhuangatimvucom closed 6 years ago

yhuangatimvucom commented 6 years ago

These are my configuration for vim-anyfold in .vimrc " configuration for vim-anyfold syntax on let anyfold_activate = 1 let anyfold_fold_comments = 1 set foldlevel=0 " configuration for vim-anyfold

This is the py file, which I want to fold, since there are lots of continuous comments, I want to fold them, but vim-anyfold not working. https://www.dropbox.com/s/dmivhrx6j8h3na8/lesson1.py?dl=0

huangyingw commented 6 years ago

@pseewald , hi, I am huangyingw, yhuangatimvucom is my office github account, this issue is much more difficult, I don't think I could fix it myself this time :(

huangyingw commented 6 years ago

did some debug tonight: it will recognize the line, with # in the first col as comment:

abcfds

while for line like this, the # is not in the first col, would not be recognized as comment.

abcfds

I am trying to fix

huangyingw commented 6 years ago

I am trying with this change to identify indented comments, but fail :(. Will continue to struggle tomorrow after work.

function! s:CommentLine(lnum, force) abort if indent(a:lnum) >= &sw && !a:force return 0 else return getline(a:lnum) =~? '^.#.' \ || synIDattr(synID(a:lnum,indent(a:lnum)+1,1),"name") =~? 'comment|string' endif endfunction

pseewald commented 6 years ago

Hi, vim-anyfold does not fold indented comments on purpose. The problem is that synID (that is called to recognize comments) is very slow. Therefore it is called on unindented lines only. However it is really easy to provide an option to fold all comment lines (in the function s:CommentLine above, just set force always to 1). You don't need to spend time on this, I can easily provide this as an option.

pseewald commented 6 years ago

I just committed the fix for this issue. In order to enable this option, put let anyfold_identify_comments = 2 in your vimrc. Can you let me know if it works for you? Thanks!

huangyingw commented 6 years ago

it works well, now it is very very perfect, thanks for the quick commit.

pseewald commented 6 years ago

@huangyingw the defaults for comments have changed in commit e73a3921b5c140b5d0a27e9fd5d3f7cb903ee5f2 because I wanted vim-anyfold to be faster by default. This completely changes the meaning of anyfold_identify_comments. You may set it to 1 if you want to fold Python comments starting with # (fast). You need to set it to 2 if you want to fold Python multiline comments using """ (slow). No matter what value you use, indented comments are always identified.

huangyingw commented 6 years ago

Thanks for letting me know, I have synced with your repo, till now, haven't seen any issue.

I am setting anyfold_identify_comments to 2. It could fold python multi-line comments using ", I haven't tried """ yet.

I just did an experiment:

I set anyfold_identify_comments to 1, and python multi-line comments using " also work.

So, for now, I would like to set anyfold_identify_comments to 1, to have better performance.

Thanks again for great work, if any issue, I will let you know, or try to fix and then let you know :)

On 3/14/18 5:36 AM, Patrick Seewald wrote:

@huangyingw https://github.com/huangyingw the defaults for comments have changed in commit e73a392 https://github.com/pseewald/vim-anyfold/commit/e73a3921b5c140b5d0a27e9fd5d3f7cb903ee5f2 because I wanted vim-anyfold to be faster by default. This completely changes the meaning of |anyfold_identify_comments|. You may set it to 1 if you want to fold Python comments starting with |#| (fast). You need to set it to 2 if you want to fold Python multiline comments using |"""| (slow). No matter what value you use, indented comments are always identified.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pseewald/vim-anyfold/issues/17#issuecomment-373005417, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFmbVxRq_mWZerpTgQc7hyMURSKOWpyks5teQ7egaJpZM4SDIlU.