diff options
author | C. McEnroe | 2020-04-07 10:48:44 -0400 |
---|---|---|
committer | C. McEnroe | 2020-04-07 10:48:44 -0400 |
commit | e3f7362241a82d2089a45d119b86109c9d89ec8f (patch) | |
tree | c07c14f663ae4d21c2c5eb38353c72161051b99a /edit.c | |
parent | 0bf49817f6c0c069ddee1b1e40ebfc1bae9c2639 (diff) |
Add M-q to collapse whitespace
Diffstat (limited to 'edit.c')
-rw-r--r-- | edit.c | 13 |
1 files changed, 13 insertions, 0 deletions
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)) { |