Mikhail <[email protected]> wrote:
> On Wed, Mar 02, 2022 at 09:47:31AM +0100, Omar Polo 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?
>
> I've tested the patch and it works as intended.
thanks for testing!
> I like new behavior for c-mode, but not sure if it is good for
> auto-indent one. If user presses <tab> and then <enter> I'd argue that
> removing first tab is good idea in this particular mode, but no hard
> objections, since I don't use auto-indent.
even thought i think it's more useful/intuitive the behaviour in my diff
(and coherent with vi' auto-indent) what you're suggesting is actually
in line with what GNU emacs does.
Here's an updated diff that calls delwhite before computing the
indentation for auto-indent-mode.
diff 00f81dd44029396ae6f0e446c345d3f3fe7dfca2
fa684de7df0c9db2c4f5e78b8ff0f31b29f58e2a
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 + d128ac230e48a9b3569ae552f4b3411b7ce97d1e
--- usr.bin/mg/util.c
+++ usr.bin/mg/util.c
@@ -364,6 +364,7 @@ lfindent(int f, int n)
undo_boundary_enable(FFRAND, 0);
while (n--) {
+ (void)delwhite(FFRAND, 1);
nicol = 0;
for (i = 0; i < llength(curwp->w_dotp); ++i) {
c = lgetc(curwp->w_dotp, i);