]> git.neil.brown.name Git - edlib.git/commitdiff
Get rid of attributes shift_left and shift-left
authorNeilBrown <neil@brown.name>
Fri, 25 Aug 2023 03:48:07 +0000 (13:48 +1000)
committerNeilBrown <neil@brown.name>
Fri, 25 Aug 2023 05:35:37 +0000 (15:35 +1000)
Add more meaning to render:wrap and discard shift-left and shift_left.
It was confusing having two ...  or three ...  attributes for almost the
same thing.

Signed-off-by: NeilBrown <neil@brown.name>
DOC/Developer/06-rendering.md
DOC/TODO.md
DOC/render-control
core.h
lib-askpass.c
lib-menu.c
lib-messageline.c
lib-renderline.c
mode-emacs.c
render-lines.c

index 657099afbbae8536448cd2b89cffdffa7d65d722..14b6a74382ae2acee4ddc9f2e013a4b033168c45 100644 (file)
@@ -245,8 +245,12 @@ appearing in the pane stack:
        perform detailed drawing of the background
     + "color:COLOUR" - fills the background with the given colour.
     + "image:IMAGE" - the image is drawn to fill the pane
-- "render-wrap" - if set to any value other than "yes", text is not
-   wrapped.
+- "render-wrap" - How to handle lines wider than the pane:
+       - if "yes" wrap the line onto multiple lines.
+       - if "NN" shift the line "NN" character spaces (in standard font) to left.
+       - if "NN auto", update as needed so that cursor is displayed.
+       - if not set, treat as "yes"
+       - if any other value, treat as "0 auto"
 - "render-vmargin" - if set to a number of lines, "render-lines" will
    attempt to keep the cursor at least this far from the top or bottom
    of the display.
@@ -291,11 +295,9 @@ redraw as needed.
 The pane's behaviour can be modified by several attributes that can be
 found in the stack:
 
-- "shift_left" - this should be in integer.  If less than zero the line
-  will be wrapped if it is too wide to display completely in the pane.
-  If it is non-negative then the display will not be wrapped and the
-  display will be shifted to the left this far so later parts of the
-  line can be seen.
+- "render:wrap" - this is processed the same way that render-lines
+  understands it, though no "auto" adjustment is made.  It either
+  requests wrap or sets the shift size.
 
 - "prefix" - This marked-up text will be display first.  It will not be
   shifted even when the main text is shifted left.
index f051ba3a0dff193bbb60883f2e6addfd5e5bb21d..ecd90022ea59b73896132ad58633079c75b746f3 100644 (file)
@@ -37,7 +37,8 @@ the file.
        replacement string is shorter.  If longer, they get added.
 - [X] path completion in shell command.  If cannot find look for '/'
       following punctuation (=) and try there.
-- [ ] resolve shift-left vs shift_left distinction - add a "fixed" suffix?
+- [X] resolve shift-left vs shift_left distinction - add a "fixed"
+      suffix? Also consider render-wrap
 - [ ] should zoom affect whole window, not just pane?
 - [X] ditch cached-size for images - store in pane data instead.
 - [X] use foreach_attr for parsing image details
index 23cdf20140aaaefd508cf660f077c2ab6e25908d..b3bf9a7b51cbe8da7c0d4080d3a4e40321928274 100644 (file)
@@ -200,7 +200,11 @@ Several pane attributes can affect the pane as a whole:
  - "scale" - width/height values to aim for - in "points" which are 1/10 for an M
           e.g. if 800x240, then text is scaled so that at least 80 M's fit across,
           and 24 M's fit down.
- - "render-wrap" - if define but not "yes", don't wrap long lines, else shift left to
-          fit cursor on pane.
+ - "render-wrap" - How to handle lines wider than the pane:
+       - if "yes" wrap the line onto multiple lines.
+       - if "NN" shift the line "NN" character spaces (in standard font) to left.
+       - if "NN auto", update as needed so that cursor is displayed.
+       - if not set, treat as "yes"
+       - if any other value, treat as "0 auto"
  - "prefix" - text to place at start of each line.  This can be used as a prompt in a
           dialogue box.
diff --git a/core.h b/core.h
index 68bc788890c141c2bb1d7dfad59db9d0cca16372..8987d3d496bc29f5aefafc689c812fae81bbace5 100644 (file)
--- a/core.h
+++ b/core.h
@@ -495,7 +495,7 @@ static inline int pane_attr_get_int(struct pane *p safe, const char *key safe,
        if (!c)
                return dflt;
        rv = strtol(c, &end, 10);
-       if (end == c || !end || *end)
+       if (end == c || !end || (*end && *end != ' '))
                return dflt;
        return rv;
 }
