print folds

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

print folds

Samuel Wright
HI All

Is it possible to print with folds collapsed? Whenever I print they all expand.

Thanks
Sam
Reply | Threaded
Open this post in threaded view
|

Re: print folds

Stefan Karlsson-3
As a workaround you could use ":TOhtml" and then print the generated
HTML page.

-- Stefan


Samuel Wright wrote:

>HI All
>
>Is it possible to print with folds collapsed? Whenever I print they all expand.
>
>Thanks
>Sam
>
>  
>
Reply | Threaded
Open this post in threaded view
|

Re: print folds

Hari Krishna Dara
In reply to this post by Samuel Wright

On Thu, 25 Aug 2005 at 7:24pm, Stefan Karlsson wrote:

> As a workaround you could use ":TOhtml" and then print the generated
> HTML page.
>
> -- Stefan
>
>
> Samuel Wright wrote:
>
> >HI All
> >
> >Is it possible to print with folds collapsed? Whenever I print they all
expand.
> >
> >Thanks
> >Sam

I don't think :TOhtml preserves the folds as well, I just tried as of
6.3.86. Are you sure it works the way OP wants it for you? Which version
of vim are you using?

An alternative is to temporary change the buffer to replace the lines in
the fold with a "real" line representing the fold. The below function
(tested on a sample buffer) will do the trick. You will call this
function, print the buffer (or convert to HTML) and undo. You may have
to recreate your fold (or reload the buffer if using one of the fold
methods other than "manual") to get the original folds back.

function! CreatePrintableFolds()
  let dashBank =
'-------------------------------------------------------------------------------'
  let spaceBank = '      '
  exec 1
  while 1
    let foldst = foldclosed('.')
    if foldst != -1
      " We are already inside a fold.
      let folden = foldclosedend('.')
      let lineCnt = (folden-foldst+1).''
      let foldtext = '+--'.strpart(spaceBank, 0, 3-strlen(lineCnt)).lineCnt.'
lines: '.getline(foldst)
      let foldtext = foldtext.strpart(dashBank, 0, 80-strlen(foldtext))
      silent! exec foldst.','.folden.'d'
      silent! exec foldst.'put! =foldtext'
    endif
    let curline = line('.')
    silent! normal zj
    if line('.') == curline
      " No more folds.
      break
    endif
  endwhile
endfunction

--
HTH,
Hari


               
__________________________________
Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html 

Reply | Threaded
Open this post in threaded view
|

Re: print folds

Stefan Karlsson-3
Sorry, I was using Vim 7 (compiled by A. Mechelynck 20 August 20) and
there it works. When trying it om Vim 6.3.85 it didn't work.


-- Stefan

Hari Krishna Dara wrote:

>On Thu, 25 Aug 2005 at 7:24pm, Stefan Karlsson wrote:
>
>  
>
>>As a workaround you could use ":TOhtml" and then print the generated
>>HTML page.
>>
>>-- Stefan
>>
>>
>>Samuel Wright wrote:
>>
>>    
>>
>>>HI All
>>>
>>>Is it possible to print with folds collapsed? Whenever I print they all
>>>      
>>>
>expand.
>  
>
>>>Thanks
>>>Sam
>>>      
>>>
>
>I don't think :TOhtml preserves the folds as well, I just tried as of
>6.3.86. Are you sure it works the way OP wants it for you? Which version
>of vim are you using?
>
>An alternative is to temporary change the buffer to replace the lines in
>the fold with a "real" line representing the fold. The below function
>(tested on a sample buffer) will do the trick. You will call this
>function, print the buffer (or convert to HTML) and undo. You may have
>to recreate your fold (or reload the buffer if using one of the fold
>methods other than "manual") to get the original folds back.
>
>function! CreatePrintableFolds()
>  let dashBank =
>'-------------------------------------------------------------------------------'
>  let spaceBank = '      '
>  exec 1
>  while 1
>    let foldst = foldclosed('.')
>    if foldst != -1
>      " We are already inside a fold.
>      let folden = foldclosedend('.')
>      let lineCnt = (folden-foldst+1).''
>      let foldtext = '+--'.strpart(spaceBank, 0, 3-strlen(lineCnt)).lineCnt.'
>lines: '.getline(foldst)
>      let foldtext = foldtext.strpart(dashBank, 0, 80-strlen(foldtext))
>      silent! exec foldst.','.folden.'d'
>      silent! exec foldst.'put! =foldtext'
>    endif
>    let curline = line('.')
>    silent! normal zj
>    if line('.') == curline
>      " No more folds.
>      break
>    endif
>  endwhile
>endfunction
>
>  
>
Reply | Threaded
Open this post in threaded view
|

Re: print folds

Stefan Karlsson-3
compiled by A. Mechelynck 20 August *2005*

Who knows, perhaps Vim 7 can send collapsed folds directly to the
printer as well ... I don't have any printer here so I can't test it.

Stefan Karlsson wrote:

