Hi Gary,

On Wed, Mar 7, 2012 at 20:38, Gary Johnson <[email protected]> wrote:
> On 2012-03-07, Guido Van Hoecke wrote:
>> Hi,
>>
>> I have this simple GuivhoFoldText function:
>>
>>     function! GuivhoFoldText() " show text b4 marker and count
>>         return getline(v:foldstart) . ' ⋯' . (v:foldend - v:foldstart
>> + 1) . '⋯ '
>>     endfunction
>>
>> As apparent from the code, I want the complete text before the marker to
>> be shown, followed by the number of folded lines.
>>
>> The important issue is that the displayed text should keep the original
>> indentation whitespace so that its folded text would start on the column
>> where it starts in the unfolded state.
>>
>> This works well if the file formatting matches the current smarttab,
>> smartindent, softtabstop etc settings.
>>
>> For a file that has leading tabs although it is supposed not to use tabs
>> but spaces, this foldtext expression fails. It returns one single space
>> for each leading tab, rather than either the leading whitespace
>> verbatim or the leading text where the leading tabs are replaced by
>>  &softtabstop spaces (4 in casu).
>>
>> As soon as I issue ':retab' the foldtext expression works as desired.
>> But I do not own this file, so it would be unpolite to the owner to
>> return his/her file with whitespace changes all over...
>>
>> Anybody has any suggestion how my foldtext function can be ameliorated
>> so that it also works without performing a :retab?
>
> You can replace "getline(v:foldstart)" with this:
>
>    repeat(' ', indent(v:foldstart)) . matchstr(getline(v:foldstart), '\S')
>
> That will replace the leading whitespace of the current line with
> enough spaces to achieve the same indentation.
>
> That is untested, but is derived from my own foldtext(), so if it is
> not exactly correct, it shouldn't be off by much.

Thanks for the suggestion; after some further fiddling I came up with

    repeat(' ', indent(v:foldstart))
          \ . strpart(getline(v:foldstart), match(getline(v:foldstart), '\S'))
          \ . ' ⋯'
          \ . (v:foldend - v:foldstart + 1)
          \ . '⋯ '

and that seems to do the job.


Guido

--
If built in great numbers, motels will be used for nothing
but illegal purposes.
                -- J. Edgar Hoover

http://vanhoecke.org ... and go2 places!

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