]> git.neil.brown.name Git - edlib.git/commitdiff
Rationalise prev/next mark function.
authorNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 01:29:34 +0000 (12:29 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:54:09 +0000 (13:54 +1100)
- 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 <neil@brown.name>
core-mark.c
core.h
doc-text.c
lib-line-count.c

index 9479bbc71e2cecdfb3a9c0bb5c651696c64f2909..45a583b2f3413007ed5cbb47b8e33bfb10d7ca9b 100644 (file)
@@ -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 d4ebf74db8c07905dd494ec66d8a6b9a0a4e872b..61a01441d4f46d010f5ec84063720c98b7ce138b 100644 (file)
--- 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);
index 460aa1e8925fe97bdca61998261f89e1f3b32785..59a1fe3cd0cdf6d01305ecccf42ef2b805295a1c 100644 (file)
@@ -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);
index 8f7f919cee972fdabf0d040264f52eac22ef717e..045c9153a1b95f1658fbd3e18ada6435e681042e 100644 (file)
@@ -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) {