index 6ab786c10a2bae64e2c40bf143a411385e649f61..c880591416c551e3d817ceda7815122bed44acea 100644 (file)
@@ -40,7 +40,7 @@ DEF_CMD(askpass_refresh_view)
        call("render-line:set", ci->focus, b.len, NULL, buf_final(&b));
        for (i = 0; i < 10; i++) {
                int cw;
-               attr_set_int(&ci->focus->attrs, "shift_left", shift);
+               attr_set_int(&ci->focus->attrs, "render-wrap", shift);
                call("render-line:measure", ci->focus, b.len);
                cw = pane_attr_get_int(ci->focus, "curs_width", 1);
                if (ci->home->parent->cx < ci->home->parent->w - cw)
index f21ec3703c5c04f6e09d9b66d4bdb53bad5f77ef..296286b8a8c9a9479aefbcd422f476dd18f53aed 100644 (file)
@@ -94,7 +94,7 @@ DEF_CMD(menu_attach)
                return Efail;
        call("doc:set:autoclose", docp, 1);
        attr_set_str(&docp->attrs, "render-simple", "format");
-       attr_set_str(&docp->attrs, "shift-left", "0");
+       attr_set_int(&docp->attrs, "render-wrap", 0);
        attr_set_str(&docp->attrs, "heading", "");
        attr_set_str(&docp->attrs, "line-format", "<action-activate:menu-select>%name</>");
        attr_set_str(&docp->attrs, "done-key", ci->str2 ?: "menu-done");
index ae6540ec5ac1ba8a006ef32d6610c4f5d6e7e696..d6e6ba097356578a08ff4a6bcc23ff858f56fa6b 100644 (file)
@@ -260,7 +260,7 @@ static struct pane *do_messageline_attach(struct pane *p safe)
                return NULL;
        }
        /* Support wrapping */
-       attr_set_int(&mlp->attrs, "shift_left", -1);
+       attr_set_str(&mlp->attrs, "render:wrap", "yes");
        pane_damaged(ret, DAMAGED_VIEW);
        mli->line = mlp;
        pane_focus(ret);
