Summary: | accommodate overlapping syntax regions (especially for php) | ||
---|---|---|---|
Product: | [Applications] kate | Reporter: | William Kilian <will> |
Component: | syntax | Assignee: | KWrite Developers <kwrite-bugs-null> |
Status: | RESOLVED FIXED | ||
Severity: | wishlist | CC: | borge, james, kde, martin.ereth |
Priority: | NOR | ||
Version: | 2.3.2 | ||
Target Milestone: | --- | ||
Platform: | unspecified | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Attachments: |
example from initial report
"Better" php.xml Full version of modified php.xml (for people who just want to grab and use it). Updated php folding for alternate block syntax. |
Description
William Kilian
2005-04-05 02:20:08 UTC
Created attachment 10517 [details]
example from initial report
*** Bug 143022 has been marked as a duplicate of this bug. *** Note: Folding no longer collapses until the end of the file since SVN rev. 744206, but now stops at the "?>". This makes the problem less severe, but we'd still really need overlapping regions to solve it correctly. Thinking about it, actually, we don't really need overlapping regions, we just need deeper nesting, and a good way to define it in the highlighting definition. Then your example would be mapped as: 1. Start in "HTML" region 2. On "<?" enter "PHP" region 3. On "{" enter "Brace" region 4. On "?>" enter "Embedded HTML" region 5. On "<?" leave "Embedded HTML" region 6. On "}" leave "Brace" region 7. On "?>" leave "PHP" region The "Brace" region is basically just a region that includes the general PHP rules, but #pops on encountering "}" and dispatches to "Embedded HTML" when encountering "?>". This last bit is the difficult one in the current setup, as from within php.xml we have no way of knowing which context would need to be included as "Embedded HTML". That's why right now we have no choice but to pop back to initial context, instead of starting a new level of nesting as would be required to get folding to work correctly. I took a cursory glance at the php.xml. It looks to me your idea would work if there were two different phpsource contexts. Make the brace enter the second context instead of just a new region, then that second phpsource context could treat the "?>" as entering "Embedded HTML". The only thing that would mess that up would be a file with unmatched open braces. I don't remember if it's possible to legally do that in php -- it might be if the matching close brace is in an include()'d file -- I haven't done anything in php in awhile and can't remember what php would do in that case. *** Bug 126673 has been marked as a duplicate of this bug. *** *** Bug 125604 has been marked as a duplicate of this bug. *** I can confirm that this is still a problem with Kate 2.5.8 on KDE 3.5.8. Code folding in php does not work in this manner and for that matter, brace syntax highlighting across these blocks are now broken. It didn't used to be broken in previous versions. Created attachment 35428 [details]
"Better" php.xml
The attached patch against php.xml (version 1.36), in my opinion, simply works far better and completely avoids this bug.
Quite simply, it forgets about folding on the <?php and ?> all togethor, and this prevents the entire problem with under-zealous or over-zealous folding which this bug (and #143022) is in regard to.
With this patch, one can correctly fold on php braces and any embedded html inside is folded away, you can also correctly fold on (foldable) html elements like <table> and any php inside is folded away.
It is my opinion that going to lengths, as have been in the past evidenced here, to preserve the ability to fold <?php and ?>, gives a very small reward and due the problems reported in this bug it produces a very big downsides in terms of much reduced folding usability for PHP+HTML - which is, after all, the typical way people write PHP "in the real world".
Simply avoiding the situation, as my patch does, I believe brings a large benefit for, in my opinion, insignificant loss.
I'll attach a full version of the file in a second.
Created attachment 35429 [details]
Full version of modified php.xml (for people who just want to grab and use it).
Yes! Thank you very much, I appreciate your work on this issue. Your new file is already superior to the old one, so if you have commit rights, please go ahead and push it into KDE SVN. Else I'll commit it for you. There is at least one thing I spotted which you might try to work on. As far as I know that is unrelated to your changes and did not work before either: <div> <?php if ( something ): ?> fuubar <?php endif; ?> </div> With your patch I can fold the div (great feature!), but I cannot fold the conditional, because it doesn't use curly braces to mark the context. Yes Milian, please do commit it if you think it's ok. I'll take a look at that other syntax, don't use it myself but I think it should be possible. Commited, thanks James! Created attachment 35551 [details]
Updated php folding for alternate block syntax.
The attached file provides folding for the PHP alternate block syntax.
The case and default statements ( case 'foo':, default: ) are not treated as blocks as we can't reliably say when they end (could be break, return, closing brace, the next case etc, who knows), so case and default simply don't fold (unless you make it explicit with braces of curse).
Committed, thanks James! |