return ' ';
}
-static char *docs_getstr(struct doc *d, struct mark *from, struct mark *to)
-{
- return NULL;
-}
-
static void docs_setref(struct doc *doc, struct mark *m, bool start)
{
.replace = docs_replace,
.reundo = docs_reundo,
.step = docs_step,
- .get_str = docs_getstr,
.set_ref = docs_setref,
.same_ref = docs_sameref,
.get_attr = docs_get_attr,
char *str, bool *first);
int (*reundo)(struct point *pos, bool undo);
wint_t (*step)(struct doc *d, struct mark *m, bool forward, bool move);
- char *(*get_str)(struct doc *d, struct mark *from, struct mark *to);
void (*set_ref)(struct doc *d, struct mark *m, bool start);
int (*same_ref)(struct doc *d, struct mark *a, struct mark *b);
/* get/set attr operate on the attributes of the char immediately
ci.key = "doc:load-file";
return key_lookup(d->map, &ci);
}
-static inline char *doc_getstr(struct doc *d, struct mark *from, struct mark *to)
+static inline char *doc_getstr(struct point *from, struct mark *to)
{
- return d->ops->get_str(d, from, to);
+ struct cmd_info ci = {0};
+ struct doc *d = from->doc;
+ int ret;
+
+ ci.key = "doc:get-str";
+ ci.pointp = &from;
+ ci.mark = to;
+ ret = key_lookup(d->map, &ci);
+ if (!ret)
+ return NULL;
+ return ci.str;
}
+
static inline char *doc_attr(struct doc *d, struct mark *m, bool forward, char *attr)
{
return d->ops->get_attr(d, m, forward, attr);
return ret;
}
-static char *dir_getstr(struct doc *d, struct mark *from, struct mark *to)
-{
- return NULL;
-}
-
static void dir_setref(struct doc *doc, struct mark *m, bool start)
{
struct directory *dr = container_of(doc, struct directory, doc);
.replace = dir_replace,
.reundo = dir_reundo,
.step = dir_step,
- .get_str = dir_getstr,
.set_ref = dir_setref,
.same_ref = dir_sameref,
.get_attr = dir_get_attr,
return l;
}
-static char *text_getstr(struct doc *d, struct mark *from, struct mark *to)
+DEF_CMD(text_get_str)
{
+ struct point *pt = *ci->pointp;
+ struct doc *d = pt->doc;
+ struct mark *from = NULL, *to = NULL;
struct text *t = container_of(d, struct text, doc);
struct text_chunk *c, *first, *last;
char *ret;
int l = 0, head, tail;
+ if (ci->mark) {
+ if (mark_ordered(&pt->m, ci->mark)) {
+ from = &pt->m;
+ to = ci->mark;
+ } else {
+ from = ci->mark;
+ to = &pt->m;
+ }
+ }
+
first = list_first_entry_or_null(&t->text, struct text_chunk, lst);
head = 0;
if (from && from->ref.c) {
break;
}
ret[l] = 0;
- return ret;
+ ci->str = ret;
+ return 1;
}
static void text_setref(struct doc *d, struct mark *m, bool start)
.replace = text_replace,
.reundo = text_reundo,
.step = text_step,
- .get_str = text_getstr,
.set_ref = text_setref,
.same_ref = text_sameref,
.get_attr = text_get_attr,
key_add(text_map, "doc:load-file", &text_load_file);
key_add(text_map, "doc:same-file", &text_same_file);
+ key_add(text_map, "doc:get-str", &text_get_str);
}
}
s = malloc(sizeof(*s));
s->m = esi->start;
- str = doc_getstr((*ci->pointp)->doc, NULL, NULL);
+ str = doc_getstr(*ci->pointp, NULL);
s->len = strlen(str);
free(str);
s->next = esi->s;
if (esi->s == NULL)
return 0;
- str = doc_getstr((*ci->pointp)->doc, NULL, NULL);
+ str = doc_getstr(*ci->pointp, NULL);
if (strlen(str) > esi->s->len) {
free(str);
return 0;
d->ops->set_attr(esi->end, "highlight", NULL);
ci2.pointp = &esi->end;
ci2.mark = mark_dup(esi->start, 1);
- ci2.str = doc_getstr((*ci->pointp)->doc, NULL, NULL);
+ ci2.str = doc_getstr(*ci->pointp, NULL);
ci2.key = "text-search";
ret = key_lookup(pane2ed(esi->target)->commands, &ci2);
if (ret == 0)
struct popup_info {
struct pane *target, *popup;
- struct doc *doc;
+ struct point *point;
char *style;
};
struct popup_info *ppi = p->data;
if (strcmp(ci->key, "Close") == 0) {
- if (ppi->doc)
- doc_destroy(ppi->doc);
+ if (ppi->point)
+ doc_destroy(ppi->point->doc);
free(ppi);
return 1;
}
ci2.key = "PopupDone";
ci2.numeric = 1;
ci2.str = ci->str;
- if (ppi->doc)
- ci2.str = doc_getstr(ppi->doc, NULL, NULL);
+ if (ppi->point)
+ ci2.str = doc_getstr(ppi->point, NULL);
ci2.mark = NULL;
key_handle_focus(&ci2);
- if (ppi->doc)
+ if (ppi->point)
free(ci2.str);
pane_close(ppi->popup);
return 1;
ppi->target = ci->focus;
ppi->popup = pane_register(root, z, &popup_handle, ppi, NULL);
ppi->style = style;
- ppi->doc = NULL;
+ ppi->point = NULL;
popup_resize(ppi->popup, style);
for (i = 0, j = 0; i < 4; i++) {
if (strchr(style, "TLBR"[i]) == NULL)
attr_set_str(&ppi->popup->attrs, "render-wrap", "no", -1);
if (ci->pointp) {
- pt = *ci->pointp;
+ p = pane_attach(ppi->popup, "view", *ci->pointp, NULL);
} else {
pt = doc_new(pane2ed(root), "text");
doc_set_name(pt->doc, "*popup*");
- ppi->doc = pt->doc;
+ p = pane_attach(ppi->popup, "view", pt, NULL);
+ point_new(pt->doc, &ppi->point);
}
- p = pane_attach(ppi->popup, "view", pt, NULL);
render_attach(NULL, p);
pane_focus(p);
ci2.key = "local-set-key";
* popup menu
*/
struct doc *doc = (*ci->pointp)->doc;
- char *str = doc_getstr(doc, NULL, NULL);
+ char *str = doc_getstr(*ci->pointp, NULL);
char *d, *b, *c;
int fd;
struct pane *par, *pop;
* Attach the 'docs' document as a completing popup menu
*/
struct doc *doc = (*ci->pointp)->doc;
- char *str = doc_getstr(doc, NULL, NULL);
+ char *str = doc_getstr(*ci->pointp, NULL);
struct pane *par, *pop;
struct cmd_info ci2 = {0};
struct point *pt, **ptp;