using tabs instead of spaces in folds

classic Classic list List threaded Threaded
4 messages Options
kae
Reply | Threaded
Open this post in threaded view
|

using tabs instead of spaces in folds

kae
Hi guys,
  sorry if this is an obvious question, but how can I get vim to use
tabs when drawing a fold, instead of spaces? An example of some folded
text I have:

        var n=catid?newText(data['name']):newText('main contents');
        el.appendChild(n);
 
if(catid){-----------------------------------------------------------------------------------------------------------------------------------
  if(data['subcats'].length>0 &&
data['subcats'][0][0]){---------------------------------------------------------------------------------------
        var el=newEl('div','shoppingcart_items_'+cartid+'_'+catid);
        contents.appendChild(el);
 
Note that the "if" blocks start with two spaces, where it would be more
in line with my own coding style if they used two tabs instead.

Kae

kae
Reply | Threaded
Open this post in threaded view
|

Re: using tabs instead of spaces in folds

kae
Kae Verens wrote:

> Hi guys,
>  sorry if this is an obvious question, but how can I get vim to use
> tabs when drawing a fold, instead of spaces? An example of some folded
> text I have:
>
>        var n=catid?newText(data['name']):newText('main contents');
>        el.appendChild(n);
>  
> if(catid){-----------------------------------------------------------------------------------------------------------------------------------
>
>  if(data['subcats'].length>0 &&
> data['subcats'][0][0]){---------------------------------------------------------------------------------------
>
>        var el=newEl('div','shoppingcart_items_'+cartid+'_'+catid);
>        contents.appendChild(el);
>
> Note that the "if" blocks start with two spaces, where it would be
> more in line with my own coding style if they used two tabs instead.


sorry - I guess it was an RTFM case...

I've documented my solution here:
http://verens.com/archives/2005/07/12/neatly-indented-folds-in-vim/

the solution will be on a case-by-case basis, I guess.

Kae

Reply | Threaded
Open this post in threaded view
|

Re: using tabs instead of spaces in folds

Antony Scriven
In reply to this post by kae
On Jul 12, Kae Verens wrote:

 > Hi guys,
 >  sorry if this is an obvious question, but how can I get
 > vim to use tabs when drawing a fold, instead of spaces?
 > An example of some folded text I have:
 >
 >        var n=catid?newText(data['name']):newText('main contents');
 >        el.appendChild(n);
 >  
 > if(catid){----------------------------------------- [...]
 >  if(data['subcats'].length>0 &&
 > data['subcats'][0][0]){---------------------------- [...]
 >        var el=newEl('div','shoppingcart_items_'+cartid+'_'+catid);
 >        contents.appendChild(el);

Yikes! Those were long lines. Imagine the fun after it's
been quoted several times.

 > Note that the "if" blocks start with two spaces, where it
 > would be more in line with my own coding style if they
 > used two tabs instead.

It seems that tabs get converted to a single space for
displaying fold text. I don't know whether this is a bug of
if it is intentional.

I'd write my own function for use in 'foldtext'. Among other
things it might make use of the following function. I wonder
if there's a neater way to turn tabs to spaces?

   fun! Detab(str, ts)
           let spc = '         '
           while (strlen(spc) - 1 < a:ts)
                   let spc = spc . spc
           endwhile
           let str = substitute(a:str, '\([^\t]*\)\zs\t',
           \ '\=strpart(spc,1,a:ts-strlen(submatch(1))%a:ts)', 'g')

           return str
   endfun

Antony
Reply | Threaded
Open this post in threaded view
|

Re: using tabs instead of spaces in folds

Gary Johnson
On 2005-07-12, Antony Scriven <[hidden email]> wrote:

> On Jul 12, Kae Verens wrote:
>
>  > Hi guys,
>  >  sorry if this is an obvious question, but how can I get
>  > vim to use tabs when drawing a fold, instead of spaces?
>  > An example of some folded text I have:
>  >
>  >        var n=catid?newText(data['name']):newText('main contents');
>  >        el.appendChild(n);
>  >  
>  > if(catid){----------------------------------------- [...]
>  >  if(data['subcats'].length>0 &&
>  > data['subcats'][0][0]){---------------------------- [...]
>  >        var el=newEl('div','shoppingcart_items_'+cartid+'_'+catid);
>  >        contents.appendChild(el);
>
> Yikes! Those were long lines. Imagine the fun after it's
> been quoted several times.
>
>  > Note that the "if" blocks start with two spaces, where it
>  > would be more in line with my own coding style if they
>  > used two tabs instead.
>
> It seems that tabs get converted to a single space for
> displaying fold text. I don't know whether this is a bug of
> if it is intentional.
>
> I'd write my own function for use in 'foldtext'. Among other
> things it might make use of the following function. I wonder
> if there's a neater way to turn tabs to spaces?

That's what I did, too.  From my .vimrc:

    set foldtext=MyFoldText()

    function! MyFoldText()
        let n = v:foldend - v:foldstart + 1
        let i = indent(v:foldstart)
        let istr = ''
        while i > 0
            let istr = istr . ' '
            let i = i - 1
        endwhile
        return istr . "+-" . v:folddashes . " " . n . " lines "
    endfunction

Note that MyFoldText() changes other things about the way folds are
displayed to suit my taste and coding style.

HTH,
Gary

--
Gary Johnson                 | Agilent Technologies
[hidden email]     | Wireless Division
                             | Spokane, Washington, USA