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

vim packages not being folded. #251

Open
Jeansen opened this issue Oct 29, 2017 · 32 comments
Open

vim packages not being folded. #251

Jeansen opened this issue Oct 29, 2017 · 32 comments

Comments

@Jeansen
Copy link

Jeansen commented Oct 29, 2017

Description of issue

I am not able to fold packages.

Your description here!

Maybe I am missing something, but though I have set foldmethod=syntax and fiddled around with all the different settings, I get everything to work - except code-folding for packages.

E.g.:

package Null {
    my $null = bless {}, __PACKAGE__;
    sub AUTOLOAD {$null}
    sub ok       {0}
}

My settings:

let g:perl_fold = 1
let g:perl_include_pod = 1
let g:perl_extended_vars=1
let g:perl_fold_blocks = 1

I've also tried let g:perl_nofold_packages with 0/1, but no setting worked.

If it is a real bug, I'd definitely appreciate a fix :) If I just missed something, I would be grateful for any help.

@hoelzro
Copy link
Member

hoelzro commented Oct 29, 2017

Thanks for the bug report, @Jeansen! It seems that this form is folded:

package Null;

my $null = bless {}, __PACKAGE__;
sub AUTOLOAD {$null}
sub ok       {0}

But not the one you posted. Let's see if we can get that fixed!

@Jeansen
Copy link
Author

Jeansen commented Oct 29, 2017

Hey @hoelzro! Thank's for the quick answer. I would really appreciate a fix 😄 If I can be of support in any way, just let me know!

hoelzro added a commit that referenced this issue Oct 30, 2017
@hoelzro
Copy link
Member

hoelzro commented Oct 30, 2017

@Jeansen I just pushed some tests for "braced" packages - we could benefit from more tests (ex. package NAME VERSION { ... } is untested), and the implementation seems to have a bug with your exact example (for some reason the fold ends at sub ok). Also nice would be to add a CPAN module that uses brace packages to the corpus test, but that's something I'll probably need to do.

If you feel comfortable writing tests, that would be great - if you feel up to the challenge of debugging why the folding Vimscript isn't working, that would be even better!

@Jeansen
Copy link
Author

Jeansen commented Oct 30, 2017

@hoelzro Thank you. I'll have a look and see, what I can do. I am no Vimscript expert, but I'll take the challenge. But it might take some time.

@Jeansen
Copy link
Author

Jeansen commented Nov 4, 2017

@hoelzro I am not sure, if I am missing something, but when I use the following vimrc and try to fold the snippet from #251 (comment) then I do not see any change. Here's my minimalistic vimrc:

#!/usr/bin/vim

set encoding=utf-8
scriptencoding utf-8
set termencoding=utf-8
set shell=bash
filetype plugin indent on 
syntax on
set foldmethod=syntax

let g:perl_fold = 1
let g:perl_nofold_packages=0

call plug#begin('~/.vim/plugged')

Plug 'vim-perl/vim-perl', { 'branch': 'dev', 'for': 'perl', 'do': 'make clean carp dancer highlight-all-pragmas moose test-more try-tiny' }

call plug#end()

@hoelzro
Copy link
Member

hoelzro commented Nov 4, 2017

Hmm...looking at the code it turns out that setting perl_nofold_packages to anything will disable the folding; I'll fix that up in a bit!

@Jeansen
Copy link
Author

Jeansen commented Nov 4, 2017

Oh...well. Now I am ashamed to not have checked it myself 😊 Must be, because I am still in the Perl-Universe 😆

@Jeansen
Copy link
Author

Jeansen commented Nov 4, 2017

And yes, without perl_nofold_packages it works as described

@Jeansen
Copy link
Author

Jeansen commented Nov 4, 2017

I have made a PR with something working. Could you check, please? 😄

@Jeansen
Copy link
Author

Jeansen commented Nov 5, 2017

BTW, I noticed, that I have to delete my perl.vim in the vim home folder. Should it not be overwritten/overruled by the plugin installation?

@hoelzro
Copy link
Member

hoelzro commented Nov 5, 2017

It depends on how you're installing your plugins - if you're using something like Pathogen, for example, $HOME/.vim/syntax/perl.vim will take precedence over $HOME/.vim/bundle/vim-perl/syntax/perl.vim.

@hoelzro
Copy link
Member

hoelzro commented Jan 3, 2018

@Jeansen Sorry for the delay on this - I don't get a lot of time to work on vim-perl, and every time I do I feel like I'm just remembering where I was at! I believe I have fixed the package folding issue - could you grab what's on the dev branch and verify that it works?

@Jeansen
Copy link
Author

Jeansen commented Jan 5, 2018

@hoelzro No problem, same here ;) Backage folding issue seems to be resolved. Great work! Thank you 😃

@Jeansen
Copy link
Author

Jeansen commented Mar 18, 2018

