PIV icon indicating copy to clipboard operation
PIV copied to clipboard

Losing syntax on save

Open mauserrifle opened this issue 12 years ago • 13 comments

I'm using the full spf13-vim package, but I think this issue is related to PIV. When I edit most files of projects (old php code with functions only, or a big class file) I lose syntax highlighting after saving. I got a sample code to reproduce the problem: http://pastebin.com/UCKxiPQd

  1. Open the file go to the end (G). Syntax should be broken already (look at the variable colors)
  2. Go back to the first line (gg) and scroll down to the end using }. Syntax is working!
  3. Save the file (:w). Syntax is broken again

The strange thing is: if i remove something like the first method (get_id) the problem is gone. When I delete the constants, the problem is gone. Not sure how to fix it myself. I assume the highlighter is breaking on some pattern but that is currently out of my league :(

Due to this bug vim is not usable for all my projects as it happens in almost all files. Hope this can be fixed!

mauserrifle avatar Sep 18 '12 13:09 mauserrifle

Got a temporary fix:

:syn on

That brings back highlighting.

Tried to make a autocmd:

:autocmd BufWriteCmd *.php :syn on

But then the bottom status bar loses style :( Oh well I'm happy I can use :syn on for now.

mauserrifle avatar Sep 18 '12 15:09 mauserrifle

Hmm I have more problems than this. I got a legacy project with horrible code. 1439 lines within one file. With syn on vim takes like 20 seconds to save the file (yes I've timed it). Vim uses 100% CPU during this 20 seconds. Within other editors like Eclipse PDT there is no slowness.

The syntax highlighter seems to be going wild!

With :syn off the save is instant. I tested this with the default spf13-vim config on three machines.

What have I tried without success:

  • Disable folding
  • http://stackoverflow.com/questions/4775605/vim-syntax-highlight-improve-performance
  • Install vim package from debian sid and squeeze
  • Use gvim
  • Use vim in tty1
  • Compile and use the latest version of vim

I can't believe i'm the only one having this issue. The three machines are all debian tho.

With PIV disabled the problem is solved, but no more sweet completion :(

mauserrifle avatar Sep 19 '12 18:09 mauserrifle

You've probably hit some edge case in the syntax file or another plugin. If possible if you could email me the PHP file you are using to generate this I could spend time trying to investigate / reproducing.

Best, Steve

http://stevefrancia.com http://spf13.com http://twitter.com/spf13

On Wednesday, September 19, 2012 at 2:42 PM, mauserrifle wrote:

Hmm I have more problems than this. I got an legacy project with horrible code. 1439 lines within one file. With syn on vim takes like 20 seconds to save the file. Vim uses 100% CPU during this 20 seconds. Within other editors like Eclipse PDT there is no slowness. The syntax highlighter seems to be going wild! With :syn off the save is instant. I tested this with the default spf13-vim config on three machines. What have I tried without success: Disable folding http://stackoverflow.com/questions/4775605/vim-syntax-highlight-improve-performance Install vim package from debian sid and squeeze Use gvim Use vim in tty1 Compile and use the latest version of vim

I can't believe i'm the only one having this issue. The three machines are all debian tho. With PIV disabled the problem is solved, but no more sweet completion :(

— Reply to this email directly or view it on GitHub (https://github.com/spf13/PIV/issues/15#issuecomment-8701734).

spf13 avatar Sep 19 '12 18:09 spf13

Hi Steve,

I have just tried an Arch Linux LiveCD (http://ctkarch.org/), so that is not Debian related. I do not lose the syntax there, but I still have the slow save and 100% CPU on the files i've sent you through e-mail. It even takes 30 seconds because its in virtualbox.

The losing syntax seems Debian related and the slow saving is not Debian related. I think it's one bug, it just acts different on systems.

Regards, Maurice

mauserrifle avatar Sep 20 '12 18:09 mauserrifle

Hello Steve,

Ok I might have precious information.

Slow saving

I changed php_folding to '0' within ~/.vim/bundle/PIV/ftplugin/php.vim

This is 100% the caus of the 20 sec saving! Saving is instant now!

Changed it back to '1' to find its root cause.

The bug is within line 577 of ~/.vim/bundle/PIV/syntax/php.vim:

 syn region phpFoldFunction matchgroup=Storageclass start="^\z(\s*\)\(abstract\s\+\|final\s\+\|private\s\+\|protected\s\+\|public\s\+\|static\s\+\)*function\s\([^};]*$\)\@="rs=e-9 matchgroup=Delimiter end="^\z1}" contains=@phpClFunction,phpFoldHtmlInside,phpFCKeyword contained transparent fold extend

Removing that line fixes my slow save, the same as completely disabling php_folding.

Currently no idea how to debug this line as I am not really a vim expert.

Losing syntax

Still losing syntax highlighting on saving.

Removing the following within ~/.vim/bundle/PIV/syntax/php.vim:

" Clusters
syn cluster phpClConst contains=phpFunctions,phpClasses,phpIdentifier,phpStatement,phpOperator,phpStringSingle,phpStringDouble,phpBacktick,phpNumber,phpType,phpBoolean,phpStructure,phpMethodsVar,phpConstants,phpException,phpSuperglobals,phpMagicConstants,phpServerVars
syn cluster phpClInside contains=@phpClConst,phpComment,phpParent,phpParentError,phpInclude,phpHereDoc,phpNowDoc
syn cluster phpClFunction contains=@phpClInside,phpDefine,phpParentError,phpStorageClass,phpSpecial
syn cluster phpClTop contains=@phpClFunction,phpFoldFunction,phpFoldClass,phpFoldInterface,phpFoldTry,phpFoldCatch

" Php Region
if exists("php_parent_error_open")
  syn region phpRegion matchgroup=Delimiter start="<?\(php\)\=" end="?>" contains=@phpClTop
else
  syn region phpRegion matchgroup=Delimiter start="<?\(php\)\=" end="?>" contains=@phpClTop keepend
endif

Gives the same syntax on loading as when I'm done saving (very gray).

Same goes for removing the whole ~/.vim/bundle/ftplugin/php.vim. This way it's lacking colors, but not complete grayness on save.

Hope this might ring a bell!

Cheers, Maurice

mauserrifle avatar Sep 22 '12 13:09 mauserrifle

Same thing under OSX, vim version 7.3.672 compiled using homebrew formula and latest PIV from Vundle.

For now i just removed PIV, will try to fix it this weekend.

gonzaloserrano avatar Oct 31 '12 11:10 gonzaloserrano

Glad I'm not the only one. I haven't looked into it anymore because I gave up on Vim as my primary IDE due to no intellisense autocompletion like i'm used to from Eclipse.

I hope you get the problem fixed. If I need to test things, i'll be happy to!

mauserrifle avatar Oct 31 '12 16:10 mauserrifle

Hi,

I think I have kind of the same problem. Not while I'm saving though, but when I'm navigating in any php file : everything becomes gray, and only things like '>' are marked in red... I have to scroll up for a while,n then stop to re-enable the correct syntax highlight.

Taluu avatar Feb 27 '13 11:02 Taluu

Ye it happens on different moments. For me it was mainly saving. Haven't touched vim anymore :( I was 'trying' vim when I found out. Surprised the bug is still there. Hope someone finds it. I have no idea where to search (except my finding above this post)

mauserrifle avatar Feb 27 '13 12:02 mauserrifle

I'm having the same issue. With editing PHP files. Only :syn on helps

karolsojko avatar May 08 '13 11:05 karolsojko

For those of you still having issues, you can try using something lighter than PIV. I personally switched to this one myself: https://github.com/StanAngeloff/php.vim

For those looking for a really lightweight alternative, see: https://github.com/mageekguy/php.vim

Of course, neither of these options support as much as PIV, but that's part of the reason why they're faster.

jaywilliams avatar May 08 '13 17:05 jaywilliams

Bump! Also meet same issues here.

Environment:
* Ubuntu 10.10,  
* Vim 7.4 (2013 Aug 10, compiled Oct 17 2013 16:16:48) 

Reproduce:
* Do curl http://j.mp/spf13-vim3 -L -o - | sh
* Wait until spf13 successfuly installed.
* Ctrl + P, Open a  pure php class with more than 100 lines 
* Every function within class are folded by default. 
(Color themes shown correctly). 
* Navigate up and down, then editor goes in gray mode.

brain90 avatar Mar 19 '14 07:03 brain90

remove

58 call s:InitVariable("g:load_doxygen_syntax", 1) 59 call s:InitVariable("g:syntax_extra_php", 'doxygen') 60 call s:InitVariable("g:syntax_extra_inc", 'doxygen')

in ~/.spf13-vim-3/.vim/bundle/PIV/ftplugin/php.vim

lian4187 avatar Mar 29 '15 03:03 lian4187