~sircmpwn/aerc

lib/templates: don't wrap lines that may be code v1 PROPOSED

Evan Gates: 1
 lib/templates: don't wrap lines that may be code

 1 files changed, 2 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/14297/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] lib/templates: don't wrap lines that may be code Export this patch

The wrapText function used in the quoted_reply template squeezes
whitespace due to the use of strings.Fields.  As a result any code in
the body would lose leading whitespace for indentation.  There was
already a check to not wrap quoted lines (lines begining with '>').
Add more characters and don't wrap if a line starts with '+', '-',
' ', '\t'.  These characters provide an heuristic that the text is
code or part of a patch.
---
 lib/templates/template.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/templates/template.go b/lib/templates/template.go
index 4346111..31bf46f 100644
--- a/lib/templates/template.go
+++ b/lib/templates/template.go
@@ -118,8 +118,8 @@ func wrapText(text string, lineWidth int) string {
		switch {
		case line == "":
			// deliberately left blank
		case line[0] == '>':
			// leave quoted text alone
		case strings.IndexByte(">+- \t", line[0]) != -1:
			// do not wrap lines that are quoted or probably code
			wrapped.WriteString(line)
		default:
			wrapped.WriteString(wrapLine(line, lineWidth))
-- 
2.28.0
thanks for the patch.
However I won't merge this, if you don't want wrapping use a different template.

We shouldn't special case characters other than the quoting char.