From 2fa5e8b4c48db4e7dffbf5676e7946d73024f56e Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Tue, 25 Mar 2025 14:15:08 -0400 Subject: [PATCH] AutoYADM commit: 2025-03-25 14:15:08 --- .../aerc/helix-config/.helix/languages.toml | 3 +- .config/mail/1742924137042008814_13717.py | 4 -- .config/mail/format.py | 67 +++++++++---------- .config/mail/format2.py | 49 -------------- 4 files changed, 34 insertions(+), 89 deletions(-) delete mode 100755 .config/mail/1742924137042008814_13717.py delete mode 100755 .config/mail/format2.py diff --git a/.config/aerc/helix-config/.helix/languages.toml b/.config/aerc/helix-config/.helix/languages.toml index 137c2d59..46d33381 100644 --- a/.config/aerc/helix-config/.helix/languages.toml +++ b/.config/aerc/helix-config/.helix/languages.toml @@ -2,5 +2,6 @@ name = "markdown" file-types = [{ glob = "/tmp/aerc-compose-*.eml" }] language-servers = ["harper-ls", "marksman", "scls"] -formatter = { command = "/usr/lib/aerc/filters/wrap", args = ["-w", "74"] } +# formatter = { command = "/usr/lib/aerc/filters/wrap", args = ["-w", "74"] } +formatter = { command = "/home/fic/.config/mail/format.py" } auto-format = true diff --git a/.config/mail/1742924137042008814_13717.py b/.config/mail/1742924137042008814_13717.py deleted file mode 100755 index d9124dd6..00000000 --- a/.config/mail/1742924137042008814_13717.py +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/env python - -print("test") - diff --git a/.config/mail/format.py b/.config/mail/format.py index 6077fa92..ca87b44b 100755 --- a/.config/mail/format.py +++ b/.config/mail/format.py @@ -1,49 +1,46 @@ #!/bin/env python +# Simple text-wrapping script for email. +# Preserves code blocks, quotes, and signature. +# Author: Daniel Fichtinger +# License: MIT + import textwrap import sys -# first pass: reflow paragraphs + paragraph = [] -lines = [] skipping = False + +def flush_paragraph(): + if paragraph: + joined = " ".join(paragraph) + wrapped = textwrap.wrap(joined, width=74, break_long_words=False, replace_whitespace=True) + print("\n".join(wrapped)) + paragraph.clear() + for line in sys.stdin: line = line.rstrip() - if line: - if line.startswith(">") or skipping: - # ignore quoted line - lines.append(line) - elif line.startswith("```"): - # ignore code block - skipping = not skipping - lines.append(line) - elif line.startswith("--"): - skipping = True - lines.append(line) - else: - paragraph.append(line) - else: - if paragraph: - lines.append(' '.join(paragraph)) - paragraph = [] - lines.append("\n") -if paragraph: - lines.append(' '.join(paragraph)) -skipping = False -for line in lines: - if line.startswith(">"): - # ignore quoted line - print(line) - elif line.startswith("```"): - # ignore code block + + if line.startswith("```"): + flush_paragraph() skipping = not skipping print(line) + elif line.startswith(">"): + flush_paragraph() + print(line) + elif line.startswith(("- ", "+ ", "* ", "\t", " ")): + flush_paragraph() + print(line) elif line.startswith("--"): + flush_paragraph() skipping = True print(line) + elif not line: + flush_paragraph() + print(line) + elif skipping: + print(line) else: - # TODO: fix signature being mangled and newlines erased - if not skipping: - wrapped = textwrap.wrap(line, width=74, break_long_words=False, replace_whitespace=True) - print("\n".join(wrapped)) - else: - print(line) + paragraph.append(line) +else: + flush_paragraph() diff --git a/.config/mail/format2.py b/.config/mail/format2.py deleted file mode 100755 index 6077fa92..00000000 --- a/.config/mail/format2.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/env python - -import textwrap -import sys -# first pass: reflow paragraphs -paragraph = [] -lines = [] -skipping = False -for line in sys.stdin: - line = line.rstrip() - if line: - if line.startswith(">") or skipping: - # ignore quoted line - lines.append(line) - elif line.startswith("```"): - # ignore code block - skipping = not skipping - lines.append(line) - elif line.startswith("--"): - skipping = True - lines.append(line) - else: - paragraph.append(line) - else: - if paragraph: - lines.append(' '.join(paragraph)) - paragraph = [] - lines.append("\n") -if paragraph: - lines.append(' '.join(paragraph)) -skipping = False -for line in lines: - if line.startswith(">"): - # ignore quoted line - print(line) - elif line.startswith("```"): - # ignore code block - skipping = not skipping - print(line) - elif line.startswith("--"): - skipping = True - print(line) - else: - # TODO: fix signature being mangled and newlines erased - if not skipping: - wrapped = textwrap.wrap(line, width=74, break_long_words=False, replace_whitespace=True) - print("\n".join(wrapped)) - else: - print(line)