Preben Randhol wrote:
Hi

I'm trying to make a function that wraps some text around a block like
this:


        bla bla bla bla
        bla bla bla bla
        bla bla bla bla
        bla bla bla bla
        bla bla bla bla

So it becomes:

        header text
                bla bla bla bla
                bla bla bla bla
                bla bla bla bla
                bla bla bla bla
                bla bla bla bla
        footer text

Since the header and footer can change, my idea was to mark the block visually 
so I can get the text and then call the Wrap_Block function (given at the end 
of the mail) with the propper wrap_text function (example given below) like 
this:

Here I just use the <F5> key for clarity.

        vmap <F5> "ax:call Wrap_Block(wrap_text1)<CR>

The problem is that the pasting doesn't get right. I need the whole block indented, 
but either it keeps it original indentation or if I pass the text to the function by 
using <c-r>=@@, the text gets inserted like this:

                        bla bla bla bla
                                bla bla bla bla
                                        bla bla bla bla
                                                bla bla bla bla
                                                        bla bla bla bla

So my question is should I rather make a function that first indent the whole 
block and then move to the top of the block inserting the header above it and 
then to the bottom and inserting the footer, or is there a way to make my 
original idea work?

Thanks in advance!

Preben

        function! Wrap_Block(function_name)
                " Calls the given function and wrap the text

                let l:pos = getpos('.')
let Func = function(a:function_name) execute "normal! a". Func()

                if search("<-->", 'Wc')  " search for the marker to insert text
                        execute "normal! df>"
                        execute "normal! \"ap"
                endif

                call setpos('.', l:pos)

        endfunction

        function! wrap_text1()
                return "header text\<CR>\<TAB><-->\<CR>footer text\<CR>"
        endfunction




Have you tried ":set paste"? Or rather, since it's inside a function,

        let save_paste = &paste
        set paste
        "
        " do your stuff
        "
        if ! save_paste
                set nopaste
        endif


Best regards,
Tony.

Reply via email to