Hello tech,

mg(1) has this tendency to leave a lot of trailing whitespaces around in
auto-indent-mode and c-mode which I find annoying.  Yes, there's
delete-trailing-space but it works only on the current line (and not the
whole buffer as in emacs) and one has to manually call it anyway.
Emacs, and even vi in base, are clever in this regard: trailing
whitespaces before the cursor are delete upon RET before adding a new
line.

So, here's the same heuristic for mg when auto-indent-mode or c-mode is
enabled.  It's still possible to leave trailing whitespace in a buffer
in those modes, it only gets a little bit harder to do.

(as a next step I guess we could also garbage collect cc_strip_trailp,
it was used in only one place before this patch and is unconditionally
set to TRUE.)

Thoughts/OK?

Cheers,

Omar Polo


Index: cmode.c
===================================================================
RCS file: /home/cvs/src/usr.bin/mg/cmode.c,v
retrieving revision 1.17
diff -u -p -r1.17 cmode.c
--- cmode.c     11 Jul 2019 18:20:18 -0000      1.17
+++ cmode.c     2 Mar 2022 08:28:59 -0000
@@ -205,6 +205,8 @@ cc_lfindent(int f, int n)
 {
        if (n < 0)
                return (FALSE);
+       if (cc_strip_trailp)
+               (void)delwhite(FFRAND, 1);
        if (enewline(FFRAND, 1) == FALSE)
                return (FALSE);
        return (cc_indent(FFRAND, n));
Index: util.c
===================================================================
RCS file: /home/cvs/src/usr.bin/mg/util.c,v
retrieving revision 1.43
diff -u -p -r1.43 util.c
--- util.c      1 Mar 2021 10:51:14 -0000       1.43
+++ util.c      2 Mar 2022 08:26:49 -0000
@@ -373,6 +373,7 @@ lfindent(int f, int n)
                                nicol |= 0x07;
                        ++nicol;
                }
+               (void)delwhite(FFRAND, 1);
                if (lnewline() == FALSE || ((
 #ifdef NOTAB
                    curbp->b_flag & BFNOTAB) ? linsert(nicol, ' ') == FALSE : (

Reply via email to