On Fri, Aug 05, 2022 at 08:04:17PM +0000, Tim Chase wrote:
> On Thu, Aug 04, 2022 at 08:17:39PM +0200, Dennis Preiser wrote:
>> | def g:FixMailQuotes()
>> |    # find first body line after headers
>> |    var first_body_line = search('^$') + 1
>> |    # compress quote marks
>> |    while search('^>[> ]* >', 'w') > 0
>> |            silent! s/> >/>>/e
>> |    endwhile
>> |    # add space after last '>' if none is present
>> |    silent! :%s/^[>]*\zs>\ze[^> ]/> /e
>> |    # place cursor at first line of body
>> |    cursor(first_body_line, 1)
>> | enddef

> Not sure if you want it, but this reduces a bunch of that code
> to a one-liner
> 
> %s/^\(> *\)\+/\=substitute(submatch(0), ' ', '', 'g').' '
> 
> finding any quoted indentation, removing all the spaces from it,
> and tacking on one space at the end.
> 
> Additionally, I think that your first_body_line pair of lines can
> be reduced to just a raw search:
> 
> /^$/+

The idea here was that the following while loop, at least in the first
pass, starts searching after the headers and you don't have to search
for the end of the headers again after the loop. For a one-liner, i.e.
without a loop, this is of course no longer useful.

> reducing your function to:
> 
> def g:FixMailQuotes()
> %s/^\(> *\)\+/\=substitute(submatch(0), ' ', '', 'g').' '
> /^$/+
> enddef

For vim9script this has to be adapted slightly. A colon is needed before
a range and string concatenation now works with two dots instead of one.
Also, white space is required before and after the two dots.

Eventually, I now use this function:

def g:FixMailQuotes()
        :%s/^\(> *\)\+/\=substitute(submatch(0), ' ', '', 'g') .. ' '
        silent! :/^$/+
enddef

> Just in case you find it useful.

Yes indeed, thanks for sharing!

Dennis

Reply via email to