index 5cbaa2a26b11227ac2d4ca3a83101af46652ad9e..ef34b8a68a57769ee90a9c71f467862624e51659 100644 (file)
@@ -517,7 +517,7 @@ static int measure_line(struct pane *p safe, struct pane *focus safe, int offset
         */
        struct rline_data *rd = &p->data;
        struct render_item *ri, *wraprl;
-       int shift_left = pane_attr_get_int(focus, "shift_left", 0);
+       int shift_left = pane_attr_get_int(focus, "render-wrap", -1);
        bool wrap = shift_left < 0;
        int wrap_margin;
        int right_margin;
index 389c18bf0bb81afa44ea7e231016b5837c637fc4..eae289356f68bfb762535f664728c2ea51be0c24 100644 (file)
@@ -2704,7 +2704,7 @@ DEF_CMD(emacs_shift)
        int rpt = ci->num;
        int shift;
 
-       shift = pane_attr_get_int(ci->focus, "shift-left", -1);
+       shift = pane_attr_get_int(ci->focus, "render-wrap", -1);
        if (strcmp(ci->key, "K:CX->") == 0 || strcmp(ci->key, "K->") == 0)
                rpt = -rpt;
        if (rpt == NO_NUMERIC) {
@@ -2730,9 +2730,14 @@ DEF_CMD(emacs_shift)
                        shift += rpt;
        }
        if (shift < 0)
-               attr_set_str(&ci->focus->attrs, "shift-left", "");
+               attr_set_str(&ci->focus->attrs, "render-wrap", "yes");
+       else if (shift > 0)
+               attr_set_int(&ci->focus->attrs, "render-wrap", shift);
+       else if (rpt > 0)
+               attr_set_str(&ci->focus->attrs, "render-wrap", "0 auto");
        else
-               attr_set_int(&ci->focus->attrs, "shift-left", shift);
+               /* When reducing shift to zero, don't enable auto */
+               attr_set_int(&ci->focus->attrs, "render-wrap", 0);
        call("view:changed", ci->focus);
        call("Mode:set-num2", ci->focus, N2_shift);
        call("Message:modal", ci->focus, 0, NULL, "Type < or > to shift again");
index 459a3f95bcd53389249884ff319623c279eb7140..b6e8622801843f1d33d99d5b6d0fa2ee08a961a6 100644 (file)
@@ -170,12 +170,22 @@ static int _measure_line(struct pane *p safe, struct pane *focus safe,
                          struct mark *mk safe, short cursor_offset,
                          char **cursor_attr)
 {
+       struct rl_data *rl = p->data;
        struct pane *hp = mk->mdata;
        struct call_return cr;
 
        if (!mark_valid(mk) || !hp)
                return False;
        pane_resize(hp, hp->x, hp->y, p->w, p->h);
+       if (!rl->shift_locked) {
+               int sl = pane_attr_get_int(focus, "render-wrap", -2);
+               if (sl != rl->shift_left) {
+                       char *sla = NULL;
+                       asprintf(&sla, "%d auto", rl->shift_left);
+                       attr_set_str(&focus->attrs, "render-wrap", sla);
+                       free(sla);
+               }
+       }
        cr = pane_call_ret(all, hp, "render-line:measure",
                           focus, cursor_offset);
        if (cursor_attr)
@@ -990,21 +1000,6 @@ static int render(struct mark *pm, struct pane *p safe,
        return y;
 }
 
-DEF_CMD(render_lines_get_attr)
-{
-       struct rl_data *rl = ci->home->data;
-
-       if (ci->str && strcmp(ci->str, "shift_left") == 0) {
-               char ret[10];
-               if (rl->do_wrap && !rl->shift_locked)
-                       return comm_call(ci->comm2, "cb", ci->focus,
-                                        0, NULL, "-1");
-               snprintf(ret, sizeof(ret), "%d", rl->shift_left);
-               return comm_call(ci->comm2, "cb", ci->focus, 0, NULL, ret);
-       }
-       return Efallthrough;
-}
-
 DEF_CMD(render_lines_point_moving)
 {
        struct pane *p = ci->home;
@@ -1222,27 +1217,46 @@ DEF_CMD(render_lines_revise)
        struct mark *pm = NULL;
        struct mark *m1, *m2;
        bool refresh_all = False;
+       bool wrap;
        char *hdr;
        char *a;
        int shift;
 
        a = pane_attr_get(focus, "render-wrap");
-       if (rl->do_wrap != (!a || strcmp(a, "yes") ==0)) {
-               rl->do_wrap = (!a || strcmp(a, "yes") ==0);
+       wrap = (!a || strcmp(a, "yes") == 0);
+       if (rl->do_wrap != wrap) {
+               rl->do_wrap = wrap;
                refresh_all = True;
+               rl->shift_left = 0;
+       }
+       if (wrap)
+               rl->shift_locked = True;
+       if (!a)
+               /* avoid any ambiguity */
+               attr_set_str(&focus->attrs, "render-wrap", "yes");
+
+       if (a) {
+               char *end;
+               shift = strtol(a, &end, 10);
+               if (end == a || (end && *end && *end != ' '))
+                       shift = -1;
        }
+       else
+               shift = -1;
 
-       shift = pane_attr_get_int(focus, "shift-left", -1);
-       if (shift >= 0) {
+       if (a && shift >= 0) {
                if (rl->shift_left != shift)
                        refresh_all = True;
 
                rl->shift_left = shift;
-               rl->shift_locked = 1;
-       } else {
+               rl->shift_locked = strstr(a, "auto") == NULL;
+       } else if (!wrap) {
+               /* unrecognised - no wrap, not locked */
                if (rl->shift_locked)
                        refresh_all = True;
+               rl->shift_left = 0;
                rl->shift_locked = 0;
+               attr_set_str(&focus->attrs, "render-wrap", "0 auto");
        }
        if (refresh_all) {
                struct mark *v;
@@ -1966,7 +1980,6 @@ static void render_lines_register_map(void)
        key_add(rl_map, "Refresh:view", &render_lines_revise);
        key_add(rl_map, "Refresh:size", &render_lines_resize);
        key_add(rl_map, "Notify:clip", &render_lines_clip);
-       key_add(rl_map, "get-attr", &render_lines_get_attr);
        key_add(rl_map, "mark:moving", &render_lines_point_moving);
 
        key_add(rl_map, "doc:replaced", &render_lines_notify_replace);