> Sorry, I was using Vim 7 (compiled by A. Mechelynck 20 August 20) and
> there it works. When trying it om Vim 6.3.85 it didn't work.
>
>
> -- Stefan
>
> Hari Krishna Dara wrote:
>
>> On Thu, 25 Aug 2005 at 7:24pm, Stefan Karlsson wrote:
>>
>>  
>>
>>> As a workaround you could use ":TOhtml" and then print the generated
>>> HTML page.
>>>
>>> -- Stefan
>>>
>>>
>>> Samuel Wright wrote:
>>>
>>>  
>>>
>>>> HI All
>>>>
>>>> Is it possible to print with folds collapsed? Whenever I print they
>>>> all
>>>>    
>>>
>> expand.
>>  
>>
>>>> Thanks
>>>> Sam
>>>>    
>>>
>>
>> I don't think :TOhtml preserves the folds as well, I just tried as of
>> 6.3.86. Are you sure it works the way OP wants it for you? Which version
>> of vim are you using?
>>
>> An alternative is to temporary change the buffer to replace the lines in
>> the fold with a "real" line representing the fold. The below function
>> (tested on a sample buffer) will do the trick. You will call this
>> function, print the buffer (or convert to HTML) and undo. You may have
>> to recreate your fold (or reload the buffer if using one of the fold
>> methods other than "manual") to get the original folds back.
>>
>> function! CreatePrintableFolds()
>>  let dashBank =
>> '-------------------------------------------------------------------------------'
>>
>>  let spaceBank = '      '
>>  exec 1
>>  while 1
>>    let foldst = foldclosed('.')
>>    if foldst != -1
>>      " We are already inside a fold.
>>      let folden = foldclosedend('.')
>>      let lineCnt = (folden-foldst+1).''
>>      let foldtext = '+--'.strpart(spaceBank, 0,
>> 3-strlen(lineCnt)).lineCnt.'
>> lines: '.getline(foldst)
>>      let foldtext = foldtext.strpart(dashBank, 0, 80-strlen(foldtext))
>>      silent! exec foldst.','.folden.'d'
>>      silent! exec foldst.'put! =foldtext'
>>    endif
>>    let curline = line('.')
>>    silent! normal zj
>>    if line('.') == curline
>>      " No more folds.
>>      break
>>    endif
>>  endwhile
>> endfunction
>>
>>  
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: print folds

Hari Krishna Dara
In reply to this post by Samuel Wright

On Thu, 25 Aug 2005 at 8:42pm, Stefan Karlsson wrote:

> Sorry, I was using Vim 7 (compiled by A. Mechelynck 20 August 20) and
> there it works. When trying it om Vim 6.3.85 it didn't work.
>
>
> -- Stefan

That is ok, I expected that (and nice to know that Vim7 has this
enhancement that I waited for).

--
Thanks,
Hari

>
> Hari Krishna Dara wrote:
>
> >On Thu, 25 Aug 2005 at 7:24pm, Stefan Karlsson wrote:
> >
> >
> >
> >>As a workaround you could use ":TOhtml" and then print the generated
> >>HTML page.
> >>
> >>-- Stefan
> >>
> >>
> >>Samuel Wright wrote:
> >>
> >>
> >>
> >>>HI All
> >>>
> >>>Is it possible to print with folds collapsed? Whenever I print they all
> >>>
> >>>
> >expand.
> >
> >
> >>>Thanks
> >>>Sam
> >>>
> >>>
> >
> >I don't think :TOhtml preserves the folds as well, I just tried as of
> >6.3.86. Are you sure it works the way OP wants it for you? Which version
> >of vim are you using?
> >
> >An alternative is to temporary change the buffer to replace the lines in
> >the fold with a "real" line representing the fold. The below function
> >(tested on a sample buffer) will do the trick. You will call this
> >function, print the buffer (or convert to HTML) and undo. You may have
> >to recreate your fold (or reload the buffer if using one of the fold
> >methods other than "manual") to get the original folds back.
> >
> >function! CreatePrintableFolds()
> >  let dashBank =
>
>'-------------------------------------------------------------------------------'
> >  let spaceBank = '      '
> >  exec 1
> >  while 1
> >    let foldst = foldclosed('.')
> >    if foldst != -1
> >      " We are already inside a fold.
> >      let folden = foldclosedend('.')
> >      let lineCnt = (folden-foldst+1).''
> >      let foldtext = '+--'.strpart(spaceBank, 0,
3-strlen(lineCnt)).lineCnt.'

> >lines: '.getline(foldst)
> >      let foldtext = foldtext.strpart(dashBank, 0, 80-strlen(foldtext))
> >      silent! exec foldst.','.folden.'d'
> >      silent! exec foldst.'put! =foldtext'
> >    endif
> >    let curline = line('.')
> >    silent! normal zj
> >    if line('.') == curline
> >      " No more folds.
> >      break
> >    endif
> >  endwhile
> >endfunction
> >
> >
> >
>
>


               
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs