Menu

#371 purify has no effect

Unknown
open
nobody
None
v4.4
5
2020-01-14
2017-05-07
No

The purify mode doesn't seem to have any effect when it is set in the editor. In fact, the only places it is referenced in the source code are commented out (in lindent and rindent). I think it probably should have an effect on save: remove trailing whitespace from otherwise blank lines -- and this is in-line with what most other source editors do.

Related to [#350]

Related

Bugs: #350

Discussion

  • John J. Jordan

    John J. Jordan - 2017-05-07
    • Applies To: v4.3 --> v4.4
     
  • John J. Jordan

    John J. Jordan - 2017-05-07

    Updating applies-to

     
  • John J. Jordan

    John J. Jordan - 2020-01-14

    Proposed change. If -purify set, then trim lines before save. Alternately, this could be specified as -msnew trimlines, -msold trimlines if we don't want to re-purpose the option.

    diff -r a1e841ca6188 joe/cmd.c
    --- a/joe/cmd.c Thu Oct 25 18:32:00 2018 -0400
    +++ b/joe/cmd.c Mon Jan 13 19:52:05 2020 -0800
    @@ -206,6 +206,7 @@
            {"tomatch", TYPETW + TYPEPW + EFIXXCOL, utomatch, NULL, 0, NULL},
            {"tomouse", TYPETW+TYPEPW+TYPEQW+TYPEMENU, utomouse, 0, 0, 0 },
            {"tos", TYPETW + TYPEPW + EMOVE, utos, NULL, 0, NULL},
    
    +       {"trimlines", TYPETW, utrimlines, NULL, 0, NULL},
            {"tw0", TYPETW + TYPEPW + TYPEQW + TYPEMENU, utw0, NULL, 0, NULL},
            {"tw1", TYPETW + TYPEPW + TYPEQW + TYPEMENU, utw1, NULL, 0, NULL},
            {"txt", TYPETW + TYPEPW, utxt, NULL, 0, NULL},
    diff -r a1e841ca6188 joe/ufile.c
    --- a/joe/ufile.c       Thu Oct 25 18:32:00 2018 -0400
    +++ b/joe/ufile.c       Mon Jan 13 19:52:05 2020 -0800
    @@ -333,6 +333,14 @@
            if (bw->b->er == 0 && bw->o.msold) {
                    exmacro(bw->o.msold, 1, NO_MORE_DATA);
            }
    +       if (bw->b->o.purify) {
    +               static CMD *trimlines = 0;
    +               if (!trimlines) {
    +                       trimlines = findcmd("trimlines");
    +               }
    +
    +               execmd(trimlines, NO_MORE_DATA);
    +       }
            if ((fl = bsave(bw->b->bof, req->name, bw->b->eof->byte, req->rename ? 2 : 1)) != 0) {
                    msgnw(bw->parent, joe_gettext(msgs[-fl]));
                    if (req->callback) {
    diff -r a1e841ca6188 joe/uformat.c
    --- a/joe/uformat.c     Thu Oct 25 18:32:00 2018 -0400
    +++ b/joe/uformat.c     Mon Jan 13 19:52:05 2020 -0800
    @@ -799,3 +799,43 @@
            } else
                    return uformat(w, 0);
     }
    +
    +/* Clean up indentation: Remove indentation from blank lines */
    +
    +int utrimlines(W *w, int k)
    +{
    +       P *p, *q;
    +       BW *bw;
    +       struct charmap *map;
    +       int c;
    +
    +       WIND_BW(bw, w);
    +
    +       p = pdup(bw->b->bof, "utrimlines");
    +       map = bw->b->o.charmap;
    +
    +       while (!piseof(p)) {
    +               p->valcol = 0; /* Avoid some extra work */
    +               p_goto_eol(p);
    +               q = pdup(p, "utrimlines");
    +
    +               do {
    +                       c = prgetc(q);
    +               } while (joe_isblank(map, c));
    +
    +               /* We read a non-blank unless we bumped the bof */
    +               if (c != NO_MORE_DATA) {
    +                       pgetc(q);
    +               }
    +
    +               if (q->byte < p->byte) {
    +                       bdel(q, p);
    +               }
    +
    +               prm(q);
    +               pgetc(p);
    +       }
    +
    +       prm(p);
    +       return 0;
    +}
    diff -r a1e841ca6188 joe/uformat.h
    --- a/joe/uformat.h     Thu Oct 25 18:32:00 2018 -0400
    +++ b/joe/uformat.h     Mon Jan 13 19:52:05 2020 -0800
    @@ -14,3 +14,4 @@
     void wrapword(BW *bw, P *p, off_t indent, int french, int no_over, char *indents);
     int uformat(W *w, int k);
     int ufmtblk(W *w, int k);
    +int utrimlines(W *w, int k);
    
     

Log in to post a comment.

MongoDB Logo MongoDB