Hey @hoelzro. I hope you are doing fine? After some months of absence, I finally found some time to get back to my project. Thou your fix solve some folding problems, it still is not doing everything as expected. It seems to be a bit too eager ;-)

If I use your current fix from the development branch and use syntax folding on https://github.com/Jeansen/cdmn/blob/master/cdmn , then some packages are recursively folded beneath package cdmn::math, though they are defined on the same level. That is,cdmn::contstants is folded beneath package cdmn::math. cdmn::proc is folded beneath cdmn::constants and so son.

Could you check again? I bet it is just a very little change that has to be done ;)

@hoelzro
Copy link
Member

hoelzro commented Mar 19, 2018

Hi @Jeansen! I will try to check this out later today

@hoelzro
Copy link
Member

hoelzro commented Mar 28, 2018

Hi again @Jeansen - sorry this took me so long to check out! I had some time to look tonight, and I was able to fix it - but not without breaking folding for anonymous subs. I think I'll need to step back and see how I unify these two ideas.

@Jeansen
Copy link
Author

Jeansen commented Mar 29, 2018

Hi @hoelzro. Thanks for all your efforts! Do not hurry yourself. There is no rush 😉 But maybe you will find some more time to also fix the folding for anonymous subs. Keep on the good work! 😄

@Jeansen
Copy link
Author

Jeansen commented Mar 29, 2018

@hoelzro: Did you push your fix? I cannot find it on dev ...

@hoelzro
Copy link
Member

hoelzro commented Mar 29, 2018

@Jeansen No fix yet, I'm afraid - I can't push what I have since it breaks anonymous subs =(

@Jeansen
Copy link
Author

Jeansen commented Mar 31, 2018

Oh, ok. No problem. Then I'll wait until you find a fix 😃

@sdondley
Copy link

sdondley commented Apr 2, 2019

Has this issue been abandoned? At first glance, this plugin seems unmaintained and kind of unusable but maybe I'm using it wrong.

@petdance
Copy link
Contributor

petdance commented Apr 2, 2019

Not abandoned. Still maintained. But it looks like nobody has a fix for it.

@sdondley
Copy link

sdondley commented Apr 2, 2019

K, thanks. I'm investigating. Started with a clean vim install on a new OS. I'm poking around. I just know enough vim scripting to be dangerous, though.

@petdance
Copy link
Contributor

petdance commented Apr 2, 2019

That's OK. Any vim scripting is dangerous.

@sdondley
Copy link

sdondley commented Apr 2, 2019

Well, so commenting out line 394 in /syntax/perl.vim restores indenting but you lose highlighting.

syn match perlFunction "\<sub\>\_s*" nextgroup=perlSubDeclaration

@sdondley
Copy link

sdondley commented Apr 2, 2019

And commenting out line 393 keeps both the highlighting and the indenting. But not sure if that might break folding or what. Line 393:

syn region perlSubDeclaration start="" end="[;{]" contains=perlSubName,perlSubPrototype,perlSubAttribute,perlSubSignature,perlComment contained transparent

@sdondley
Copy link

sdondley commented Apr 2, 2019

Yeah, that breaks folding. It folds all subs into a singe fold.

@sdondley
Copy link

sdondley commented Apr 3, 2019

OK, this seems to do the trick:

syn region perlSubDeclaration start="\_.\{-}{"hs=e+1 end="[;{]"he=e-1 contains=perlSubName,perlSubPrototype,perlSubAttribute,perlSubSignature,perlComment contained transparent

This line should replace line 392 (or thereabout).

Untested, though. How do I do that? Is this a perl module I can download?

UPDATE: NVM, figured out how to run the tests.

@hoelzro
Copy link
Member

hoelzro commented Apr 3, 2019

@sdondley Thanks for looking into this - by the way, if you want quick feedback on whether or not a change would break something, the test suite runs highlighting and folding against some known sharp corners, as well as a pretty good corpus of Perl modules from the CPAN. It even gives you pretty feedback like this for highlighting failures:

highlight-test-example

You may need to install some Perl modules to run the test suite, but we're happy to assist!

@sdondley
Copy link

sdondley commented Apr 3, 2019

Yeah, just got done running the tests. As I suspected, it failed on anon subroutines. Not sure what the corpus tests are but it failed many of those.

But basically the issue is that the regions is "covering" the braces. By adjusting where the region begins and ends with the offset values, you can "move" the beginning and ending of the region so the braces are "uncovered." Then the indentation will work properly.

@sdondley
Copy link

sdondley commented Apr 3, 2019

Oops, all these previous comments of mine were mean for #267. Sorry!

@hoelzro
Copy link
Member

hoelzro commented Apr 4, 2019

Ah, ok - vim-perl could really use some proper indent tests! The "corpus" tests are essentially golden master tests that make sure that highlighting and folding is consistent across a few modules I picked - they make sure that, for the most part, users don't see code suddenly highlight differently when a change is made.

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

4 participants