Charles Campbell (2008-12-01 15:43 -0500) wrote:
> anhnmncb wrote:
>> On 2008-11-30, anhnmncb wrote:
>>
>>> As title, I want to make a function for foldtext like this:
>>>
>>> function MY_TeX_BiBFoldText()
>>> let line = getline(v:foldstart, v:foldend)
>>> let matchlinea = match(line, '^\s*author.*{.*}.*') + 1
>>> let matchlinet = match(line, '^\s*title.*{.*}.*') + 1
>>> let matcha = substitute(getline(matchlinea), '^.*{\(.*\)}*.*$', '\1', 'g')
>>> let matcht = substitute(getline(matchlinet), '^.*{\(.*\)}*.*$', '\1', 'g')
>>> let matched = "title: " . matcht . " author: " . matcha
>>> return v:folddashes . matched
>>> endfunction
>>>
>>> So the folding will show the string "matched", but I find that v:foldstart
>>> and
>>> v:foldend have the same value in foldings, so all my foldings show the same
>>> string, why?
>>>
>>>
>> Isn't my description clear? If so, let me know please.
>>
>>
> Hello!
>
> I've not messed with the foldtext option before; I suspect its one of
> the less common things people do, so your target audience is small.
> Also, I've moved recently to a new email delivery mechanism (even though
> my email address itself hasn't changed), and its flagging your email as
> spam:
>
>
> Content analysis details: (5.9 points, 3.5 required)
>
> pts rule name description
> ---- ---------------------- --------------------------------------------------
> 0.1 RDNS_NONE Delivered to trusted network by a host with no
> rDNS
> 3.2 FROM_LOCAL_NOVOWEL From: localpart has series of non-vowel letters
> 2.6 RCVD_NUMERIC_HELO Received: contains an IP address used for HELO
>
> The biggest item on the above list is your false "name". Rather discourages
> one from looking at your email, you know.
>
> Now, on to your problem -- I instrumented your function with Decho.vim calls
> (Dfunc, Decho, Dret). Since the foldtext option says its a no-no to change
> windows, I used DechoMsgOn which sends Decho output via echomsg.
>
> You can get the Decho plugin from:
>
> http://vim.sourceforge.net/scripts/script.php?script_id=120
> -or-
> http://mysite.verizon.net/astronaut/vim/index.html#DECHO
> (this latter one is always the most up-to-date)
>
> Here's the modified function/script:
>
> DechoMsgOn
> function! MY_TeX_BiBFoldText()
> call Dfunc("My_TeX_BiBFoldText() v:fold[".v:foldstart.",".v:foldend."]")
> let line = getline(v:foldstart, v:foldend)
> let matchlinea = match(line, '^\s*author.*{.*}.*') + 1
> let matchlinet = match(line, '^\s*title.*{.*}.*') + 1
> call Decho("matchlinea=".matchlinea." matchlinet=".matchlinet)
> let matcha = substitute(getline(matchlinea), '^.*{\(.*\)}*.*$', '\1',
> 'g')
> let matcht = substitute(getline(matchlinet), '^.*{\(.*\)}*.*$', '\1',
> 'g')
> let matched = "title: " . matcht . " author: " . matcha
> call Dret("My_TeX_BiBFoldText ".v:folddashes . matched)
> return v:folddashes . matched
> endfunction
> set foldtext=MY_TeX_BiBFoldText()
>
> With it, you'll see that v:foldstart and v:foldend do differ when
> MY_TeX_BiBFoldText() is called for each fold. An example of one of the calls
> (gotten by typing :mess):
>
> My_TeX_BiBFoldText() v:fold[30,35] {
> |matchlinea=0 matchlinet=0
> |return My_TeX_BiBFoldText -title: author: }
>
> The problem here is that your two match() calls which look for author and
> title don't match. None of my bib entries that I used for this test have {}s
> for author=... or title=... , so that's the proximate cause for me. You'd
> need to share some of your bib files for a better test, or better: get
> Decho.vim and try debugging this one yourself.
I use following lines for bib filetype:
set fdm=syntax
set foldtext=MY_TeX_BiBFoldText()
syntax region bibentry start=/[EMAIL PROTECTED]/ end=/^\s\?}.*\n\s*$/
contained contains=ALL fold
and the bib example is following:
@ARTICLE{foo1,
author = {author1},
title = {This is a long
title.),
journal = {journal1},
year = 1980,
volume = 18,
pages = {55--67},
TypeofLit = {J}
}
@ARTICLE{foo2,
author = {author2 and author 3},
title = {title 2},
journal = {Throbosis Res},
year = 1982,
volume = 13,
pages = {58--67},
TypeofLit = {J}
}
>
> Regards,
> Chip Campbell
>
>
>
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---