]> git.neil.brown.name Git - edlib.git/commitdiff
Introduce doc_following_pane and change many mark_next/mark_prev to _pane
authorNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:20:35 +0000 (13:20 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:54:09 +0000 (13:54 +1100)
still tring to get 'doc' references out of non-core/doc code.

Signed-off-by: NeilBrown <neil@brown.name>
core.h
lib-search.c
mode-emacs.c
render-format.c
render-hex.c

diff --git a/core.h b/core.h
index 7fb05f598ec1024f48b93194184d6b535936bdf3..cbf9da989b3dca961c6de0ffc2cfe192ed6d794b 100644 (file)
--- a/core.h
+++ b/core.h
@@ -179,6 +179,8 @@ struct mark *point_new(struct doc *d);
 struct mark *point_dup(struct mark *p);
 wint_t mark_step(struct doc *d, struct mark *m, int forward, int move, struct cmd_info *ci);
 wint_t mark_step2(struct doc *d, struct mark *m, int forward, int move);
+wint_t mark_step_pane(struct pane *p, struct mark *m, int forward, int move, struct cmd_info *ci);
+
 wint_t mark_next(struct doc *d, struct mark *m);
 wint_t mark_prev(struct doc *d, struct mark *m);
 wint_t mark_next_pane(struct pane *p, struct mark *m);
@@ -353,6 +355,10 @@ static inline wint_t doc_following(struct doc *d, struct mark *m)
 {
        return mark_step2(d, m, 1, 0);
 }
+static inline wint_t doc_following_pane(struct pane *p, struct mark *m)
+{
+       return mark_step_pane(p, m, 1, 0, NULL);
+}
 static inline wint_t doc_prior(struct doc *d, struct mark *m)
 {
        return mark_step2(d, m, 0, 0);
index 55747ba16588b24baa6206b054c61b2fd42b7941..1ec87671ebf83dc87670428d01562924524557ee 100644 (file)
 DEF_CMD(text_search)
 {
        struct mark *m, *endmark = NULL;;
-       struct doc *d;
        unsigned short *rxl;
        struct match_state *st;
        int since_start, len;
 
-       if (!ci->str|| !ci->mark)
+       if (!ci->str|| !ci->mark || !ci->focus)
                return -1;
 
-       d = doc_from_pane(ci->focus);
-       if (!d)
-               return -1;
        m = ci->mark;
        rxl = rxl_parse(ci->str, NULL, 1);
        if (!rxl)
@@ -33,7 +29,7 @@ DEF_CMD(text_search)
        st = rxl_prepare(rxl);
        since_start = -1;
        while (since_start < 0 || len != -2) {
-               wint_t wch = mark_next(d, m);
+               wint_t wch = mark_next_pane(ci->focus, m);
                if (wch == WEOF)
                        break;
 
index 2d1b0921d52082e08905d39994b1f14a4fb80aa2..047751ab3518fe9dc47d429dca5248daef51af94 100644 (file)
@@ -131,13 +131,12 @@ REDEF_CMD(emacs_delete)
        struct move_command *mv = container_of(ci->comm, struct move_command, cmd);
        int ret = 0;
        struct mark *m;
-       struct doc *d = doc_from_pane(ci->home);
 
        m = mark_dup(ci->mark, 1);
 
        if (strcmp(mv->type, "Move-EOL") == 0 &&
            mv->direction == 1 && RPT_NUM(ci) == 1 &&
-           doc_following(d, m) == '\n')
+           doc_following_pane(ci->focus, m) == '\n')
                ret = call3("Move-Char", ci->focus, mv->direction * RPT_NUM(ci), m);
        else
                ret = call3(mv->type, ci->focus, mv->direction * RPT_NUM(ci), m);
index a46d2d2ce39c30336957bb06bbb07b5a85df73ba..0c7df85f39c973d0b33989dbf4d245eca92db5c6 100644 (file)
@@ -34,12 +34,12 @@ DEF_CMD(render_line)
        int field = 0;
        int rv;
 
-       if (!d || !ci->mark)
+       if (!d || !ci->mark || !ci->focus)
                return -1;
 
        if (pm && !mark_same_pane(ci->home, pm, m, NULL))
                pm = NULL;
-       ch = doc_following(d, m);
+       ch = doc_following_pane(ci->focus, m);
        if (ch == WEOF)
                return 1;
        buf_init(&ret);
@@ -145,7 +145,7 @@ endwhile:
                        ;
                else {
                        buf_append(&ret, '\n');
-                       mark_next(d, m);
+                       mark_next_pane(ci->focus, m);
                }
        }
        rv = comm_call(ci->comm2, "callback:render", ci->focus, 0, NULL,
@@ -157,12 +157,11 @@ endwhile:
 DEF_CMD(render_line_prev)
 {
        struct mark *m = ci->mark;
-       struct doc *d = doc_from_pane(ci->home);
 
        if (RPT_NUM(ci) == 0)
                /* always at start-of-line */
                return 1;
-       if (mark_prev(d, m) == WEOF)
+       if (mark_prev_pane(ci->home, m) == WEOF)
                /* Hit start-of-file */
                return -1;
        return 1;
@@ -190,17 +189,16 @@ DEF_CMD(format_clone)
 
 DEF_CMD(format_move_line)
 {
-       struct doc *d = doc_from_pane(ci->focus);
        int rpt = RPT_NUM(ci);
        struct rf_data *rf = ci->home->data;
 
        while (rpt > 1) {
-               if (mark_next(d, ci->mark) == WEOF)
+               if (mark_next_pane(ci->focus, ci->mark) == WEOF)
                        break;
                rpt -= 1;
        }
        while (rpt < -1) {
-               if (mark_prev(d, ci->mark) == WEOF)
+               if (mark_prev_pane(ci->focus, ci->mark) == WEOF)
                        break;
                rpt += 1;
        }
@@ -218,17 +216,16 @@ DEF_CMD(format_move_horiz)
        /* Horizonal movement - adjust ->rpos within fields, or
         * move to next line
         */
-       struct doc *d = doc_from_pane(ci->focus);
        struct rf_data *rf = ci->home->data;
        int rpt = RPT_NUM(ci);
 
        if (rf->fields < 2)
                return 1;
-       while (rpt > 0 && doc_following(d, ci->mark) != WEOF) {
+       while (rpt > 0 && doc_following_pane(ci->focus, ci->mark) != WEOF) {
                if (ci->mark->rpos < rf->fields - rf->home_field + 1)
                        ci->mark->rpos += 1;
                else {
-                       if (mark_next(d, ci->mark) == WEOF)
+                       if (mark_next_pane(ci->focus, ci->mark) == WEOF)
                                break;
                        ci->mark->rpos = -rf->home_field;
                }
@@ -238,7 +235,7 @@ DEF_CMD(format_move_horiz)
                if (ci->mark->rpos > -rf->home_field)
                        ci->mark->rpos -= 1;
                else {
-                       if (mark_prev(d, ci->mark) == WEOF)
+                       if (mark_prev_pane(ci->focus, ci->mark) == WEOF)
                                break;
                        ci->mark->rpos = rf->fields - rf->home_field + 1;
                }
index 9148169d90599a679f51ebcba1e4348ace51d02d..7230f869ddea4da7704c43b6530891df92a08d1c 100644 (file)
@@ -80,7 +80,6 @@ DEF_CMD(render_hex_notify)
 
 DEF_CMD(render_hex_eol)
 {
-       struct doc *d = doc_from_pane(ci->home);
        wint_t ch = 1;
        int rpt = RPT_NUM(ci);
        int pos;
@@ -95,21 +94,21 @@ DEF_CMD(render_hex_eol)
        pos = attr_find_int(*mark_attr(ci->mark), "chars");
        while (rpt > 0 && ch != WEOF) {
                while ((pos & 15) != 15 &&
-                      (ch = mark_next(d, ci->mark)) != WEOF)
+                      (ch = mark_next_pane(ci->focus, ci->mark)) != WEOF)
                        pos += 1;
                rpt -= 1;
                if (rpt) {
-                       ch = mark_next(d, ci->mark);
+                       ch = mark_next_pane(ci->focus, ci->mark);
                        pos += 1;
                }
        }
        while (rpt < 0 && ch != WEOF) {
                while ((pos & 15) != 0 &&
-                      (ch = mark_prev(d, ci->mark)) != WEOF)
+                      (ch = mark_prev_pane(ci->focus, ci->mark)) != WEOF)
                        pos -= 1;
                rpt += 1;
                if (rpt) {
-                       ch = mark_prev(d, ci->mark);
+                       ch = mark_prev_pane(ci->focus, ci->mark);
                        pos -= 1;
                }
        }
@@ -121,14 +120,13 @@ DEF_CMD(render_line)
        struct buf ret;
        struct cmd_info ci2 = {0};
        struct mark *m = NULL;
-       struct doc *d = doc_from_pane(ci->home);
        struct mark *pm = ci->mark2;
        int pos;
        int i;
        char buf[10];
        int rv;
 
-       if (!d || !ci->mark)
+       if (!ci->focus || !ci->mark)
                return -1;
 
        ci2.key = "CountLines";
@@ -138,7 +136,7 @@ DEF_CMD(render_line)
        pos = attr_find_int(*mark_attr(ci->mark), "chars");
 
        buf_init(&ret);
-       if (doc_following(d, ci->mark) == WEOF)
+       if (doc_following_pane(ci->focus, ci->mark) == WEOF)
                goto done;
        sprintf(buf, "<bold>%08x:</> ", pos);
        buf_concat(&ret, buf);
@@ -153,7 +151,7 @@ DEF_CMD(render_line)
                    ci->numeric <= ret.len)
                        goto done;
 
-               ch = mark_next(d, m2);
+               ch = mark_next_pane(ci->focus, m2);
                if (ch == WEOF)
                        strcpy(buf, "   ");
                else
@@ -167,7 +165,7 @@ DEF_CMD(render_line)
        for (i = 0; i < 16; i++) {
                wint_t ch;
 
-               ch = mark_next(d, m);
+               ch = mark_next_pane(ci->focus, m);
                if (ch == WEOF)
                        ch = ' ';
                if (ch < ' ')
@@ -192,7 +190,6 @@ DEF_CMD(render_line_prev)
        /* If ->numeric is 0, round down to multiple of 16.
         * if it is 1, subtract a further 16.
         */
-       struct doc *d = doc_from_pane(ci->home);
        struct cmd_info ci2 = {0};
        int to, from;
 
@@ -206,7 +203,7 @@ DEF_CMD(render_line_prev)
        if (ci->numeric && to >= 16)
                to -= 16;
        while (to < from) {
-               mark_prev(d, ci->mark);
+               mark_prev_pane(ci->focus, ci->mark);
                from -= 1;
        }
        return 1;