they get send to the document instead of having to find it.
Signed-off-by: NeilBrown <neil@brown.name>
#include "core.h"
-int doc_add_view(struct doc *d, struct command *c)
+static int do_doc_add_view(struct doc *d, struct command *c, int size)
{
struct docview *g;
int ret;
}
points_attach(d, ret);
d->views[ret].space = 0;
+ if (size > 0 && (unsigned)size > sizeof(struct mark))
+ d->views[ret].space = size - sizeof(struct mark);
d->views[ret].notify = c;
d->views[ret].marked = 0;
return ret;
}
-void doc_del_view(struct doc *d, struct command *c)
+static void do_doc_del_view(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
}
}
-int doc_find_view(struct doc *d, struct command *c)
+static int do_doc_find_view(struct doc *d, struct command *c)
{
int i;
for (i = 0 ; i < d->nviews; i++)
return 1;
}
+ if (strcmp(ci->key, "doc:add-view") == 0) {
+ if (!ci->comm2)
+ return -1;
+ ci->extra = do_doc_add_view(d, ci->comm2, ci->extra);
+ return 1;
+ }
+
+ if (strcmp(ci->key, "doc:del-view") == 0) {
+ if (!ci->comm2)
+ return -1;
+ do_doc_del_view(d, ci->comm2);
+ return 1;
+ }
+
+ if (strcmp(ci->key, "doc:find-view") == 0) {
+ if (!ci->comm2)
+ return -1;
+ ci->extra = do_doc_find_view(d, ci->comm2);
+ return 1;
+ }
+
return key_lookup(d->map, ci);
}
};
void doc_init(struct doc *d);
-int doc_add_view(struct doc *d, struct command *c);
-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, int fd, char *name);
char *str, *str2;
struct mark *mark, *mark2;
struct point **pointp;
- struct command *comm;
+ struct command *comm, *comm2;
};
#define NO_NUMERIC (INT_MAX/2)
#define RPT_NUM(ci) ((ci)->numeric == NO_NUMERIC ? 1 : (ci)->numeric)
return key_handle_focus(&ci);
}
+
+static inline int doc_add_view(struct pane *p, struct command *c, int size)
+{
+ struct cmd_info ci = {0};
+ ci.focus = p;
+ ci.key = "doc:add-view";
+ ci.comm2 = c;
+ ci.extra = size;
+ if (key_handle_focus(&ci) == 0)
+ return -1;
+ return ci.extra;
+}
+
+static inline void doc_del_view(struct pane *p, struct command *c)
+{
+ struct cmd_info ci = {0};
+ ci.focus = p;
+ ci.key = "doc:del-view";
+ ci.comm2 = c;
+ key_handle_focus(&ci);
+}
+
+static inline int doc_find_view(struct pane *p, struct command *c)
+{
+ struct cmd_info ci = {0};
+ ci.focus = p;
+ ci.key = "doc:find-view";
+ ci.comm2 = c;
+ if (key_handle_focus(&ci) == 0)
+ return -1;
+ return ci.extra;
+}
+
{
struct es_info *esi = ci->focus->data;
- doc_del_view((*ci->pointp)->doc, &esi->watch);
+ doc_del_view(ci->focus, &esi->watch);
/* TEMP HACK - please fix */
doc_set_attr(esi->end, "highlight", NULL);
point_free(esi->end);
int ret;
if (strcmp(ci->key, "Release") == 0) {
- struct doc *d = ci->home->data;
-
/* No marks to remove */
- doc_del_view(d, ci->comm);
+ doc_del_view(ci->home, ci->comm);
return 0;
}
struct pane *p;
struct es_info *esi;
struct cmd_info ci2 = {0};
- struct point **ptp;
if (!es_map)
emacs_search_init_map();
esi->matched = 0;
esi->search = ci->focus;
esi->watch = search_again;
- ptp = pane_point(ci->focus);
- doc_add_view((*ptp)->doc, &esi->watch);
+ doc_add_view(ci->focus, &esi->watch, 0);
ci->focus = pane_final_child(ci->focus);
p = pane_register(ci->focus, 0, &search_handle.c, esi, NULL);
if (strcmp(ci->key, "Release") == 0) {
struct doc *d = ci->home->data;
struct mark *m;
- int i = doc_find_view(d, ci->comm);
+ int i = doc_find_view(ci->home, ci->comm);
if (i < 0)
return 0;
while ((m = doc_first_mark(d, i)) != NULL)
mark_free(m);
- doc_del_view(d, ci->comm);
+ doc_del_view(ci->home, ci->comm);
}
return 0;
}
static void count_calculate(struct doc *d, struct mark *start, struct mark *end)
{
- int type = doc_find_view(d, &count_notify);
+ int type = doc_find_view(d->home, &count_notify);
int lines, words, chars, l, w, c;
struct mark *m, *m2;
struct attrset **attrs;
if (type < 0)
- type = doc_add_view(d, &count_notify);
+ type = doc_add_view(d->home, &count_notify, 0);
m = doc_first_mark(d, type);
if (m == NULL) {
DEF_CMD(view_handle)
{
struct pane *p = ci->home;
- struct point *pt;
struct view_data *vd = p->data;
int ret;
vd->pane = p; /* FIXME having to do this is horrible */
if (strcmp(ci->key, "Close") == 0) {
- pt = *ci->pointp;
- doc_del_view(pt->doc, &vd->ch_notify);
+ doc_del_view(p, &vd->ch_notify);
free(vd);
return 1;
}
{
struct view_data *vd = par->data;
struct pane *p;
- struct point **ptp = pane_point(par);
- vd->ch_notify_num = doc_add_view((*ptp)->doc, &vd->ch_notify);
+ vd->ch_notify_num = doc_add_view(par, &vd->ch_notify, 0);
p = pane_register(par, 0, &view_null, vd, NULL);
pane_damaged(p, DAMAGED_SIZE);
};
static struct map *dr_map;
-static struct pane *do_render_dir_attach(struct pane *parent, struct point **ptp);
+static struct pane *do_render_dir_attach(struct pane *parent);
static int put_str(struct pane *p, char *buf, char *attrs, int x, int y)
{
struct pane *p = ci->home;
struct dir_data *dd = p->data;
struct mark *end = NULL, *top;
- struct doc *d;
int ret;
ret = key_lookup(dr_map, ci);
if (strcmp(ci->key, "Close") == 0) {
struct pane *p = dd->pane;
- d = (*ci->pointp)->doc;
+
mark_free(dd->top);
mark_free(dd->bot);
dd->pane = NULL;
- doc_del_view(d, &dd->type);
+ doc_del_view(p, &dd->type);
p->data = NULL;
p->handle = NULL;
free(dd);
struct pane *parent = ci->focus;
struct pane *c;
- do_render_dir_attach(parent, NULL);
+ do_render_dir_attach(parent);
c = pane_child(p);
if (c)
return pane_clone(c, parent->focus);
key_add(dr_map, "Chr-g", &render_dir_reload);
}
-static struct pane *do_render_dir_attach(struct pane *parent, struct point **ptp)
+static struct pane *do_render_dir_attach(struct pane *parent)
{
struct dir_data *dd = malloc(sizeof(*dd));
struct pane *p;
if (!dr_map)
render_dir_register_map();
- if (!ptp)
- ptp = pane_point(parent);
- if (!ptp)
- return NULL;
dd->top = NULL;
dd->bot = NULL;
dd->ignore_point = 0;
dd->type = render_dir_notify;
- dd->typenum = doc_add_view((*ptp)->doc, &dd->type);
+ dd->typenum = doc_add_view(parent, &dd->type, 0);
p = pane_register(parent, 0, &render_dir_handle, dd, NULL);
dd->pane = p;
dd->header = 0;
DEF_CMD(render_dir_attach)
{
- ci->focus = do_render_dir_attach(ci->focus, ci->pointp);
+ ci->focus = do_render_dir_attach(ci->focus);
return 1;
}
};
static struct map *he_map;
-static struct pane *do_render_hex_attach(struct pane *parent, struct point **ptp);
+static struct pane *do_render_hex_attach(struct pane *parent);
DEF_CMD(render_hex_handle)
{
struct pane *p = ci->home;
struct he_data *he = p->data;
- struct doc *d;
int ret;
ret = key_lookup(he_map, ci);
if (strcmp(ci->key, "Close") == 0) {
struct pane *p = he->pane;
- d = (*ci->pointp)->doc;
he->pane = NULL;
- doc_del_view(d, &he->type);
+ doc_del_view(p, &he->type);
p->data = NULL;
p->handle = NULL;
free(he);
struct pane *parent = ci->focus;
struct pane *c;
- do_render_hex_attach(parent, NULL);
+ do_render_hex_attach(parent);
c = pane_child(p);
if (c)
return pane_clone(c, parent->focus);
key_add(he_map, "render-line", &render_line);
}
-static struct pane *do_render_hex_attach(struct pane *parent, struct point **ptp)
+static struct pane *do_render_hex_attach(struct pane *parent)
{
struct he_data *he = malloc(sizeof(*he));
struct pane *p;
if (!he_map)
render_hex_register_map();
- if (!ptp)
- ptp = pane_point(parent);
- if (!ptp)
- return NULL;
-
he->type = render_hex_notify;
- he->typenum = doc_add_view((*ptp)->doc, &he->type);
+ he->typenum = doc_add_view(parent, &he->type, 0);
p = pane_register(parent, 0, &render_hex_handle, he, NULL);
attr_set_str(&p->attrs, "render-wrap", "no", -1);
attr_set_str(&p->attrs, "heading", "<bold> 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0 1 2 3 4 5 6 7 8 9 a b c d e f</>", -1);
DEF_CMD(render_hex_attach)
{
- ci->focus = do_render_hex_attach(ci->focus, ci->pointp);
+ ci->focus = do_render_hex_attach(ci->focus);
return 1;
}
}
rl->pane = NULL;
- doc_del_view(d, &rl->type);
+ doc_del_view(p, &rl->type);
p->data = NULL;
p->handle = NULL;
free(rl);
REDEF_CMD(render_lines_attach)
{
struct rl_data *rl = malloc(sizeof(*rl));
- struct point **ptp;
if (!rl_map)
render_lines_register_map();
- ptp = ci->pointp;
- if (!ptp)
- return -1;
-
rl->ignore_point = 0;
rl->top_sol = 0;
rl->skip_lines = 0;
rl->shift_left = 0;
rl->header_lines = 0;
rl->type = render_lines_notify;
- rl->typenum = doc_add_view((*ptp)->doc, &rl->type);
- (*ptp)->doc->views[rl->typenum].space =
- sizeof(struct rl_mark) - sizeof(struct mark);
+ rl->typenum = doc_add_view(ci->focus, &rl->type, sizeof(struct rl_mark));
rl->pane = pane_register(ci->focus, 0, &render_lines_handle.c, rl, NULL);
ci->focus = rl->pane;
};
static struct map *rt_map;
-static struct pane *do_render_text_attach(struct pane *p, struct point **pt);
+static struct pane *do_render_text_attach(struct pane *p);
static int rt_fore(struct doc *d, struct pane *p, struct mark *m, int *x, int *y, int draw)
{
{
struct pane *p = ci->home;
struct rt_data *rt = p->data;
- struct doc *d;
int ret;
ret = key_lookup(rt_map, ci);
if (strcmp(ci->key, "Close") == 0) {
struct pane *p = rt->pane;
- d = (*ci->pointp)->doc;
mark_free(rt->top);
mark_free(rt->bot);
rt->pane = NULL;
- doc_del_view(d, &rt->type);
+ doc_del_view(p, &rt->type);
p->data = NULL;
p->handle = NULL;
free(rt);
struct pane *parent = ci->focus;
struct pane *c;
- do_render_text_attach(parent, NULL);
+ do_render_text_attach(parent);
c = pane_child(p);
if (c)
return pane_clone(c, parent->focus);
key_add(rt_map, "Replace", &render_text_follow_point);
}
-static struct pane *do_render_text_attach(struct pane *parent, struct point **ptp)
+static struct pane *do_render_text_attach(struct pane *parent)
{
struct rt_data *rt = malloc(sizeof(*rt));
struct pane *p;
if (!rt_map)
render_text_register_map();
- if (!ptp)
- ptp = pane_point(parent);
- if (!ptp)
- return NULL;
rt->top = NULL;
rt->bot = NULL;
rt->ignore_point = 0;
rt->target_x = -1;
rt->type = render_text_notify;
- rt->typenum = doc_add_view((*ptp)->doc, &rt->type);
+ rt->typenum = doc_add_view(parent, &rt->type, 0);
p = pane_register(parent, 0, &render_text_handle, rt, NULL);
rt->pane = p;
return p;
DEF_CMD(render_text_attach)
{
- ci->focus = do_render_text_attach(ci->focus, ci->pointp);
+ ci->focus = do_render_text_attach(ci->focus);
return 1;
}