format-flowed correcting help

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

format-flowed correcting help

Kyle Wheeler
Hello,

I've been using vim for a while now with mutt. Lots of times I get mail
that is not in format-flowed format (with spaces at the end of each
line). This makes sending format-flowed messages more difficult, and can
lead to wrapping problems (the text *I* send is created with fo+=aw -
but I want the entire message to be properly f-f formatted). So I
figured with the power of vim I could reformat people's email and fix it
so I don't have to bother with adding spaces to the end of every line by
hand.

So, I wrote this function, not really knowing a whole lot about what I'm
doing. Does anyone have a better way of doing it? Perhaps a way that
won't mangle ascii-art or that will trigger the auto-format reflowing
more directly?

function! Fixflowed()
    " save position
    let l = line(".")
    let c = col(".")
    normal G$
    " add spaces to the end of every line
    while search('\([^]> :]\)\n\(>[> ]*[^> ]\)','w') > 0
        s/\([^]> :]\)\n\(>[> ]*[^> ]\)/\1 \r\2/g
        " THIS IS A TOTAL HACK TO TRIGGER THE AUTO-FORMAT
        normal gqk
        normal gqj
        normal k
    endwhile
    " now, fix the wockas spacing from the text
    while (search('^\([> ]*>\)\([^> ]\)','w') > 0
                s/^\([> ]*>\)\([^> ]\)/\1 \2/
        endwhile
    " now, compress the wockas
    while search('^\(>>*\) \(>>*\( [^>]\)*\)', 'w') > 0
                s/^\(>>*\) \(>>*\( [^>]\)*\)/\1\2/
        endwhile
    " restore the original location, such as it is
    execute l . " normal " . c . "|"
endfunction

Thanks,
~Kyle
--
Do not seek to follow in the footsteps of the men of old. Seek what they
sought.
-- Matsuo Basho

signature.asc (203 bytes) Download Attachment
Loading...