struct pane *p;
unsigned int ignore;
};
+#define DOC_SHARESREF
+#define DOC_DATA_TYPE struct docs
+struct docs;
+#define DOC_NEXT docs_next
+#define DOC_PREV docs_prev
#include "core.h"
static struct map *docs_map, *docs_aux_map, *docs_modified_map,
struct command callback;
struct pane *collection safe;
};
+#include "core-pane.h"
static void docs_demark(struct pane *d safe, struct pane *p safe)
{
/* This document (p) is about to be moved in the list (d->collection).
* Any mark pointing at it is moved forward
*/
- struct docs *doc = container_of(d->data, struct docs, doc);
+ struct docs *doc = &d->doc_data;
struct mark *m, *first = NULL;
struct pane *next;
struct pane *col = doc->collection;
/* This document has just been added to the list.
* any mark pointing just past it is moved back.
*/
- struct docs *doc = container_of(d->data, struct docs, doc);
+ struct docs *doc = &d->doc_data;
struct mark *m, *first = NULL;
struct pane *next;
struct pane *col = doc->collection;
static void doc_checkname(struct pane *p safe, struct pane *d safe, int n)
{
- struct docs *ds = container_of(d->data, struct docs, doc);
-
+ struct docs *ds = &d->doc_data;
ASSERT(p->parent->handle == &docs_aux.c);
- ASSERT(p->parent->data == d);
check_name(ds, p);
if (n) {
docs_demark(d, p);
DEF_CMD(docs_callback_byname)
{
- struct docs *doc = ci->home->data;
+ struct docs *doc = &ci->home->doc_data;
struct pane *p;
if (ci->str == NULL || strcmp(ci->str, "*Documents*") == 0)
DEF_CMD(docs_callback_byfd)
{
- struct docs *doc = ci->home->data;
+ struct docs *doc = &ci->home->doc_data;
struct pane *p;
list_for_each_entry(p, &doc->collection->children, siblings) {
DEF_CMD(docs_callback_byeach)
{
- struct docs *doc = ci->home->data;
+ struct docs *doc = &ci->home->doc_data;
struct pane *p;
list_for_each_entry(p, &doc->collection->children, siblings) {
DEF_CMD(docs_callback_choose)
{
- struct docs *doc = ci->home->data;
+ struct docs *doc = &ci->home->doc_data;
struct pane *choice = NULL, *last = NULL;
struct pane *p;
DEF_CMD(docs_callback_saveall)
{
- struct docs *doc = ci->home->data;
+ struct docs *doc = &ci->home->doc_data;
struct pane *p;
int dirlen = ci->str ? (int)strlen(ci->str) : -1;
DEF_CMD(docs_callback_modified)
{
- struct docs *doc = ci->home->data;
+ struct docs *doc = &ci->home->doc_data;
struct pane *p;
p = home_call_ret(pane, ci->home, "doc:attach-view", ci->focus,
DEF_CMD(docs_callback_appeared)
{
- struct docs *doc = ci->home->data;
+ struct docs *doc = &ci->home->doc_data;
struct pane *p;
/* Always return Efallthrough so other handlers get a chance */
{
struct pane *p = ci->focus;
struct pane *dp = ci->home->data;
- struct docs *docs = container_of(dp->data, struct docs, doc);
+ struct docs *docs = &dp->doc_data;
if (!p)
return Einval;
return 1;
}
-static int docs_step(struct pane *home safe, struct mark *mark safe,
- int num, int num2)
+static inline wint_t docs_next(struct docs *d safe, struct doc_ref *r safe, bool bytes)
{
- struct doc *doc = home->data;
- struct mark *m = mark;
- bool forward = num;
- bool move = num2;
- int ret;
- struct pane *p, *next;
- struct docs *d = container_of(doc, struct docs, doc);
-
- p = m->ref.p;
- if (forward) {
- /* report on d */
- if (p == NULL || p == list_last_entry(&d->collection->children,
- struct pane, siblings))
- next = NULL;
- else
- next = list_next_entry(p, siblings);
- } else {
- next = p;
- if (list_empty(&d->collection->children))
- p = NULL;
- else if (!p)
- p = list_last_entry(&d->collection->children,
- struct pane, siblings);
- else if (p != list_first_entry(&d->collection->children,
- struct pane, siblings))
- p = list_prev_entry(p, siblings);
- else
- p = NULL;
- if (p)
- next = p;
- }
- if (move) {
- mark_step_sharesref(m, forward);
- m->ref.p = next;
- }
+ struct pane *p = r->p;
if (p == NULL)
- ret = WEOF;
+ return WEOF;
+
+ if (p == list_last_entry(&d->collection->children,
+ struct pane, siblings))
+ r->p = NULL;
else
- ret = '\n';
+ r->p = list_next_entry(p, siblings);
+ return '\n';
+}
+static inline wint_t docs_prev(struct docs *d safe, struct doc_ref *r safe, bool bytes)
+{
+ struct pane *p = r->p;
- return CHAR_RET(ret);
+ if (list_empty(&d->collection->children))
+ return WEOF;
+ else if (!p)
+ p = list_last_entry(&d->collection->children,
+ struct pane, siblings);
+ else if (p != list_first_entry(&d->collection->children,
+ struct pane, siblings))
+ p = list_prev_entry(p, siblings);
+ else
+ return WEOF;
+ r->p = p;
+ return '\n';
}
DEF_CMD(docs_char)
{
- struct mark *m = ci->mark;
- struct mark *end = ci->mark2;
- int steps = ci->num;
- int forward = steps > 0;
- int ret = Einval;
-
- if (!m)
- return Enoarg;
- if (end && mark_same(m, end))
- return 1;
- if (end && (end->seq < m->seq) != (steps < 0))
- /* Can never cross 'end' */
- return Einval;
- while (steps && ret != CHAR_RET(WEOF) && (!end || !mark_same(m, end))) {
- ret = docs_step(ci->home, m, forward, 1);
- steps -= forward*2 - 1;
- }
- if (end)
- return 1 + (forward ? ci->num - steps : steps - ci->num);
- if (ret == CHAR_RET(WEOF) || ci->num2 == 0)
- return ret;
- if (ci->num && (ci->num2 < 0) == forward)
- return ret;
- /* Want the 'next' char */
- return docs_step(ci->home, m, ci->num2 > 0, 0);
+ return do_char_byte(ci);
}
DEF_CMD(docs_set_ref)
{
- struct doc *dc = ci->home->data;
- struct docs *d = container_of(dc, struct docs, doc);
+ struct docs *d = &ci->home->doc_data;
struct mark *m = ci->mark;
if (!m)
DEF_CMD(docs_val_marks)
{
- struct doc *dc = ci->home->data;
- struct docs *d = container_of(dc, struct docs, doc);
+ struct docs *d = &ci->home->doc_data;
struct pane *p;
int found;
DEF_CMD(docs_close)
{
- struct docs *docs = ci->home->data;
+ struct docs *docs = &ci->home->doc_data;
call_comm("global-set-command-prefix", ci->home, &edlib_noop,
0, NULL, "docs:");
struct docs *doc;
struct pane *pd, *paux;
- alloc(doc, pane);
docs_init_map();
- pd = doc_register(ci->home, &docs_handle.c, doc);
- if (!pd) {
- free(doc->doc.name);
- free(doc);
+ pd = doc_register(ci->home, &docs_handle.c);
+ if (!pd)
return Efail;
- }
+ doc = &pd->doc_data;
doc->doc.name = strdup("*Documents*");
paux = pane_register(ci->home, 0, &docs_aux.c, pd);
if (!paux) {