On Mon, Jan 16, 2012 at 09:24, Guido Van Hoecke <gui...@gmail.com> wrote:
> On Sun, Jan 15, 2012 at 20:11, Gary Johnson <garyj...@spocom.com> wrote:
>> On 2012-01-15, AK wrote:
>>> On 01/15/2012 01:56 PM, Gary Johnson wrote:
>>> >On 2012-01-15, AK wrote:
>>> >
>>> >>It does work for me but I'm dealing with lines that have
>>> >>leading spaces and I add leading spaces, here is a relevant
>>> >>snip:
>>> >>
>>> >>     let l = getline(v:foldstart)
>>> >>     let line = substitute(l, '^[ ]*', '', '')
>>> >>     let prefix = repeat(' ', (strlen(l) - strlen(line)))
>>> >>     let c = ''
>>> >>     if l =~ '^\s*class\s' | let c = '(c)--' | endif
>>> >>     let line = prefix . '+--' . c . '  ' . line
>>> >
>>> >You can also use the indent() function to get the indentation of the
>>> >line directly instead of calculating string lengths, e.g.,
>>> >
>>> >     let n = v:foldend - v:foldstart + 1
>>> >     let i = indent(v:foldstart)
>>> >     return repeat(' ', i) . "+-" . v:folddashes . " " . n . " lines "
>>
>>> Thanks! I know that now, but I wrote this function a
>>> long time ago..  -ak
>>
>> You're welcome.  I should thank you, too.  I also wrote my function
>> a long time ago and until now used a while loop instead of repeat()
>> to create the indent prefix.
>>
>
> Inspired by all received answers, I finally came up with a foldtext
> function that positions the fold text exactly right, namely
> indent(v:foldstart) - foldlevel(v:foldstart) spaces:
>
> function! VhoFoldText() " show the text before the fold marker {{{2
>    let n = v:foldend - v:foldstart + 1
>    let l = getline(v:foldstart)
>    let i = indent(l)
>    let j = foldlevel(l)
>    let t = substitute(l, '\*\|\*/\|{\+\d\=', '('.n.' lines)', 'g')
>    return repeat(' ', i-j) . t
> endfunction

oops, this should be:
function! VhoFoldText() " show the text before the fold marker {{{2
    let n = v:foldend - v:foldstart + 1
    let i = indent(v:foldstart)
    let j = foldlevel(v:foldstart)
    let l = getline(v:foldstart)
    let t = substitute(l, '\*\|\*/\|{\+\d\=', '('.n.' lines)', 'g')
    return repeat(' ', i-j) . t
endfunction

Sorry for the erroneous version,

Kind regards,


Guido

--
Law of the Yukon:
        Only the lead dog gets a change of scenery.

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

Reply via email to