From: NeilBrown Date: Thu, 10 Dec 2015 02:20:35 +0000 (+1100) Subject: Introduce doc_following_pane and change many mark_next/mark_prev to _pane X-Git-Tag: lca2016~80 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=55123386a61ae374c83c58d63e2fcf0b97d3ac94;p=edlib.git Introduce doc_following_pane and change many mark_next/mark_prev to _pane still tring to get 'doc' references out of non-core/doc code. Signed-off-by: NeilBrown --- diff --git a/core.h b/core.h index 7fb05f59..cbf9da98 100644 --- 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); diff --git a/lib-search.c b/lib-search.c index 55747ba1..1ec87671 100644 --- a/lib-search.c +++ b/lib-search.c @@ -15,17 +15,13 @@ 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; diff --git a/mode-emacs.c b/mode-emacs.c index 2d1b0921..047751ab 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -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); diff --git a/render-format.c b/render-format.c index a46d2d2c..0c7df85f 100644 --- a/render-format.c +++ b/render-format.c @@ -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; } diff --git a/render-hex.c b/render-hex.c index 9148169d..7230f869 100644 --- a/render-hex.c +++ b/render-hex.c @@ -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, "%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;