]> git.neil.brown.name Git - edlib.git/commitdiff
doc: make it possible to delete a view by number
authorNeilBrown <neil@brown.name>
Mon, 25 Jan 2016 02:42:13 +0000 (13:42 +1100)
committerNeilBrown <neil@brown.name>
Mon, 25 Jan 2016 02:42:13 +0000 (13:42 +1100)
As we are deprecating the 'notifier', don't depend on it for deletion.

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core.h
lib-line-count.c
render-lines.c

index 0148730a1237371639272c990ea8f42e38fd3bd0..3f0558e1ce18da62e053febe0c2f56517139a8d8 100644 (file)
@@ -69,7 +69,7 @@ static int do_doc_add_view(struct doc *d, struct command *c)
        return ret;
 }
 
-static void do_doc_del_view(struct doc *d, struct command *c)
+static void do_doc_del_view_notifier(struct doc *d, struct command *c)
 {
        /* This view should only have points on the list, not typed
         * marks.  Just delete everything and clear the 'notify' pointer
@@ -90,6 +90,23 @@ static void do_doc_del_view(struct doc *d, struct command *c)
        }
 }
 
+static void do_doc_del_view(struct doc *d, int i)
+{
+       /* This view should only have points on the list, not typed
+        * marks.  Just delete everything and clear the 'notify' pointer
+        */
+       if (i < 0 || i >= d->nviews)
+               return;
+       d->views[i].notify = NULL;
+       d->views[i].state = 0;
+       while (!tlist_empty(&d->views[i].head)) {
+               struct tlist_head *tl = d->views[i].head.next;
+               if (TLIST_TYPE(tl) != GRP_LIST)
+                       abort();
+               tlist_del_init(tl);
+       }
+}
+
 static int do_doc_find_view(struct doc *d, struct command *c)
 {
        int i;
@@ -458,9 +475,12 @@ DEF_CMD(doc_handle)
        }
 
        if (strcmp(ci->key, "doc:del-view") == 0) {
-               if (!ci->comm2)
+               if (ci->numeric >= 0)
+                       do_doc_del_view(dd->doc, ci->numeric);
+               else if (ci->comm2)
+                       do_doc_del_view_notifier(dd->doc, ci->comm2);
+               else
                        return -1;
-               do_doc_del_view(dd->doc, ci->comm2);
                return 1;
        }
 
diff --git a/core.h b/core.h
index e957b9379c203c9baa4da0df1b84f29bed985a03..562717cef2cc0fd813b36656a780c2d32f365ba8 100644 (file)
--- a/core.h
+++ b/core.h
@@ -461,11 +461,21 @@ static inline int doc_add_view(struct pane *p, struct command *c)
        return ret - 1;
 }
 
-static inline void doc_del_view(struct pane *p, struct command *c)
+static inline void doc_del_view(struct pane *p, int num)
 {
        struct cmd_info ci = {0};
        ci.focus = p;
        ci.key = "doc:del-view";
+       ci.numeric = num;
+       key_handle(&ci);
+}
+
+static inline void doc_del_view_notifier(struct pane *p, struct command *c)
+{
+       struct cmd_info ci = {0};
+       ci.focus = p;
+       ci.key = "doc:del-view";
+       ci.numeric = -1;
        ci.comm2 = c;
        key_handle(&ci);
 }
index a2c9654d5b5ea12c9b66b5e0d8e8d53aa825db78..455f067add0a1bc713dd18fdd4ac47f0fd5f3e43 100644 (file)
@@ -96,7 +96,7 @@ DEF_CMD(count_notify)
                        return 0;
                while ((m = vmark_first(ci->home, i)) != NULL)
                        mark_free(m);
-               doc_del_view(ci->home, ci->comm);
+               doc_del_view_notifier(ci->home, ci->comm);
        }
        return 0;
 }
index 78e2392c2c24ba341cf62ae43ba42d0adc3e633a..a885500ae4d5f6bd2d9a1ee93a9cba911ab7366b 100644 (file)
@@ -804,7 +804,7 @@ DEF_CMD(render_lines_close)
        }
 
        rl->pane = NULL;
-       doc_del_view(p, &rl->type);
+       doc_del_view(p, rl->typenum);
        p->data = NULL;
        p->handle = NULL;
        free(rl);