]> git.neil.brown.name Git - edlib.git/commitdiff
Split doc_attach_view from doc_open.
authorNeilBrown <neil@brown.name>
Wed, 25 Nov 2015 05:31:31 +0000 (16:31 +1100)
committerNeilBrown <neil@brown.name>
Wed, 25 Nov 2015 05:31:31 +0000 (16:31 +1100)
It is silly combining these two functions with very different results.

Signed-off-by: NeilBrown <neil@brown.name>
core-doc.c
core.h
doc-dir.c
mode-emacs.c

index e673acd17494ca4bdc5fe82e30912c6f973f2255..69657863b0382960d5a400d084fa0cb2be5136b1 100644 (file)
@@ -168,8 +168,7 @@ struct pane *doc_new(struct editor *ed, char *type)
        return ci.focus;
 }
 
-struct pane *doc_open(struct editor *ed, struct pane *parent, int fd,
-                     char *name, char *render)
+struct pane *doc_open(struct editor *ed, int fd, char *name)
 {
        struct stat stb;
        struct pane *p;
@@ -183,7 +182,7 @@ struct pane *doc_open(struct editor *ed, struct pane *parent, int fd,
                ci2.extra = -1;
                ci2.str2 = (void*)&stb;
                if (key_handle_focus(&ci2) > 0)
-                       goto found;
+                       return p;
        }
 
        rp = realpath(name, pathbuf);
@@ -196,13 +195,14 @@ struct pane *doc_open(struct editor *ed, struct pane *parent, int fd,
        if (!p)
                return NULL;
        doc_load_file(p, fd, rp);
-found:
-       if (parent) {
-               p = pane_attach(parent, "view", p, NULL);
-               if (p)
-                       render_attach(render, p);
-               return p;
-       }
+       return p;
+}
+
+struct pane *doc_attach_view(struct pane *parent, struct pane *doc, char *render)
+{
+       struct pane *p = pane_attach(parent, "view", doc, NULL);
+       if (p)
+               p = render_attach(render, p);
        return p;
 }
 
diff --git a/core.h b/core.h
index da348f66ed05fddcdc4ce2643945ad4166e3c616..000daa530b923867f469a812f0dc68cbd78eae41 100644 (file)
--- a/core.h
+++ b/core.h
@@ -102,8 +102,8 @@ void doc_del_view(struct doc *d, struct command *c);
 int doc_find_view(struct doc *d, struct command *c);
 struct pane *doc_new(struct editor *ed, char *type);
 struct pane *doc_from_text(struct pane *parent, char *name, char *text);
-struct pane *doc_open(struct editor *ed, struct pane *parent, int fd,
-                     char *name, char *render);
+struct pane *doc_open(struct editor *ed, int fd, char *name);
+struct pane *doc_attach_view(struct pane *parent, struct pane *doc, char *render);
 struct pane *doc_attach(struct pane *parent, struct doc *d);
 void doc_set_name(struct doc *d, char *name);
 struct pane *doc_find(struct editor *ed, char *name);
index 9e1f3b40867dceb55fcd94104502ff74c8d96863..e4cda10b9b61577fa5c75fe1cb76650ccd16e7c3 100644 (file)
--- a/doc-dir.c
+++ b/doc-dir.c
@@ -528,7 +528,9 @@ DEF_CMD(dir_open)
        if (p)
                pane_close(p);
        if (fd >= 0) {
-               p = doc_open(d->ed, par, fd, fname, renderer);
+               p = doc_open(d->ed, fd, fname);
+               if (p)
+                       p = doc_attach_view(par, p, renderer);
                close(fd);
        } else
                p = doc_from_text(par, fname, "File not found\n");
index 5c4f519c7970a638a5285a227e3a2ee4ac8fe526..6008ce5bc393fa8a27f9498f4c5b9214f076625c 100644 (file)
@@ -328,7 +328,9 @@ DEF_CMD(emacs_findfile)
 
        fd = open(ci->str, O_RDONLY);
        if (fd >= 0) {
-               p = doc_open(pane2ed(par), par, fd, ci->str, NULL);
+               p = doc_open(pane2ed(par), fd, ci->str);
+               if (p)
+                       doc_attach_view(par, p, NULL);
                close(fd);
        } else
                p = doc_from_text(par, ci->str, "File not found\n");
@@ -367,7 +369,7 @@ DEF_CMD(emacs_file_complete)
                free(str);
                return -1;
        }
-       docp = doc_open(doc->ed, NULL, fd, d, NULL);
+       docp = doc_open(doc->ed, fd, d);
        close(fd);
        pop = pane_attach(ci->focus, "popup", docp, "DM1");
        ptp = pane_point(pane_final_child(pop));