]> git.neil.brown.name Git - edlib.git/commitdiff
Remove doc->self link.
authorNeilBrown <neil@brown.name>
Thu, 14 Sep 2023 08:11:47 +0000 (18:11 +1000)
committerNeilBrown <neil@brown.name>
Fri, 15 Sep 2023 03:38:14 +0000 (13:38 +1000)
Now that doc is always embedded in the pane, we don't need the ->self
link.
So all uses of a generic doc need to use ->doc to find the doc.

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core-mark.c
core.h
doc-docs.c
doc-text.c
lang-python.c

index 36ba723e874a0a8ed7f9798e73b1f5c765f80f12..a27f03d2740ae0f2a9bcaa82f3d0114f396ca0fb 100644 (file)
@@ -53,7 +53,6 @@ static struct pane *doc_attach_assign(struct pane *parent safe, struct pane *doc
 
 static void doc_init(struct doc *d safe)
 {
-       d->self = d;
        INIT_HLIST_HEAD(&d->marks);
        INIT_TLIST_HEAD(&d->points, 0);
        d->views = NULL;
@@ -495,7 +494,7 @@ DEF_CMD(doc_page)
 
 DEF_CMD(doc_set)
 {
-       struct doc *d = ci->home->_data;
+       struct doc *d = &ci->home->doc;
        const char *val = ksuffix(ci, "doc:set:");
 
        if (!*val)
@@ -553,7 +552,7 @@ DEF_CMD(doc_append)
 
 DEF_CMD(doc_get_attr)
 {
-       struct doc *d = ci->home->_data;
+       struct doc *d = &ci->home->doc;
        char pathbuf[PATH_MAX];
        char *a;
 
@@ -622,7 +621,7 @@ DEF_CMD(doc_doc_get_attr)
 
 DEF_CMD(doc_set_name)
 {
-       struct doc *d = ci->home->_data;
+       struct doc *d = &ci->home->doc;
 
        if (!ci->str)
                return Enoarg;
@@ -694,14 +693,14 @@ static int do_del_view(struct doc *d safe, int v,
 
 DEF_CMD(doc_delview)
 {
-       struct doc *d = ci->home->_data;
+       struct doc *d = &ci->home->doc;
 
        return do_del_view(d, ci->num, ci->focus);
 }
 
 DEF_CMD(doc_addview)
 {
-       struct doc *d = ci->home->_data;
+       struct doc *d = &ci->home->doc;
        struct docview *g;
        int ret;
        int i;
@@ -737,7 +736,7 @@ DEF_CMD(doc_addview)
 
 DEF_CMD_CLOSED(doc_close_doc)
 {
-       struct doc *d = ci->home->_data;
+       struct doc *d = &ci->home->doc;
        doc_free(d, ci->home);
        return 1;
 }
@@ -747,7 +746,7 @@ DEF_CMD_CLOSED(doc_view_close)
        /* A pane which once held a view is closing.  We must discard
         * that view if it still exists.
         */
-       struct doc *d = ci->home->_data;
+       struct doc *d = &ci->home->doc;
        int v;
 
        for (v = 0 ; d->views && v < d->nviews; v++)
@@ -758,8 +757,8 @@ DEF_CMD_CLOSED(doc_view_close)
 DEF_CMD(doc_vmarkget)
 {
        struct mark *m, *m2;
-       m = do_vmark_first(ci->home->_data, ci->num, ci->focus);
-       m2 = do_vmark_last(ci->home->_data, ci->num, ci->focus);
+       m = do_vmark_first(&ci->home->doc, ci->num, ci->focus);
+       m2 = do_vmark_last(&ci->home->doc, ci->num, ci->focus);
        return comm_call(ci->comm2, "callback:vmark", ci->focus,
                         0, m, NULL, 0, m2) ?: 1;
 }
@@ -768,7 +767,7 @@ DEF_CMD(doc_vmarkprev)
 {
        struct mark *m = NULL;
        if (ci->mark)
-               m = do_vmark_at_or_before(ci->home->_data, ci->mark,
+               m = do_vmark_at_or_before(&ci->home->doc, ci->mark,
                                           ci->num, ci->focus);
        comm_call(ci->comm2, "callback:vmark", ci->focus, 0, m);
        return 1;
@@ -786,7 +785,7 @@ DEF_CMD(doc_vmarknew)
 DEF_CMD(doc_drop_cache)
 {
        struct pane *p = ci->home;
-       struct doc *d = p->_data;
+       struct doc *d = &p->doc;
 
        if (d->autoclose)
                pane_close(p);
@@ -1173,7 +1172,7 @@ DEF_CMD_CLOSED(doc_pass_on)
 
 DEF_CMD(doc_push_point)
 {
-       struct doc *d = ci->home->_data;
+       struct doc *d = &ci->home->doc;
        int n = ARRAY_SIZE(d->recent_points);
        struct mark *m;
        if (!ci->mark)
@@ -1190,7 +1189,7 @@ DEF_CMD(doc_push_point)
 
 DEF_CMD(doc_pop_point)
 {
-       struct doc *d = ci->home->_data;
+       struct doc *d = &ci->home->doc;
        int n = ARRAY_SIZE(d->recent_points);
 
        if (!ci->mark)
index 7f4d8e2b52e5acc7a140437c1904d9843ae60e40..a5f7dd96a77c32ed8a2ec565a7540eaa70c4f827 100644 (file)
@@ -63,7 +63,9 @@
 #include <stdlib.h>
 #include <memory.h>
 
+#define DOC_DATA_TYPE struct doc
 #include "core.h"
+#include "core-pane.h"
 #include "internal.h"
 #include "misc.h"
 
@@ -175,7 +177,7 @@ void do_mark_free(struct mark *m)
 
 static void mark_refcnt(struct mark *m safe, int inc)
 {
-       struct doc *d = m->owner->data;
+       struct doc *d = &m->owner->doc;
 
        if (d->refcnt)
                d->refcnt(m, inc);
@@ -382,7 +384,7 @@ struct mark *safe mark_dup_view(struct mark *m safe)
 /* if 'end', move mark after all other marks, else move before all others */
 void mark_to_end(struct pane *p safe, struct mark *m safe, int end)
 {
-       struct doc *d = p->data;
+       struct doc *d = &p->doc;
        unsigned int i;
        struct point_links *lnk;
 
@@ -479,7 +481,7 @@ struct mark *doc_new_mark(struct pane *p safe, int view, struct pane *owner)
 {
        /* FIXME view is >= -1 */
        struct mark *ret;
-       struct doc *d = p->data;
+       struct doc *d = &p->doc;
 
        if (view >= d->nviews ||
            view < MARK_UNGROUPED ||
@@ -541,7 +543,7 @@ wint_t do_doc_step(struct pane *p safe, struct mark *m,
 
        if (m && dodebug && count++ >= dodebug) {
                count = 0;
-               doc_check_consistent(m->owner->data);
+               doc_check_consistent(&m->owner->doc);
        }
 
        if (move)
@@ -1086,7 +1088,7 @@ struct mark *do_vmark_at_or_before(struct doc *d safe,
        if (!mark_valid(m))
                return NULL;
 
-       if (m->owner->data != d) {
+       if (&m->owner->doc != d) {
                LOG("vmark_at_or_before called with incorrect mark");
                return NULL;
        }
@@ -1205,7 +1207,7 @@ void doc_check_consistent(struct doc *d safe)
 
        hlist_for_each_entry(m, &d->marks, all) {
                ASSERT(m->seq >= seq);
-               ASSERT(m->owner->data == d);
+               ASSERT(&m->owner->doc == d);
                seq = m->seq + 1;
                if (m2 && !marks_validate(m2, m) && !warned) {
                        LOG_BT();
@@ -1251,7 +1253,7 @@ void doc_check_consistent(struct doc *d safe)
 bool marks_validate(struct mark *m1 safe, struct mark *m2 safe)
 {
        struct mark *m;
-       struct doc *d = m1->owner->data;
+       struct doc *d = &m1->owner->doc;
        int found = 0;
        int ret;
        int max = 1000;
diff --git a/core.h b/core.h
index 9cfccb97d797c7df0c0022ccfaf9e6ac060f6e1e..d475662b2f29679266ba9d7de55320ed4732b1fa 100644 (file)
--- a/core.h
+++ b/core.h
@@ -124,12 +124,6 @@ bool edlib_testing(struct pane *p safe);
 void edlib_init(struct pane *ed safe);
 
 struct doc {
-       /* This pointer always points to itelf. It allows
-        * a pane to have a pointer to a doc, or an embedded doc,
-        * and following the pointer at that location will always
-        * lead to the doc.
-        */
-       struct doc              *self;
        struct hlist_head       marks;
        struct tlist_head       points;
        struct docview {
index 74fa73bac2792c4777cd9916c9f560ac499b2abd..483988ffcdf89c2dc048fab73afddd2864754d2c 100644 (file)
@@ -145,7 +145,7 @@ static bool doc_save(struct pane *p safe, struct pane *focus safe, int test)
 
 static void check_name(struct docs *docs safe, struct pane *pane safe)
 {
-       struct doc *d = pane->data;
+       struct doc *d = &pane->doc;
        char *nname;
        int unique = 1;
        int conflict = 1;
@@ -162,7 +162,7 @@ static void check_name(struct docs *docs safe, struct pane *pane safe)
                else
                        strcpy(nname, d->name);
                list_for_each_entry(p, &docs->collection->children, siblings) {
-                       struct doc *d2 = p->data;
+                       struct doc *d2 = &p->doc;
                        if (d != d2 && d2->name &&
                            strcmp(nname, d2->name) == 0) {
                                conflict = 1;
@@ -277,7 +277,7 @@ DEF_CMD(docs_callback_byname)
                return comm_call(ci->comm2, "callback:doc",
                                 ci->home);
        list_for_each_entry(p, &doc->collection->children, siblings) {
-               struct doc *dc = p->data;
+               struct doc *dc = &p->doc;
                char *n = dc->name;
                if (n && strcmp(ci->str, n) == 0)
                        return comm_call(ci->comm2, "callback:doc", p);
@@ -323,7 +323,7 @@ DEF_CMD(docs_callback_choose)
         */
 
        list_for_each_entry(p, &doc->collection->children, siblings) {
-               struct doc *d = p->data;
+               struct doc *d = &p->doc;
 
                if (p->damaged & DAMAGED_CLOSED)
                        continue;
index 46c3c3488954234ad4230ea9513dd7020841c6ec..b8d446168a9b75464a27e7464786c9a2e2f7c44d 100644 (file)
@@ -252,10 +252,9 @@ static bool check_file_changed(struct pane *p safe)
 
 DEF_CMD(text_readonly)
 {
-       struct doc *d = ci->home->data;
        struct text *t = ci->home->doc_data;
 
-       if (t->file_changed && !d->readonly && ci->num)
+       if (t->file_changed && !t->doc.readonly && ci->num)
                t->file_changed = 2;
        /* Use default handling */
        return Efallthrough;
@@ -639,7 +638,7 @@ static void do_text_autosave(struct pane *p safe)
 DEF_CMD(text_autosave_delete)
 {
        struct pane *home = ci->home;
-       struct text *t = home->data;
+       struct text *t = home->doc_data;
        const char *name = ci->str;
        int ret = 1;
 
@@ -661,7 +660,7 @@ DEF_CMD(text_autosave_delete)
 DEF_CMD(text_autosave_tick)
 {
        struct pane *home = ci->home;
-       struct text *t = home->data;
+       struct text *t = home->doc_data;
 
        t->as.timer_started = 0;
        if (!t->fname)
@@ -701,14 +700,13 @@ static void text_check_autosave(struct pane *p safe)
 
 DEF_CMD(text_save_file)
 {
-       struct doc *d = ci->home->data;
        struct text *t = ci->home->doc_data;
        int ret;
        char *msg;
        int change_status = 0;
 
        if (!t->fname) {
-               asprintf(&msg, "** No file name known for %s ***", d->name);
+               asprintf(&msg, "** No file name known for %s ***", t->doc.name);
                ret = Efail;
        } else {
                ret = do_text_write_file(ci->home, NULL, NULL, t->fname);
@@ -1309,16 +1307,15 @@ static void text_redo(struct text *t safe, struct text_edit *e safe,
 
 static bool check_readonly(const struct cmd_info *ci safe)
 {
-       struct doc *d = ci->home->data;
        struct text *t = ci->home->doc_data;
 
        if (t->undo == t->saved &&
            check_file_changed(ci->home) &&
-           !d->readonly) {
+           !t->doc.readonly) {
                call("doc:notify:doc:status-changed", ci->home);
-               d->readonly = 1;
+               t->doc.readonly = 1;
        }
-       if (!d->readonly)
+       if (!t->doc.readonly)
                return False;
        call("Message", ci->focus, 0, NULL, "Document is read-only");
        return True;
index 4ee9c32839e5bd0111d6fa45eaa05b000becec80..06e93c944581b9d364e2dd67b136b06b2de5afcd 100644 (file)
@@ -1895,7 +1895,7 @@ static PyObject *mark_getoffset(Mark *m safe, void *x)
                PyErr_SetString(PyExc_TypeError, "Mark is NULL");
                return NULL;
        }
-       d = m->mark->owner->data;
+       d = &m->mark->owner->doc;
        if (d->refcnt == mark_refcnt)
                return PyLong_FromLong(m->mark->ref.o);
        return PyLong_FromLong(0);
@@ -1913,7 +1913,7 @@ static int mark_setoffset(Mark *m safe, PyObject *v safe, void *x)
        val = PyLong_AsLong(v);
        if (val == -1 && PyErr_Occurred())
                return -1;
-       d = m->mark->owner->data;
+       d = &m->mark->owner->doc;
        if (d->refcnt == mark_refcnt)
                m->mark->ref.o = val;
        else {
@@ -1959,7 +1959,7 @@ static PyObject *mark_getpos(Mark *m safe, void *x)
                PyErr_SetString(PyExc_TypeError, "Mark is NULL");
                return NULL;
        }
-       d = m->mark->owner->data;
+       d = &m->mark->owner->doc;
        if (d->refcnt == mark_refcnt && m->mark->ref.c) {
                Py_INCREF(m->mark->ref.c);
                return m->mark->ref.c;
@@ -1978,7 +1978,7 @@ static int mark_setpos(Mark *m safe, PyObject *v, void *x)
                PyErr_SetString(PyExc_TypeError, "Mark is NULL");
                return -1;
        }
-       d = m->mark->owner->data;
+       d = &m->mark->owner->doc;
        if (d->refcnt != mark_refcnt) {
                PyErr_SetString(PyExc_TypeError, "Cannot set ref for non-local mark");
                return -1;
@@ -1990,12 +1990,12 @@ static int mark_setpos(Mark *m safe, PyObject *v, void *x)
         * use that instead, so that mark_same() works.
         */
        if ((m2 = mark_next(m->mark)) != NULL &&
-           ((struct doc *safe)m2->owner->data)->refcnt == mark_refcnt &&
+           m2->owner->doc.refcnt == mark_refcnt &&
            m2->ref.c != NULL && v != NULL &&
            PyObject_RichCompareBool(v, m2->ref.c, Py_EQ) == 1)
                m->mark->ref.c = m2->ref.c;
        else if ((m2 = mark_prev(m->mark)) != NULL &&
-                ((struct doc *safe)m2->owner->data)->refcnt == mark_refcnt &&
+                m2->owner->doc.refcnt == mark_refcnt &&
                 m2->ref.c != NULL && v != NULL &&
                 PyObject_RichCompareBool(v, m2->ref.c, Py_EQ) == 1)
                m->mark->ref.c = m2->ref.c;