#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#define PANE_DATA_TYPE struct complete_data
#include "core.h"
#include "misc.h"
struct stk {
struct stk *prev;
const char *substr safe;
- } *stk safe;
+ } *stk;
int prefix_only;
};
+#include "core-pane.h"
static struct map *rc_map;
struct mark *m;
int offset = 0;
- if (!ci->mark)
+ if (!ci->mark || !cd->stk)
return Enoarg;
m = mark_dup(ci->mark);
return ret;
}
-DEF_CMD(complete_free)
+DEF_CMD(complete_close)
{
struct complete_data *cd = ci->home->data;
struct stk *stk = cd->stk;
free((void*)t->substr);
free(t);
}
+ cd->stk = NULL;
free(cd->attr);
- unalloc(cd, pane);
+ cd->attr = NULL;
return 1;
}
struct pane *complete;
struct complete_data *cd;
- alloc(cd, pane);
- complete = pane_register(focus, 0, &complete_handle.c, cd);
- if (!complete) {
- unalloc(cd, pane);
+ complete = pane_register(focus, 0, &complete_handle.c);
+ if (!complete)
return NULL;
- }
+ cd = complete->data;
cd->stk = malloc(sizeof(cd->stk[0]));
cd->stk->prev = NULL;
cd->stk->substr = strdup("");
{
struct complete_data *cd = ci->home->data;
char *np;
- int pl = strlen(cd->stk->substr);
+ int pl;
const char *suffix = ksuffix(ci, "doc:char-");
+ if (!cd->stk)
+ return Efail;
+ pl = strlen(cd->stk->substr);
np = malloc(pl + strlen(suffix) + 1);
strcpy(np, cd->stk->substr);
strcpy(np+pl, suffix);
struct stk *stk = cd->stk;
char *old = NULL;
- if (!stk->prev)
+ if (!stk || !stk->prev)
return 1;
if (stk->substr[0] && !stk->prev->substr[0]) {
old = (void*)stk->substr;
struct stk *stk;
struct mark *m;
+ if (!cd->stk)
+ return Efail;
/* Save a copy of the point so we can restore it if needed */
m = call_ret(mark, "doc:point", ci->focus);
if (m)
rc_map = key_alloc();
key_add(rc_map, "doc:render-line", &render_complete_line);
- key_add(rc_map, "Free", &complete_free);
+ key_add(rc_map, "Close", &complete_close);
key_add(rc_map, "Clone", &complete_clone);
key_add(rc_map, "Replace", &complete_ignore_replace);