* On 31 Jan 2017, Andreas Doll wrote: 
> 
> I write emails using vim, which provides the handy function gggqG. This
> function reformats text such that it doesn't exceed (say) 72 characters. The
> function is superior to e.g.
> 
>     $ fold -s -w 72 inputFile

par is superior to all other text reformatters.
set display_filter="env PARINIT='rT4bgq B=.,?!_A_a Q=_s>|+' par"

But to your question:

> Recently I've learned about the display_filter option, and now I want to use
> this vim function to also reformat emails I read, not just those I send. Ex is
> (roughly) a way to perform vim actions and commands without starting a vim
> instance. So I thought I create a file commands.vim containing
> 
>     :normal gggqG
>     :%print
>     :%quit!
> 
> and use in my muttrc
> 
>     set display_filter='cat commands.vim | ex'

The display filter is a filter in a strict sense: the message is send on
its stdin, and its stdout goes back to mutt.  So what you get is
analogous to the following:

    cat emailmessage.txt | cat commands.vim | ex

The first cat is a no-op since the second cat doesn't read its stdin in
this case.  You can combine a file with stdin with, e.g.

    cat commands.vim -

But that isn't what you want.  You need to compose it so that ex gets
your message and the stdin:

    #!/bin/sh
    tmp=${TMPDIR-/tmp}/tmp.$$
    touch $tmp
    trap "rm $tmp" 0 1 2 3 15
    cat >$tmp
    cat commands.vim | ex $tmp

Then set display_filter to run that script.

This is all approximate - untested. Some tweaks might be necessary.

-- 
David Champion • d...@bikeshed.us

Attachment: signature.asc
Description: PGP signature

Reply via email to