> On Sun, Nov 28, 2010 at 11:38 PM, Benjamin R. Haskell wrote:
>
>>
>>
>>> Question: Ultimatley I want code folding in html files (and
>>> preferebly later haml/erb) should using foldmethod=sytnax work for
>>> any file that it recognizes the syntax?
>>>
>>
>>
>> Not universally, no. In terms of handling things other than
>> highlighting, the syntax files vary a bit in quality. Similar to the
>> way Wikipedia articles vary in quality, the best syntax files are the
>> ones that either: 1) the most people care about, or 2) someone goes
>> out of their way to improve. Often the original author of the file
>> might just be unaware of folding, so it gets omitted.
>>
>> Since you mentioned it explicitly, the eruby filetype seems to lack
>> folding. I don't have any 'haml' files sitting around for testing
>> (had some old Ruby on Rails stuff for .rhtml files), but its syntax
>> file is by the same author, and also doesn't mention folding at all.
>>
>>
>>
>
> What about just regular ubiquitous html? I can't seem to get that to
> fold at all.
HTML doesn't support folding. You can usually see options for a given
filetype by doing:
:help ft-{filetype}-syntax
So:
:help ft-xml-syntax
(shows the g:xml_syntax_folding info)
:help ft-html-syntax
(doesn't mention folding)
If the documentation is out of date, or you want to be sure there aren't
hidden features, you can also check the source:
:exe "view ".globpath(&rtp,'syntax/html.vim')
> I also figured out that for some reason I needed to add this to my
> .vimrc file to get even xml folding to work correctly:
>
> let g:xml_syntax_folding=0
Huh? You should have to set the opposite:
let g:xml_syntax_folding = 1
Probably a broken check in xml.vim...
> Do I need to do something similar for html files? (on a whim tried -
> with no luck - let g:html_syntax_folding=0)
Part of the reason for varying levels of folding support between
languages is that there are two main ways to do syntax highlighting:
The first way is to just highlight a bunch of keywords/matches. This
way is "dumb" in the sense that you don't need to specify a lot of the
grammar of the language being highlighted. But, it's far easier to set
up. E.g., you can just say "if", "then", and "else" are keywords, vs
having to say "if" starts an "if-block" which ends with either an "else"
or a closing brace (or whatever).
But, in order to do syntax-based folding, the syntax needs to be set up
in the more-complicated, "region"-based way. The XML highlighting is a
great example of a well-written syntax that uses this method, IMO.
HTML mainly uses regions to provide the text formatting tricks that it
adds (underlined <a> text, bolded <b> text, etc.). My guess is that the
main reason it doesn't work the same way the XML syntax does is that
HTML, as an SGML application, doesn't require matched closing tags (so
writing a grammar for it in terms of syntax regions can be quite
complicated).
--
Best,
Ben
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
No comments:
Post a Comment