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?
>
> Cheers,
>
> Omar Polo
ping
this was also tested my Mikhail (thanks!) who suggested to follow the
GNU Emacs behavior in auto-indent-mode (i.e. first trim, then compute
the autoindent.) I initially agreed with the idea, but after some usage
I founded my proposed behaviour (which is the same as vi) generally more
useful -- GNU Emacs has special modes for all sorts of files which
behaves like my auto-indent mode change in diff below, so no need to
copy fundamental-mode.
diff 52285e8bf90b070d25259ca82322072e3b62169e
36baa54105c2f8c63288a9deb2833c89c2db1a16
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 : (