struct text_chunk *c;
unsigned int o;
};
-
+#define DOC_DATA_TYPE struct text
#include "core.h"
#include "misc.h"
} as;
};
+#include "core-pane.h"
+
static int text_advance_towards(struct text *t safe, struct doc_ref *ref safe,
struct doc_ref *target safe);
static int text_retreat_towards(struct text *t safe, struct doc_ref *ref safe,
static bool check_file_changed(struct pane *p safe)
{
- struct doc *d = p->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &p->doc_data;
struct stat st;
if (t->file_changed)
DEF_CMD(text_readonly)
{
struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
if (t->file_changed && !d->readonly && ci->num)
t->file_changed = 2;
DEF_CMD(text_load_file)
{
- struct doc *d = ci->home->data;
int fd = ci->num2;
const char *name = ci->str;
off_t size;
struct text_alloc *a;
struct text_chunk *c = NULL;
int len;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
if (t->saved != t->undo)
return Einval;
DEF_CMD(text_insert_file)
{
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
struct mark *pm = ci->mark, *early;
struct text_alloc *a;
int len;
static bool do_text_output_file(struct pane *p safe, struct doc_ref *start,
struct doc_ref *end, int fd)
{
- struct doc *d = p->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &p->doc_data;
struct text_chunk *c;
int offset = 0;
* Create a temp file with #basename#~, write to that,
* copy mode across, fsync and then rename
*/
- struct doc *d = p->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &p->doc_data;
char *tempname = malloc(strlen(fname) + 3 + 10);
const char *base;
char *tbase;
static void do_text_autosave(struct pane *p safe)
{
- struct doc *d = p->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &p->doc_data;
int fd = -1;
if (!t->fname)
static void text_check_autosave(struct pane *p safe)
{
- struct doc *d = p->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &p->doc_data;
if (t->undo == t->saved)
t->as.changes = 0;
DEF_CMD(text_save_file)
{
struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
int ret;
char *msg;
int change_status = 0;
DEF_CMD(text_same_file)
{
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
struct stat stb, stb2;
int fd = ci->num2;
static bool check_readonly(const struct cmd_info *ci safe)
{
struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
if (t->undo == t->saved &&
check_file_changed(ci->home) &&
DEF_CMD(text_reundo)
{
- struct doc *d = ci->home->data;
struct mark *m = ci->mark;
struct doc_ref start, end;
int last = 0;
struct text_edit *ed = NULL;
bool first = 1;
int status;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
if (!m)
return Enoarg;
static int text_step(struct pane *home safe, struct mark *mark safe,
int num, int num2)
{
- struct doc *d = home->data;
struct mark *m = mark;
bool forward = num;
bool move = num2;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &home->doc_data;
struct doc_ref r;
wint_t ret;
static int text_step_bytes(struct pane *home safe, struct mark *mark safe,
int num, int num2)
{
- struct doc *d = home->data;
struct mark *m = mark;
bool forward = num;
bool move = num2;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &home->doc_data;
struct doc_ref r;
wint_t ret;
struct text *t;
struct pane *p;
- alloc(t, pane);
+ p = doc_register(ci->home, &text_handle.c);
+ if (!p)
+ return Efail;
+ t = &p->doc_data;
t->alloc = safe_cast NULL;
INIT_LIST_HEAD(&t->text);
t->saved = t->undo = t->redo = NULL;
t->as.timer_started = 0;
t->as.last_change = 0;
text_new_alloc(t, 0);
- p = doc_register(ci->home, &text_handle.c, t);
- if (!p)
- return Efail;
return comm_call(ci->comm2, "callback:doc", p);
}
DEF_CMD(text_content)
{
- struct doc *d = ci->home->data;
struct mark *from = ci->mark, *to = ci->mark2;
struct mark *m;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
struct text_chunk *c, *first, *last;
int bytes = strcmp(ci->key, "doc:content-bytes") == 0;
int l = 0, head, tail;
DEF_CMD(text_val_marks)
{
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
struct text_chunk *c;
int found;
DEF_CMD(text_set_ref)
{
- struct doc *d = ci->home->data;
struct mark *m = ci->mark;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
if (!m)
return Enoarg;
DEF_CMD(text_replace)
{
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+
+ struct text *t = &ci->home->doc_data;
struct mark *pm = ci->mark2;
struct mark *end = ci->mark;
const char *str = ci->str;
return first ? 1 : 2;
}
-static struct attrset *text_attrset(struct doc *d safe, struct mark *m safe,
+static struct attrset *text_attrset(struct pane *p safe, struct mark *m safe,
int *op safe)
{
struct text_chunk *c;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &p->doc_data;
unsigned int o;
c = m->ref.c;
DEF_CMD(text_doc_get_attr)
{
- struct doc *d = ci->home->data;
struct mark *m = ci->mark;
const char *attr = ci->str;
const char *val;
if (!m || !attr)
return Enoarg;
- a = text_attrset(d, m, &o);
+ a = text_attrset(ci->home, m, &o);
val = attr_get_str(a, attr, o);
if (!val && !ci->num2)
return Efallthrough;
DEF_CMD(text_get_attr)
{
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
const char *attr = ci->str;
const char *val;
const char *attr = ci->str;
const char *val = ci->str2;
struct text_chunk *c, *c2;
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
unsigned int o, o2;
if (!attr)
DEF_CMD(text_modified)
{
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
if (ci->num == 0) {
/* toggle status */
DEF_CMD(text_revisited)
{
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
if (ci->num <= 0)
/* Being buried, not visited */
DEF_CMD(text_destroy)
{
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
text_cleanout(t);
return Efallthrough;
/* Clear the document, including undo/redo records
* i.e. free all text
*/
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
struct mark *m;
text_cleanout(t);
DEF_CMD(text_free)
{
- struct doc *d = ci->home->data;
- struct text *t = container_of(d, struct text, doc);
+ struct text *t = &ci->home->doc_data;
free((void*)t->fname);
free((void*)t->autosave_name);
- unalloc(t, pane);
return 1;
}