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?
--
Regards,
anhnmncb
--
Regards,
anhnmncb
Isn't it clear that I don't know how to help (and that Bram, Dr.Chip,
Bill, John and the rest are probably either too busy or equally nonplussed)?
In case you didn't know, if you don't get a reply on this list, it
usually means that none of those who got your mail (and already got to
the point of opening it) knew a satisfatory answer. Lost mail may happen
too but it's rare, and with some mail providers including @gmail.com
it's even possible to get back the mail that "an over-diligent secretary
sent to the wastebasket" (and I don't mean a human secretary).
Best regards,
Tony.
--
One nice thing about egotists: they don't talk about other people.
--
Regards,
anhnmncb
I'm using POP on my @gmail.com account (to which I have set the vim
lists to send every message) and from time to time I use the webmail
interface to handle spam (recover false positives, report false
negatives, and then clear the trash and spam folders until next time).
Now and then there is a false positive at gmail but at least (thank ***)
there's no firewall or proxy between it and me to delete my mail without
my say-so.
Best regards,
Tony.
--
"I'd love to go out with you, but I've been scheduled for a karma
transplant."
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.
Regards,
Chip Campbell
Looks to me like your function is confused...
> function MY_TeX_BiBFoldText()
You get a List containing the text of all lines in the fold:
> let line = getline(v:foldstart, v:foldend)
Then you find the offsets in that list of the matching lines:
> let matchlinea = match(line, '^\s*author.*{.*}.*') + 1
> let matchlinet = match(line, '^\s*title.*{.*}.*') + 1
Then you use those offsets as line numbers, instead of offsets into a
list. Why are you using getline(match()+1) here, instead of
line[match()] ?
> let matcha = substitute(getline(matchlinea), '^.*{\(.*\)}*.*$', '\1', 'g')
> let matcht = substitute(getline(matchlinet), '^.*{\(.*\)}*.*$', '\1', 'g')
Seems to me that those lines should be:
let matchlinea = match(line, '^\s*author.*{.*}.*')
let matchlinet = match(line, '^\s*title.*{.*}.*')
let matcha = substitute(line[matchlinea], '^.*{\(.*\)}*.*$', '\1', 'g')
let matcht = substitute(line[matchlinet], '^.*{\(.*\)}*.*$', '\1', 'g')
> let matched = "title: " . matcht . " author: " . matcha
> return v:folddashes . matched
> endfunction
Try that, see if it helps.
~Matt
From my function and other stuff, you know I'm not a programmer, and not get
familiar with vimscript and regex, anyone can give me an improve version for
my syntax for bib? My version just can fold the bib entry like this:
@article{foo,
author = {author},
title = {title},
}
it doesn't support this one:
@article{foo,
author = {author},
title = {title},}
And my foldtext can support just one line of title, the splited long line will not
be regornized, so if title = {a long \n line title}, then the function just
returns "a long", not with the following line.
I know maybe there is already some plugins like latexsuit can do that, but I
don't get along well with them.
Any helpful info will be appreciated.
--
Regards,
anhnmncb