Re: How to copy with badly wrapped lines in pager
* On 2005.05.04, in <20050504092252.GA23932@pc1>,
* "Ton Boelens" <linux@xxxxxxxxxxxxx> wrote:
>
> Thanks for you reply. It works, but I get an error 'key not defined'
> with the second part of the macro:
>
> "{snip!}...<display-message><enter-command>unset display_filter<enter>"
I think this problem is the same as Toby mentioned. My mistake; there's
no display-message in pager mode. I meant index. :)
But you can modify the macro to work from pager, too, as Toby did.
> Also, the command par could be replaced by a sed command, or a
> VIM-macro that does 'gqap', sends the output to STDOUT and then exits?
Sed would be tricky, but possible -- but also not very good at the task.
Par uses intelligent algorithms to reflow text, but it would be difficult
to make sed do much more than rewrap lines at 72 columns or something.
If you're happy with that, then I suggest fmt instead -- it's standard
across all Unixes I've seen in the last 10 years or so. But par will get
you good results in perhaps more different cases.
You probably can do something with vim, but I don't know -- I don't use
it. I gather that a lot of par's features have been absorbed into vim's
gq stuff. I have a hunch that vim got it directly from par, at least in
spirit, because "gq" is the essential part of $PARINIT that does most of
the work. I suspect par has more features, but that vim has all of the
most common/useful ones.
* On 2005.05.04, in <20050504094055.GA15509@xxxxxxxxxxxxx>,
* "Toby" <tobia.conforto@xxxxxxxx> wrote:
>
> Problem #1: <display-message> doesn't exist in the pager.
> (I'm using Mutt from Debian testing, apparently 1.5.6+20040907i CVS)
Right, thanks. It was a typo in my muttrc, in fact -- I had entered the
macro interactively and not quit mutt in a few weeks. :) I use this in
index mode:
macro index \Cr "<enter-command>set
display_filter=\"display-filter\"<enter><display-message><enter-command>unset
display_filter<enter>" "Reflow formatting"
> Solution: exit the message and the re-enter it:
>
> macro pager \Cr ":set display_filter=display-filter\nq\n:unset
> display_filter\n"
I was copying this into my muttrc when I realized that I can reuse the
index binding. So now I have just
macro pager \Cr "<exit>\Cr"
which goes completely against what I'm about to say, but is easier to
maintain. :)
> (lol.. cue readable vs. short macro lines flamewar :)
Heh. I use readable because it's also portable when people have rebound
their keys, and therefore most useful on an archived mailing list. Many
of my bindings are different from the default, so this keeps me sane and
makes sure that anyone can use what I post. And it keeps working if I
change my own bindings! :)
> + $ENV{PARINIT} = 'rTbgqR B=.,?!_A_a Q=_s>|+';
Good -- you can also just put them on par's command line, but I prefer
using the environment. Single point of maintenance, since I use par in
several ways.
open (OUT, "| par 'rTbgq B=.,?!_A_a Q=_s>|+'") or *OUT = *STDOUT;
> Problem #2: sometimes par stops in the middle of a message with the
> error "par error: Word too long". Ironically, your message (the one I'm
> replying to) generates this very error! :)
Ouch. That's because the line has too much text unbroken by whitespace,
and (from the par manual):
R[Report] If Report is 1, it is considered an error for an
input word to contain more than L = (width -
prefix - suffix) characters. Otherwise, such
words are chopped after each Lth character into
shorter words. Defaults to 0.
Come to think of it, I don't recall any reason to use R. I think I just
wanted to see what would happen. So you can change to
PARINIT='rTbgqR B=.,?!_A_a Q=_s>|+'
to fix this.
--
-D. dgc@xxxxxxxxxxxx NSIT University of Chicago