diff options
author | Robin Jarry <robin@jarry.cc> | 2022-12-01 20:17:04 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-12-05 17:25:12 +0100 |
commit | c9524d265793775e4c3e326c7191471d982c1e66 (patch) | |
tree | e6d3cee41885f94dd3ce00c09c774536af748f1d /doc | |
parent | be8154d1a77c9dce313a94e51e1b5bea7a21d7b7 (diff) | |
download | aerc-c9524d265793775e4c3e326c7191471d982c1e66.tar.gz |
filters: add wrap utility written in go
I had started writing this as an awk script but quickly got stuck with
obscure code which did not even work properly. I jumped the gun and re
did it in go. Bonus, we will not have MacOS's 1987 BSD awk issues. On
the other hand, instead of a 20.0K awk script, we now have a 2.2M static
go binary. If this makes people scream, I challenge them to do that with
BSD awk :)
Basically, this takes text from stdin or from a file and wraps long
lines on word boundaries. It takes care of not breaking up email quotes
nor list items (numbered as well). Also, it is conservative by default
and only wraps long lines and lines that end with a space (indicating
a format=flowed message).
If the AERC_SUBJECT environment variable is defined and contains the
word PATCH, the text is not modified at all (i.e. wrap behaves as
cat(1)).
There are a few command line options to control behavior:
Usage of ./wrap:
-f string
read from file instead of stdin
-l int
minimum percentage of letters in a line to be considered
a paragaph (default 50)
-r reflow all paragraphs even if no trailing space
-w int
preferred wrap margin (default 80)
Update docs, makefile and default config file with examples.
Add a torture test to ensure it works as expected.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/aerc-config.5.scd | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd index ac9a3a73..17a96f07 100644 --- a/doc/aerc-config.5.scd +++ b/doc/aerc-config.5.scd @@ -636,22 +636,19 @@ _text/plain_ ``` Wrap long lines at 100 characters, while not messing up nested quotes. - Not perfect, but works for most emails: + Handles format=flowed emails properly: ``` - text/plain=fmt -s -p ">>" -w 100 | fmt -s -p ">" -w 100 | fmt -s -w 100 | colorize + text/plain=wrap -w 100 | colorize ``` _from,<sender>_ Another example of hard wrapping lines of emails sent by a specific - person but using neovim which handles nested quotes without issues: + person. Explicitly reflow all paragraphs instead of only wrapping long + lines. This may break manual formatting in some messages: ``` - from,thatguywhoneverhardwrapshismessages=case "$AERC_SUBJECT" in \\ - \*PATCH\*) cat;; \\ - \*) nvim - -u NONE -es '+set ft=mail fo=tcqwn1j tw=80' \\ - '+:norm! gggqG' '+%print' '+:q!';; \\ - esac | colorize + from,thatguywhoneverhardwrapshismessages=wrap -r -w 72 | colorize ``` _subject,~<regexp>_ |