10 weeks bump :)

(+cc lum@)

Omar Polo <[email protected]> wrote:
> 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?

This was also tested by Mikhail (thanks!) who suggested to follow the
GNU Emacs behavior of auto-indent-mode (i.e. first trim, then compute
the autoindent.)  Initially I agreed, but after some usage I find my
proposed behaviour more useful since mg lacks an automagic indentation
for sh, awk, conf, ...

diff f2222d726a6788bfd748bd7a97d560a67c0fa887 
c9a41b1dcf7c2abb23d39c14e8e488d5bb193a95
blob - 6c0ef5b897536c8c2d6e0faa6500e5a64ea57598
blob + 7b47402aa1145e41a7e8b14ea62fcd3d49bab074
--- usr.bin/mg/cmode.c
+++ usr.bin/mg/cmode.c
@@ -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));
blob - 4d38284f3b886043336ff967602354f0fc81a4fd
blob + 2593eb6b63a675ee6b928cf13a574ebf8f9b5acf
--- usr.bin/mg/util.c
+++ usr.bin/mg/util.c
@@ -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