From: NeilBrown Date: Thu, 10 Dec 2015 01:29:34 +0000 (+1100) Subject: Rationalise prev/next mark function. X-Git-Tag: lca2016~83 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=4bba81f8fa9403e7de3601b1dcb3867d786a39d1;p=edlib.git Rationalise prev/next mark function. - don't need the 'safe' version any more - don't need to pass 'doc'. - consistent names: doc_{prev,next}_mark_{all,view} Signed-off-by: NeilBrown --- diff --git a/core-mark.c b/core-mark.c index 9479bbc7..45a583b2 100644 --- a/core-mark.c +++ b/core-mark.c @@ -343,7 +343,7 @@ void mark_reset(struct doc *d, struct mark *m) __mark_reset(d, m, 0, 0); } -struct mark *doc_next_mark(struct mark *m) +struct mark *doc_next_mark_view(struct mark *m) { struct tlist_head *tl = &m->view; @@ -353,7 +353,7 @@ struct mark *doc_next_mark(struct mark *m) return NULL; } -struct mark *doc_prev_mark(struct mark *m) +struct mark *doc_prev_mark_view(struct mark *m) { struct tlist_head *tl = &m->view; @@ -377,20 +377,13 @@ struct mark *doc_next_mark_all(struct mark *m) return NULL; } -struct mark *doc_prev_mark_all_safe(struct doc *d, struct mark *m) +struct mark *doc_prev_mark_all(struct mark *m) { if (!HLIST_IS_HEAD(m->all.pprev)) return hlist_prev_entry(m, all); return NULL; } -struct mark *doc_prev_mark_all(struct mark *m) -{ - /* Must never be called on first mark */ - return hlist_prev_entry(m, all); -} - - struct mark *doc_new_mark(struct doc *d, int view) { struct mark *ret; @@ -419,19 +412,6 @@ struct mark *doc_new_mark(struct doc *d, int view) * */ -static struct mark *next_mark(struct mark *m) -{ - if (m->all.next == NULL) - return NULL; - return hlist_next_entry(m, all); -} -static struct mark *prev_mark(struct doc *d, struct mark *m) -{ - if (HLIST_IS_HEAD(m->all.pprev)) - return NULL; - return hlist_prev_entry(m, all); -} - static void swap_lists(struct mark *p1, struct mark *p2) { struct point_links *tmp; @@ -533,7 +513,7 @@ wint_t mark_next(struct doc *d, struct mark *m) wint_t ret; struct mark *m2 = NULL; - while ((m2 = next_mark(m)) != NULL && + while ((m2 = doc_next_mark_all(m)) != NULL && mark_same(d, m, m2)) mark_forward_over(m, m2); @@ -542,7 +522,7 @@ wint_t mark_next(struct doc *d, struct mark *m) return ret; /* FIXME do I need to do this - is it precise enough? */ - while ((m2 = next_mark(m)) != NULL && + while ((m2 = doc_next_mark_all(m)) != NULL && mark_same(d, m, m2)) mark_forward_over(m, m2); return ret; @@ -553,14 +533,14 @@ wint_t mark_prev(struct doc *d, struct mark *m) wint_t ret; struct mark *mp = NULL; - while ((mp = prev_mark(d, m)) != NULL && + while ((mp = doc_prev_mark_all(m)) != NULL && mark_same(d, m, mp)) mark_backward_over(m, mp); ret = mark_step2(d, m, 0, 1); if (ret == WEOF) return ret; - while ((mp = prev_mark(d, m)) != NULL && + while ((mp = doc_prev_mark_all(m)) != NULL && mark_same(d, m, mp)) mark_backward_over(m, mp); return ret; diff --git a/core.h b/core.h index d4ebf74d..61a01441 100644 --- a/core.h +++ b/core.h @@ -157,9 +157,8 @@ struct mark *doc_new_mark(struct doc *d, int view); struct mark *doc_first_mark_all(struct doc *d); struct mark *doc_next_mark_all(struct mark *m); struct mark *doc_prev_mark_all(struct mark *m); -struct mark *doc_prev_mark_all_safe(struct doc *d, struct mark *m); -struct mark *doc_next_mark(struct mark *m); -struct mark *doc_prev_mark(struct mark *m); +struct mark *doc_next_mark_view(struct mark *m); +struct mark *doc_prev_mark_view(struct mark *m); void point_reset(struct mark *p); void mark_reset(struct doc *d, struct mark *m); void __mark_reset(struct doc *d, struct mark *m, int new, int end); diff --git a/doc-text.c b/doc-text.c index 460aa1e8..59a1fe3c 100644 --- a/doc-text.c +++ b/doc-text.c @@ -844,7 +844,7 @@ DEF_CMD(text_reundo) i = text_retreat_towards(t, &m->ref, &end); if (i == 0) break; - while ((m2 = doc_prev_mark_all_safe(&t->doc, m)) != NULL && + while ((m2 = doc_prev_mark_all(m)) != NULL && m2->ref.c == m->ref.c && m2->ref.o >= m->ref.o) mark_backward_over(m, m2); @@ -867,7 +867,7 @@ DEF_CMD(text_reundo) &start, &end) == 0) break; - early = doc_prev_mark_all_safe(&t->doc, m); + early = doc_prev_mark_all(m); if (early && !text_ref_same(t, &early->ref, &start)) early = NULL; @@ -1400,9 +1400,9 @@ DEF_CMD(text_replace) mark_free(myend); text_del(t, &pm->ref, l, &first); - for (m = doc_prev_mark_all_safe(&t->doc, pm); + for (m = doc_prev_mark_all(pm); m && text_update_prior_after_change(t, &m->ref, &pm->ref, &pm->ref); - m = doc_prev_mark_all_safe(&t->doc, m)) + m = doc_prev_mark_all(m)) ; for (m = doc_next_mark_all(pm); m && text_update_following_after_change(t, &m->ref, &pm->ref, &pm->ref); @@ -1410,7 +1410,7 @@ DEF_CMD(text_replace) ; text_check_consistent(t); } - early = doc_prev_mark_all_safe(&t->doc, pm); + early = doc_prev_mark_all(pm); if (early && !mark_same(&t->doc, early, pm)) early = NULL; @@ -1419,9 +1419,9 @@ DEF_CMD(text_replace) struct mark *m; text_add_str(t, &pm->ref, str, &start, &first); - for (m = doc_prev_mark_all_safe(&t->doc, pm); + for (m = doc_prev_mark_all(pm); m && text_update_prior_after_change(t, &m->ref, &start, &pm->ref); - m = doc_prev_mark_all_safe(&t->doc, m)) + m = doc_prev_mark_all(m)) ; for (m = doc_next_mark_all(pm); m && text_update_following_after_change(t, &m->ref, &start, &pm->ref); diff --git a/lib-line-count.c b/lib-line-count.c index 8f7f919c..045c9153 100644 --- a/lib-line-count.c +++ b/lib-line-count.c @@ -110,7 +110,7 @@ static int need_recalc(struct doc *d, struct mark *m) if (!attr_find(*mark_attr(m), "lines")) ret = 1; while (1) { - next = doc_next_mark(m); + next = doc_next_mark_view(m); if (!next) break; if (doc_prior(d, next) == '\n' && @@ -154,9 +154,9 @@ static void count_calculate(struct doc *d, struct mark *start, struct mark *end) /* Force and update to make sure spacing stays sensible */ if (need_recalc(d, m)) /* need to update this one */ - do_count(d, m, doc_next_mark(m), &l, &w, &c, 1); + do_count(d, m, doc_next_mark_view(m), &l, &w, &c, 1); - m = doc_next_mark(m); + m = doc_next_mark_view(m); } if (!m) { /* fell off the end, just count directly */ @@ -166,7 +166,7 @@ static void count_calculate(struct doc *d, struct mark *start, struct mark *end) } if (need_recalc(d, m)) /* need to update this one */ - do_count(d, m, doc_next_mark(m), &l, &w, &c, 1); + do_count(d, m, doc_next_mark_view(m), &l, &w, &c, 1); /* 'm' is not before 'start', it might be after. * if 'm' is not before 'end' either, just count from @@ -185,7 +185,7 @@ static void count_calculate(struct doc *d, struct mark *start, struct mark *end) lines = words = chars = 0; else do_count(d, start, m, &lines, &words, &chars, 0); - while ((m2 = doc_next_mark(m)) != NULL && + while ((m2 = doc_next_mark_view(m)) != NULL && (!end || mark_ordered(m2, end))) { /* Need everything from m to m2 */ lines += attr_find_int(*mark_attr(m), "lines"); @@ -193,7 +193,7 @@ static void count_calculate(struct doc *d, struct mark *start, struct mark *end) chars += attr_find_int(*mark_attr(m), "chars"); m = m2; if (need_recalc(d, m)) - do_count(d, m, doc_next_mark(m), &l, &w, &c, 1); + do_count(d, m, doc_next_mark_view(m), &l, &w, &c, 1); } /* m is the last mark before end */ if (!end) {