From: NeilBrown Date: Thu, 10 Dec 2015 01:49:42 +0000 (+1100) Subject: Introduce mark_next_pane and mark_prev_pane X-Git-Tag: lca2016~82 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=e26026369ffb867914e44a96b27d783ac659dc31;p=edlib.git Introduce mark_next_pane and mark_prev_pane Use these to remove the need for 'doc_from_pane' from search_add. Signed-off-by: NeilBrown --- diff --git a/core-mark.c b/core-mark.c index 45a583b2..d17d2d8c 100644 --- a/core-mark.c +++ b/core-mark.c @@ -501,6 +501,18 @@ wint_t mark_step(struct doc *d, struct mark *m, int forward, int move, struct cm return ret & 0xfffff; } +wint_t mark_step_pane(struct pane *p, struct mark *m, int forward, int move, struct cmd_info *ci) +{ + int ret = call5("doc:step", p, forward, m, NULL, move); + + if (ret <= 0) + return ret; + if (ret >= 0x1fffff) + return WEOF; + else + return ret & 0xfffff; +} + wint_t mark_step2(struct doc *d, struct mark *m, int forward, int move) { struct cmd_info ci = {0}; @@ -528,6 +540,27 @@ wint_t mark_next(struct doc *d, struct mark *m) return ret; } +wint_t mark_next_pane(struct pane *p, struct mark *m) +{ + wint_t ret; + struct mark *m2 = NULL; + struct cmd_info same_ci = {0}; + + while ((m2 = doc_next_mark_all(m)) != NULL && + mark_same_pane(p, m, m2, &same_ci)) + mark_forward_over(m, m2); + + ret = mark_step_pane(p, m, 1, 1, NULL); + if (ret == WEOF) + return ret; + +/* FIXME do I need to do this - is it precise enough? */ + while ((m2 = doc_next_mark_all(m)) != NULL && + mark_same_pane(p, m, m2, &same_ci)) + mark_forward_over(m, m2); + return ret; +} + wint_t mark_prev(struct doc *d, struct mark *m) { wint_t ret; @@ -546,6 +579,25 @@ wint_t mark_prev(struct doc *d, struct mark *m) return ret; } +wint_t mark_prev_pane(struct pane *p, struct mark *m) +{ + wint_t ret; + struct mark *mp = NULL; + struct cmd_info same_ci = {0}; + + while ((mp = doc_prev_mark_all(m)) != NULL && + mark_same_pane(p, m, mp, &same_ci)) + mark_backward_over(m, mp); + + ret = mark_step_pane(p, m, 0, 1, NULL); + if (ret == WEOF) + return ret; + while ((mp = doc_prev_mark_all(m)) != NULL && + mark_same_pane(p, m, mp, &same_ci)) + mark_backward_over(m, mp); + return ret; +} + /* Move the point so it is at the same location as the mark, both in the * text. * Firstly find the point closest to the mark, though that will often diff --git a/core.h b/core.h index 61a01441..7fb05f59 100644 --- a/core.h +++ b/core.h @@ -181,6 +181,8 @@ wint_t mark_step(struct doc *d, struct mark *m, int forward, int move, struct cm wint_t mark_step2(struct doc *d, struct mark *m, int forward, int move); 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); +wint_t mark_prev_pane(struct pane *p, struct mark *m); struct mark *mark_at_point(struct pane *p, struct mark *pm, int view); struct mark *do_mark_at_point(struct doc *d, struct mark *pt, int view); void points_resize(struct doc *d); diff --git a/emacs-search.c b/emacs-search.c index adb6fa7d..6dfb09b9 100644 --- a/emacs-search.c +++ b/emacs-search.c @@ -115,18 +115,15 @@ DEF_CMD(search_retreat) DEF_CMD(search_add) { struct es_info *esi = ci->home->data; - struct doc *d = doc_from_pane(esi->target); wint_t wch; char b[5]; mbstate_t ps = {0}; int l; - if (!d) - return -1; do { /* TEMP HACK - please fix */ doc_set_attr(esi->target, esi->end, "highlight", NULL); - wch = mark_next(d, esi->end); + wch = mark_next_pane(esi->target, esi->end); if (wch == WEOF) return 1; if (wch == '\n') { @@ -134,7 +131,7 @@ DEF_CMD(search_add) /* Sending this will cause a call-back to * close everything down. */ - mark_prev(d, esi->end); + mark_prev_pane(esi->target, esi->end); return 1; } /* FIXME utf-8! and quote regexp chars */