It is silly combining these two functions with very different results.
Signed-off-by: NeilBrown <neil@brown.name>
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;
ci2.extra = -1;
ci2.str2 = (void*)&stb;
if (key_handle_focus(&ci2) > 0)
- goto found;
+ return p;
}
rp = realpath(name, pathbuf);
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;
}
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);
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");
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");
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));