From e3f7362241a82d2089a45d119b86109c9d89ec8f Mon Sep 17 00:00:00 2001 From: C. McEnroe Date: Tue, 7 Apr 2020 10:48:44 -0400 Subject: Add M-q to collapse whitespace --- edit.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'edit.c') diff --git a/edit.c b/edit.c index 1b23737..a37a3e4 100644 --- a/edit.c +++ b/edit.c @@ -232,6 +232,19 @@ void edit(uint id, enum Edit op, wchar_t ch) { buf[pos - 1] = buf[pos]; buf[pos++] = t; } + break; case EditCollapse: { + size_t ws; + for (pos = 0; pos < len;) { + for (; pos < len && !iswspace(buf[pos]); ++pos); + for (ws = pos; ws < len && iswspace(buf[ws]); ++ws); + if (pos && ws < len) { + delete(false, pos, ws - pos - 1); + buf[pos++] = L' '; + } else { + delete(false, pos, ws - pos); + } + } + } break; case EditInsert: { if (reserve(pos, 1)) { -- cgit 1.4.1-2-gfad0