On Thu, Aug 04, 2022 at 08:17:39PM +0200, Dennis Preiser wrote:
> I use vim and have the following vim9script function in my vimrc:
>
> | #---------------------------------------------------------------------------
> | # fix mail quotes for mutt, e.g. '> >foo' -> '>> foo'
> | # muttrc: set editor='vim -c ":call FixMailQuotes()"'
> | # cursor placement only useful if edit_headers is set in mutt
> | #---------------------------------------------------------------------------
> | 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 better, but gets along without perl (of course only if you use
> vim). Quotes are merged and it is ensured that there is a space after
> the last quote character.
>
> '> >> >foo' becomes '>>>> foo')

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:

  /^$/+

reducing your function to:

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

Just in case you find it useful.

-tkc




Reply via email to