swekaj / php-foldexpr.vim

Vim folding for PHP with foldexpr
MIT License
41 stars 10 forks source link

Indicator on right, how much lines are folded in a fold. #16

Closed ReneFroger closed 9 years ago

ReneFroger commented 9 years ago

Currently I have this code in my vimrc: http://www.gregsexton.org/2011/03/improving-the-text-displayed-in-a-fold/

And there are many variants of lines-of-code indicators. I like it, it gives you a better view how much it's folded.

Except for PHP files. Then I use your plugin, but I'm not able to see how much is folded. It's bothering me. So I was wondering if there is any chance to integrate this in your awesome plugin, like "'44 lines of code" '

Thanks in advance for your reply.

ReneFroger commented 9 years ago

Another tips: http://vim.wikia.com/wiki/Customize_text_for_closed_folds

swekaj commented 9 years ago

Ooh, that's actually pretty neat. I'll see if I can incorporate it.

swekaj commented 9 years ago

The README is now updated, so this is all done. I left the fold dashes in the same format that they were (which also matches Vim's default). If you'd like the ability to change that, I can look into it.

I also elected to keep the dashes for the filler character, again that could be an option if anyone has a strong desire to customize it.

ReneFroger commented 9 years ago

Thanks for fixing this! I downloaded your plugin again.

And I added this to my Vimrc:

" Enable the custom foldtext option.
let b:phpfold_text = 1
 " Display the line count on the right instead of the left.
let b:phpfold_text_right_lines = 1
" - Display the percentage of lines the fold represents.
let b:phpfold_text_percent = 1

After restarting Vim and opening PHP-files, this changes nothing. I still see the same Vim default fold (# lines) the foldtext is still on left. And no percentages are showed. Was it really working?

ReneFroger commented 9 years ago

For reference, I use this code for my other filetypes (Vim, HTML, js, you name it).

http://vimrcfu.com/snippet/20

swekaj commented 9 years ago

It works for me. Can you verify that the variables and foldtext function are being properly set?

set foldtext
echo b:phpfold_text_right_lines
echo b:phpfold_text_percent

They weren't working for me initially, but that's because I used global variables (g:) instead of buffer (b:).

ReneFroger commented 9 years ago

set foldtext gives me foldtext=GetPhpFoldText()

echo b:phpfold_text_right_lines gives me a 0.

echo b:phpfold_text_percent gives me a 0.

So the variables are not properly set. When I set the let b:phpfold_text_right_lines = 1 and let b:phpfold_text_percent = 1 in the command line, the folds works properly.

So they're not set from my Vimrc, (I use Gvim on Windows). I tried it again. And it's still not working. I don't have any idea what caused this. Propably something from your plugin. First, the vimrc is loaded. Then the plugins are loaded. So something in your plugin sets the settings back at 0?

This is the full snippet in the Vimrc:

" PHP folding plugin  {

let g:DisableAutoPHPFolding = 0
" Enable the custom foldtext option.
 let b:phpfold_text = 1
" Display the line count on the right instead of the left.
 let b:phpfold_text_right_lines = 1
  " - Display the percentage of lines the fold represents.
 let b:phpfold_text_percent = 1

A weird thing is that echo b:phpfold_text gives me an error (E121, E15), undefined variable and invalid expression. Then it's strangely that

echo b:phpfold_text_right_lines
echo b:phpfold_text_percent

will not show any errors.

swekaj commented 9 years ago

What other plugins do you have? Where is the g:DisableAutoPHPFolding variable used? I don't think it's my plugin, it's only setting the variables if they don't exist when the plugin is loaded.

ReneFroger commented 9 years ago

Probably I will never figured it out. I solved it with

autocmd BufRead,BufNewFile *.php,*.inc let b:phpfold_text_right_lines = 1 autocmd BufRead,BufNewFile *.php,*.inc let b:phpfold_text_percent = 1

swekaj commented 9 years ago

I have noticed that I encounter the same issue when I open a file from within vim. I'm guessing it's because of a project management plugin, however, I haven't haven't done any testing to see why the variables don't stick, and I'm not quite sure how.

I have thought about adding global variables in addition to the buffer variables, see if they stick.

On Sunday, November 23, 2014, ReneFroger notifications@github.com wrote:

Probably I will never figured it out. I solved it with

autocmd BufRead,BufNewFile .php,.inc let b:phpfold_text_rightlines = 1 autocmd BufRead,BufNewFile .php,_.inc let b:phpfold_text_percent = 1

— Reply to this email directly or view it on GitHub https://github.com/swekaj/php-foldexpr.vim/issues/16#issuecomment-64136712 .

ReneFroger commented 9 years ago

@swekaj Thanks for your reply, I don't use any project management plugin, as far as I know. But I'm running many plugins here.

When you succeed in debug this problem, could you let me know which plugin it was? I will be curious then.

For now, my autocmd solution works. But it's not a ideal solution, however.