Monday, August 1, 2011

A mile of dashes added to foldtext

After collecting several dozen informative posts on the topic, I'm
trying out folding on a 20k+ line file, starting out with a single level
of folds, using just this in .vimrc:

" Folding:
set foldmethod=marker
set foldtext=substitute(getline(v:foldstart),'/\\*\\\|\\*/\\\|{{{\\d\\=','','g')
hi! link Folded None

and text with folds such as:

GCC:----------------------- G++ ---------------------------COMPILER: {{{

Pages of gcc stuff here.

}}}

Everything works like a bought one, straight OOTB ... except that closed
folds have a spurious second long string of dashes appearing to the
right of my headings, running out to nearly twice the 80 character page
width. (I can't see where the foldtext assignment is adding them.)

It looks like the following two lines joined:

GCC:----------------------- G++ ---------------------------COMPILER:
----------------------------------------------------------

I don't know if there's anything to the right of that.

Replacing the foldtext assignment with:

set foldtext=MyFoldText()
function MyFoldText()
let line = getline(v:foldstart)
let sub = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
return sub
endfunction

also appends the spurious extra dashes. Changing my heading fill to a
line of '=' (or even spaces) does not affect the egregious dashes.

It has also become clear that I'll have to constrain the folding with
some "au BufNewFile,BufRead", because .vimrc is only partly displayed,
apparently due to the foldtext regex being interpreted as the start of a
fold. The lack of closure of the (not real) fold leaves the rest of
.vimrc replaced by '~', until the fold is (implicitly) opened.
Fortunately that's easily rectified.

But how to remove the extra "--------- ... ------------------" hoo-haa?

Erik

--
It's so beautifully arranged on the plate ... you know someone's fingers
have been all over it.
- Julia Child on nouvelle cuisine.

--
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: