ci.pointp = &ptp;
pt.doc = d;
c = d->views[i].notify;
- c->func(c, &ci);
+ ci.comm = c;
+ c->func(&ci);
}
}
.set_attr = docs_set_attr,
};
-static int docs_open(struct command *c, struct cmd_info *ci)
+DEF_CMD(comm_open)
{
struct pane *p = ci->home;
struct point *pt;
return 0;
}
}
-DEF_CMD(comm_open, docs_open);
void doc_make_docs(struct editor *ed)
{
struct command comm;
};
-static int key_prefix(struct command *comm, struct cmd_info *ci)
+static int key_prefix(struct cmd_info *ci)
{
- struct modmap *m = container_of(comm, struct modmap, comm);
+ struct modmap *m = container_of(ci->comm, struct modmap, comm);
pane_set_mode(ci->home, m->name, m->transient);
return 1;
comm = GETCOMM(m->comms[pos-1]);
} else
return 0;
- return comm->func(comm, ci);
+ ci->comm = comm;
+ return comm->func(ci);
}
int key_handle(struct cmd_info *ci)
struct pane *p = ci->focus;
int ret = 0;
+ if (ci->comm)
+ return ci->comm->func(ci);
+
if (!ci->pointp)
ci->pointp = pane_point(p);
while (ret == 0 && p) {
if (p->handle) {
ci->home = p;
- ret = p->handle->func(p->handle, ci);
+ ci->comm = p->handle;
+ ret = p->handle->func(ci);
}
if (ret)
/* 'p' might have been destroyed */
p = p->focus;
}
ci->focus = p;
+ ci->comm = NULL;
return key_handle(ci);
}
ci->x = x;
ci->y = y;
ci->focus = p;
+ ci->comm = NULL;
return key_handle(ci);
}
if (!c)
continue;
+ ci.comm = c;
while (TLIST_TYPE(tl) == GRP_LIST)
tl = TLIST_PTR(tl->prev);
if (TLIST_TYPE(tl) == GRP_MARK)
ci.mark = tlist_entry(tl, struct mark, view);
else
ci.mark = NULL;
- c->func(c, &ci);
+ c->func(&ci);
while (TLIST_TYPE(tl) == GRP_MARK &&
(mark_ordered(m, ci.mark) || mark_same(d, m, ci.mark))) {
do
if (TLIST_TYPE(tl) == GRP_MARK) {
ci.mark = tlist_entry(tl, struct mark, view);
- c->func(c, &ci);
+ c->func(&ci);
}
}
if (TLIST_TYPE(tl) == GRP_MARK) {
ci.mark = tlist_entry(tl, struct mark, view);
if (mark_same(d, ci.mark, mark_of_point(p)))
- c->func(c, &ci);
+ c->func(&ci);
else
break;
}
ci.mark = tlist_entry(tl, struct mark, view);
else
ci.mark = NULL;
- c->func(c, &ci);
+ ci.comm = c;
+ c->func(&ci);
}
break;
}
remaining -= 1;
if (c) {
ci.mark = m;
- c->func(c, &ci);
+ ci.comm = c;
+ c->func(&ci);
}
}
if (m->all.pprev == &d->marks.first)
if (ci->extra & DAMAGED_CONTENT)
ci->extra |= DAMAGED_CURSOR;
damage &= DAMAGED_SIZE;
- if (p->handle->func(p->handle, ci))
+ ci->comm = p->handle;
+ if (p->handle->func(ci))
damage |= ci->extra;
}
p->damaged = 0;
ci.key = "Close";
ci.focus = ci.home = p;
ci.pointp = pane_point(p);
- p->handle->func(p->handle, &ci);
+ ci.comm = p->handle;
+ p->handle->func(&ci);
}
pane_damaged(p->parent, DAMAGED_SIZE);
attr_free(&p->attrs);
ci.key = "Clone";
ci.focus = parent;
ci.home = from;
+ ci.comm = from->handle;
if (from->handle)
- return from->handle->func(from->handle, &ci);
+ return from->handle->func(&ci);
return 0;
}
/* Commands */
struct command {
- int (*func)(struct command *comm, struct cmd_info *ci);
+ int (*func)(struct cmd_info *ci);
};
-#define CMD(func) {func}
-#define DEF_CMD(comm, func) static struct command comm = CMD(func)
+#define CMD(_name) {_name ## _func }
+#define DEF_CMD(_name) \
+ static int _name ## _func(struct cmd_info *ci); \
+ static struct command _name = CMD(_name); \
+ static int _name ## _func(struct cmd_info *ci)
+#define REDEF_CMD(_name) \
+ static int _name ## _func(struct cmd_info *ci)
+
#define ARRAY_SIZE(ra) (sizeof(ra) / sizeof(ra[0]))
/* Each event (above) is accompanied by a cmd_info structure.
char *str, *str2;
struct mark *mark;
struct point **pointp;
+ struct command *comm;
};
#define NO_NUMERIC (INT_MAX/2)
#define RPT_NUM(ci) ((ci)->numeric == NO_NUMERIC ? 1 : (ci)->numeric)
refresh();
}
-static int nc_misc(struct command *c, struct cmd_info *ci)
+DEF_CMD(nc_misc)
{
struct pane *p = ci->home;
struct display_data *dd = p->data;
return attr;
}
-static int do_ncurses_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(ncurses_handle)
{
struct pane *p = ci->home;
int damage = ci->extra;
struct timeval tv;
if (strcmp(ci->key, "Misc") == 0)
- return nc_misc(c, ci);
+ return nc_misc.func(ci);
if (strcmp(ci->key, "Close") == 0) {
ncurses_end();
}
return 0;
}
-DEF_CMD(ncurses_handle, do_ncurses_handle);
static void handle_winch(int sig, short ev, void *null);
static struct pane *ncurses_init(struct editor *ed)
pane_refresh(p);
}
-static int display_ncurses(struct command *c, struct cmd_info *ci)
+DEF_CMD(comm_ncurses)
{
struct pane *p = ncurses_init(pane2ed(ci->home));
ci->focus = p;
return 1;
}
-DEF_CMD(comm_ncurses, display_ncurses);
void edlib_init(struct editor *ed)
{
closedir(dir);
}
-static int dir_new(struct command *c, struct cmd_info *ci)
+DEF_CMD(comm_new)
{
struct directory *dr = malloc(sizeof(*dr));
doc_init(&dr->doc);
point_new(&dr->doc, ci->pointp);
return 1;
}
-DEF_CMD(comm_new, dir_new);
static void dir_replace(struct point *pos, struct mark *end,
char *str, bool *first)
.destroy = dir_destroy,
};
-static int doc_dir_open(struct command *c, struct cmd_info *ci)
+DEF_CMD(comm_open)
{
struct pane *p = ci->home;
struct point *pt = p->point;
pane_focus(p);
return 1;
}
-DEF_CMD(comm_open, doc_dir_open);
void edlib_init(struct editor *ed)
{
return text_ref_same(t, &a->ref, &b->ref);
}
-static int text_new(struct command *c, struct cmd_info *ci)
+DEF_CMD(comm_new)
{
struct text *t = malloc(sizeof(*t));
t->alloc = NULL;
point_new(&t->doc, ci->pointp);
return 1;
}
-DEF_CMD(comm_new, text_new);
static int count_bytes(struct text *t, struct mark *from, struct mark *to)
{
static struct map *es_map;
-static int do_search_again(struct command *c, struct cmd_info *ci);
-static int do_search_forward(struct command *c, struct cmd_info *ci)
+static int do_search_again(struct cmd_info *ci);
+
+DEF_CMD(search_forward)
{
struct es_info *esi = ci->home->data;
struct doc *d = esi->end->doc;
point_notify_change(*ci->pointp, NULL);
return 1;
}
-DEF_CMD(search_forward, do_search_forward);
-static int do_search_retreat(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_retreat)
{
struct es_info *esi = ci->home->data;
char *str;
point_notify_change(*ci->pointp, NULL);
return 1;
}
-DEF_CMD(search_retreat, do_search_retreat);
-static int do_search_add(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_add)
{
struct es_info *esi = ci->home->data;
struct doc *d = esi->end->doc;
} while (strcmp(ci->key, "C-Chr-C") != 0 && wch != ' ');
return 1;
}
-DEF_CMD(search_add, do_search_add);
-static int do_search_backward(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_backward)
{
return 1;
}
-DEF_CMD(search_backward, do_search_backward);
-static int do_search_refresh(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_refresh)
{
pane_check_size(ci->focus);
return 1;
}
-DEF_CMD(search_refresh, do_search_refresh);
-static int do_search_close(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_close)
{
struct es_info *esi = ci->focus->data;
}
return 1;
}
-DEF_CMD(search_close, do_search_close);
-static int do_search_again(struct command *c, struct cmd_info *ci)
+static int do_search_again(struct cmd_info *ci)
{
/* document has changed, retry search */
- struct es_info *esi = container_of(c, struct es_info, watch);
+ struct es_info *esi = container_of(ci->comm, struct es_info, watch);
struct cmd_info ci2 = {0};
struct doc *d = esi->end->doc;
struct pane *p;
struct doc *d = (*ci->pointp)->doc;
/* No marks to remove */
- doc_del_view(d, c);
+ doc_del_view(d, ci->comm);
return 0;
}
key_add(es_map, "Close", &search_close);
}
-static int do_search_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(search_handle)
{
return key_lookup(es_map, ci);
}
-DEF_CMD(search_handle, do_search_handle);
-static int emacs_search(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_search)
{
struct pane *p;
struct es_info *esi;
ci->home = p;
return 1;
}
-DEF_CMD(comm_emacs_search, emacs_search);
void emacs_search_init(struct editor *ed)
{
- key_add(ed->commands, "attach-emacs-search", &comm_emacs_search);
+ key_add(ed->commands, "attach-emacs-search", &emacs_search);
}
int global;
};
-static int keymap_attach(struct command *c, struct cmd_info *ci);
+static int keymap_attach_func(struct cmd_info *ci);
-static int key_do_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(keymap_handle)
{
struct key_data *kd = ci->home->data;
int i;
struct pane *p = ci->focus;
struct cmd_info ci2 = {0};
ci2.focus = p;
- keymap_attach(NULL, &ci2);
+ keymap_attach_func(&ci2);
pane_attach(p, "local-keymap", NULL, NULL);
return key_handle_focus(ci);
}
}
for (i = 0; i < kd->cmdcount; i++) {
- int ret = kd->cmds[i]->func(kd->cmds[i], ci);
+ int ret;
+ ci->comm = kd->cmds[i];
+ ret = kd->cmds[i]->func(ci);
if (ret)
return ret;
}
return key_lookup(kd->map, ci);
}
-DEF_CMD(key_handle, key_do_handle);
-static int keymap_attach(struct command *c, struct cmd_info *ci)
+DEF_CMD(keymap_attach)
{
struct key_data *kd = malloc(sizeof(*kd));
struct pane *p;
kd->cmds = NULL;
kd->globalcmd = NULL;
kd->cmdcount = 0;
- kd->global = c ? 1 : 0;
+ kd->global = ci->comm ? 1 : 0;
p = ci->focus;
while (pane_child(p))
p = pane_child(p);
- p = pane_register(p, 0, &key_handle, kd, NULL);
+ p = pane_register(p, 0, &keymap_handle, kd, NULL);
pane_check_size(p);
ci->home = p;
return 1;
}
-DEF_CMD(comm_attach, keymap_attach);
void edlib_init(struct editor *ed)
{
- key_add(ed->commands, "attach-global-keymap", &comm_attach);
+ key_add(ed->commands, "attach-global-keymap", &keymap_attach);
}
mark_free(m);
}
-static int count_notify(struct command *c, struct cmd_info *ci)
+DEF_CMD(count_notify)
{
if (strcmp(ci->key, "Replace") == 0) {
if (ci->mark != NULL) {
if (strcmp(ci->key, "Release") == 0) {
struct doc *d = (*ci->pointp)->doc;
struct mark *m;
- int i = doc_find_view(d, c);
+ int i = doc_find_view(d, ci->comm);
if (i < 0)
return 0;
while ((m = doc_first_mark(d, i)) != NULL)
mark_free(m);
- doc_del_view(d, c);
+ doc_del_view(d, ci->comm);
}
return 0;
}
-static struct command count_cmd = {count_notify};
static int need_recalc(struct doc *d, struct mark *m)
{
static void count_calculate(struct doc *d, struct mark *start, struct mark *end)
{
- int type = doc_find_view(d, &count_cmd);
+ int type = doc_find_view(d, &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_cmd);
+ type = doc_add_view(d, &count_notify);
m = doc_first_mark(d, type);
if (m == NULL) {
attr_set_int(attrs, "chars", chars);
}
-static int do_count_lines(struct command *c, struct cmd_info *ci)
+DEF_CMD(count_lines)
{
struct point *pt = *ci->pointp;
struct doc *d = pt->doc;
count_calculate(d, NULL, ci->mark);
return 1;
}
-DEF_CMD(comm_count, do_count_lines);
void edlib_init(struct editor *ed)
{
- key_add(ed->commands, "CountLines", &comm_count);
+ key_add(ed->commands, "CountLines", &count_lines);
}
pane_resize(p, x, y, w, h);
}
-static int do_popup_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(popup_handle)
{
struct pane *p = ci->home;
struct popup_info *ppi = p->data;
}
return 0;
}
-DEF_CMD(popup_handle, do_popup_handle);
-static int popup_quote(struct command *c, struct cmd_info *ci)
+DEF_CMD(popup_quote)
{
struct cmd_info ci2 = *ci;
ci2.key = "popup:Abort";
return key_handle_focus(&ci2);
}
-DEF_CMD(comm_quote, popup_quote);
-static int popup_attach(struct command *c, struct cmd_info *ci)
+DEF_CMD(popup_attach)
{
/* attach a popup. It can be attach to the view or the display,
* can be in a corner, in a side, or central, and be 1 line or
ci->home = p;
return 1;
}
-DEF_CMD(comm_attach, popup_attach);
void edlib_init(struct editor *ed)
{
- key_add(ed->commands, "attach-popup", &comm_attach);
- key_add(ed->commands, "popup:quote", &comm_quote);
+ key_add(ed->commands, "attach-popup", &popup_attach);
+ key_add(ed->commands, "popup:quote", &popup_quote);
}
#include "core.h"
#include "rexel.h"
-static int text_search(struct command *c, struct cmd_info *ci)
+DEF_CMD(text_search)
{
struct point *pt;
struct mark *m;
free(rxl);
return 1;
}
-DEF_CMD(comm_search, text_search);
void edlib_init(struct editor *ed)
{
- key_add(ed->commands, "text-search", &comm_search);
+ key_add(ed->commands, "text-search", &text_search);
}
static void tile_avail(struct pane *p, struct pane *ignore);
static int tile_destroy(struct pane *p);
-static int do_tile_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(tile_handle)
{
struct pane *p = ci->home;
int damage = ci->extra;
}
return 0;
}
-DEF_CMD(tile_handle, do_tile_handle);
-static int tile_attach(struct command *c, struct cmd_info *ci)
+DEF_CMD(tile_attach)
{
struct pane *display = ci->focus;
struct tileinfo *ti = malloc(sizeof(*ti));
attr_set_str(&p->attrs, "borders", "BL", -1);
return 1;
}
-DEF_CMD(comm_attach, tile_attach);
static struct pane *tile_split(struct pane *p, int horiz, int after)
{
return 1;
}
-static int tile_command(struct command *c, struct cmd_info *ci)
+DEF_CMD(tile_command)
{
struct pane *p = ci->home;
struct pane *p2;
return 0;
return 1;
}
-DEF_CMD(comm_tile, tile_command);
-static int tile_other(struct command *c, struct cmd_info *ci)
+DEF_CMD(tile_other)
{
/* Choose some other tile. If there aren't any, make one.
* Result is returned in ci->focus
ci->focus = p2;
return 1;
}
-DEF_CMD(comm_other, tile_other);
+
void edlib_init(struct editor *ed)
{
tile_map = key_alloc();
- key_add(tile_map, "WindowOP", &comm_tile);
- key_add(tile_map, "OtherPane", &comm_other);
+ key_add(tile_map, "WindowOP", &tile_command);
+ key_add(tile_map, "OtherPane", &tile_other);
- key_add(ed->commands, "attach-tile", &comm_attach);
+ key_add(ed->commands, "attach-tile", &tile_attach);
}
};
static struct map *view_map;
-static struct pane *view_attach(struct pane *par, struct point *pt, int border);
+static struct pane *do_view_attach(struct pane *par, struct point *pt, int border);
static int view_refresh(struct cmd_info *ci)
{
return 0;
}
-static int do_view_handle(struct command *cm, struct cmd_info *ci)
+DEF_CMD(view_handle)
{
struct pane *p = ci->home;
struct point *pt;
if (!p->point)
return 0;
point_dup(p->point, &pt);
- p2 = view_attach(parent, pt, vd->border);
+ p2 = do_view_attach(parent, pt, vd->border);
c = pane_child(pane_child(p));
if (c)
return pane_clone(c, p2);
return view_refresh(ci);
return 0;
}
-DEF_CMD(view_handle, do_view_handle);
-static int do_view_null(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_null)
{
struct pane *p = ci->home;
struct view_data *vd = p->data;
}
return 0;
}
-DEF_CMD(view_null, do_view_null);
static struct pane *view_reattach(struct pane *p, struct point *pt);
-static int view_notify(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_notify)
{
- struct view_data *vd = container_of(c, struct view_data, ch_notify);
+ struct view_data *vd = container_of(ci->comm, struct view_data, ch_notify);
if (strcmp(ci->key, "Replace") == 0) {
pane_damaged(vd->pane, DAMAGED_CONTENT);
return p;
}
-static struct pane *view_attach(struct pane *par, struct point *pt, int border)
+static struct pane *do_view_attach(struct pane *par, struct point *pt, int border)
{
struct view_data *vd;
struct pane *p;
vd = malloc(sizeof(*vd));
vd->border = border;
- vd->ch_notify.func = view_notify;
+ vd->ch_notify = view_notify;
pt->owner = &pt;
p = pane_register(par, 0, &view_handle, vd, NULL);
vd->pane = p;
return view_reattach(p, pt);
}
-static int do_view_attach(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_attach)
{
int borders = 0;
char *borderstr = pane_attr_get(ci->focus, "borders");
if (strchr(borderstr, 'L')) borders |= BORDER_LEFT;
if (strchr(borderstr, 'R')) borders |= BORDER_RIGHT;
- ci->home = view_attach(ci->focus, *ci->pointp, borders);
+ ci->home = do_view_attach(ci->focus, *ci->pointp, borders);
return ci->home != NULL;
}
-DEF_CMD(comm_attach, do_view_attach);
-static int view_char(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_char)
{
struct point *pt = *ci->pointp;
int rpt = RPT_NUM(ci);
return 1;
}
-DEF_CMD(comm_char, view_char);
-static int view_word(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_word)
{
struct point *pt = *ci->pointp;
int rpt = RPT_NUM(ci);
return 1;
}
-DEF_CMD(comm_word, view_word);
-static int view_WORD(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_WORD)
{
struct point *pt = *ci->pointp;
int rpt = RPT_NUM(ci);
return 1;
}
-DEF_CMD(comm_WORD, view_WORD);
-static int view_eol(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_eol)
{
struct point *pt = *ci->pointp;
wint_t ch = 1;
}
return 1;
}
-DEF_CMD(comm_eol, view_eol);
-static int view_line(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_line)
{
struct point *pt = *ci->pointp;
wint_t ch = 1;
}
return 1;
}
-DEF_CMD(comm_line, view_line);
-static int view_file(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_file)
{
struct point *pt = *ci->pointp;
wint_t ch = 1;
}
return 1;
}
-DEF_CMD(comm_file, view_file);
-static int view_page(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_page)
{
struct point *pt = *ci->pointp;
wint_t ch = 1;
}
return 1;
}
-DEF_CMD(comm_page, view_page);
-static int view_replace(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_replace)
{
struct point *pt = *ci->pointp;
bool first_change = (ci->extra == 0);
doc_replace(pt, ci->mark, ci->str, &first_change);
return 1;
}
-DEF_CMD(comm_replace, view_replace);
-static int view_click(struct command *c, struct cmd_info *ci)
+DEF_CMD(view_click)
{
struct pane *p = ci->home;
struct view_data *vd = p->data;
return 0;
return key_handle_focus(&ci2);
}
-DEF_CMD(comm_click, view_click);
void edlib_init(struct editor *ed)
{
view_map = key_alloc();
- key_add(view_map, "Move-Char", &comm_char);
- key_add(view_map, "Move-Word", &comm_word);
- key_add(view_map, "Move-WORD", &comm_WORD);
- key_add(view_map, "Move-EOL", &comm_eol);
- key_add(view_map, "Move-Line", &comm_line);
- key_add(view_map, "Move-File", &comm_file);
- key_add(view_map, "Move-View-Large", &comm_page);
+ key_add(view_map, "Move-Char", &view_char);
+ key_add(view_map, "Move-Word", &view_word);
+ key_add(view_map, "Move-WORD", &view_WORD);
+ key_add(view_map, "Move-EOL", &view_eol);
+ key_add(view_map, "Move-Line", &view_line);
+ key_add(view_map, "Move-File", &view_file);
+ key_add(view_map, "Move-View-Large", &view_page);
- key_add(view_map, "Replace", &comm_replace);
+ key_add(view_map, "Replace", &view_replace);
- key_add(view_map, "Click-1", &comm_click);
- key_add(view_map, "Press-1", &comm_click);
+ key_add(view_map, "Click-1", &view_click);
+ key_add(view_map, "Press-1", &view_click);
- key_add(ed->commands, "attach-view", &comm_attach);
+ key_add(ed->commands, "attach-view", &view_attach);
}
#include "core.h"
-static int emacs_move(struct command *c, struct cmd_info *ci);
-static int emacs_delete(struct command *c, struct cmd_info *ci);
+REDEF_CMD(emacs_move);
+REDEF_CMD(emacs_delete);
static struct move_command {
struct command cmd;
"C-Chr-K", NULL, NULL},
};
-static int emacs_move(struct command *c, struct cmd_info *ci)
+REDEF_CMD(emacs_move)
{
- struct move_command *mv = container_of(c, struct move_command, cmd);
+ struct move_command *mv = container_of(ci->comm, struct move_command, cmd);
struct pane *cursor_pane = pane_with_cursor(ci->home, NULL, NULL);
struct point *pt = *ci->pointp;
int old_x = -1;
return ret;
}
-static int emacs_delete(struct command *c, struct cmd_info *ci)
+REDEF_CMD(emacs_delete)
{
- struct move_command *mv = container_of(c, struct move_command, cmd);
+ struct move_command *mv = container_of(ci->comm, struct move_command, cmd);
struct cmd_info ci2 = {0};
int ret = 0;
struct mark *m;
return ret;
}
-static int emacs_str(struct command *c, struct cmd_info *ci);
+REDEF_CMD(emacs_str);
static struct str_command {
struct command cmd;
char *type;
{CMD(emacs_str), "NOP", NULL, "emCX4-C-Chr-G"},
};
-static int emacs_str(struct command *c, struct cmd_info *ci)
+REDEF_CMD(emacs_str)
{
- struct str_command *sc = container_of(c, struct str_command, cmd);
+ struct str_command *sc = container_of(ci->comm, struct str_command, cmd);
struct cmd_info ci2;
ci2 = *ci;
return key_handle_focus(&ci2);
}
-static int emacs_insert(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_insert)
{
char str[5];
struct cmd_info ci2 = {0};
return ret;
}
-DEF_CMD(comm_insert, emacs_insert);
static struct {
char *key;
{NULL, NULL}
};
-static int emacs_insert_other(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_insert_other)
{
struct pane *p = ci->home;
struct cmd_info ci2 = {0};
pane_set_extra(p, 0); /* A newline starts a new undo */
return ret;
}
-DEF_CMD(comm_insert_other, emacs_insert_other);
-static int emacs_undo(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_undo)
{
struct point *pt = *ci->pointp;
doc_undo(pt, 0);
return 1;
}
-DEF_CMD(comm_undo, emacs_undo);
-static int emacs_redo(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_redo)
{
struct point *pt = *ci->pointp;
doc_undo(pt, 1);
return 1;
}
-DEF_CMD(comm_redo, emacs_redo);
-static int emacs_findfile(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_findfile)
{
int fd;
struct pane *p, *par;
pane_focus(p);
return 1;
}
-DEF_CMD(comm_findfile, emacs_findfile);
-static int emacs_finddoc(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_finddoc)
{
struct pane *p, *par;
struct doc *d;
render_attach(NULL, p);
return 1;
}
-DEF_CMD(comm_finddoc, emacs_finddoc);
-static int emacs_viewdocs(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_viewdocs)
{
struct pane *p, *par;
struct doc *d;
render_attach(NULL, p);
return 1;
}
-DEF_CMD(comm_viewdocs, emacs_viewdocs);
-static int emacs_meta(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_meta)
{
pane_set_mode(ci->home, "M-", 1);
pane_set_numeric(ci->home, ci->numeric);
pane_set_extra(ci->home, ci->extra);
return 1;
}
-DEF_CMD(comm_meta, emacs_meta);
-static int emacs_num(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_num)
{
int rpt = RPT_NUM(ci);
char *last = ci->key + strlen(ci->key)-1;
pane_set_extra(ci->home, ci->extra);
return 1;
}
-DEF_CMD(comm_num, emacs_num);
-static int emacs_kill_doc(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_kill_doc)
{
struct doc *d;
if (!ci->pointp)
doc_destroy(d);
return 1;
}
-DEF_CMD(comm_kill_doc, emacs_kill_doc);
-static int emacs_search(struct command *c, struct cmd_info *ci)
+DEF_CMD(emacs_search)
{
struct cmd_info ci2 = {0};
mark_free(ci2.mark);
return 1;
}
-DEF_CMD(comm_search, emacs_search);
static struct map *emacs_map;
key_add(m, "C-Chr-X", cx_cmd);
key_add(m, "emCX-Chr-4", cx4_cmd);
- key_add(m, "ESC", &comm_meta);
+ key_add(m, "ESC", &emacs_meta);
for (i = 0; i < ARRAY_SIZE(move_commands); i++) {
struct move_command *mc = &move_commands[i];
key_add(m, sc->k, &sc->cmd);
}
- key_add_range(m, "Chr- ", "Chr-~", &comm_insert);
- key_add(m, "Tab", &comm_insert_other);
- key_add(m, "LF", &comm_insert_other);
- key_add(m, "Return", &comm_insert_other);
+ key_add_range(m, "Chr- ", "Chr-~", &emacs_insert);
+ key_add(m, "Tab", &emacs_insert_other);
+ key_add(m, "LF", &emacs_insert_other);
+ key_add(m, "Return", &emacs_insert_other);
- key_add(m, "C-Chr-_", &comm_undo);
- key_add(m, "M-C-Chr-_", &comm_redo);
+ key_add(m, "C-Chr-_", &emacs_undo);
+ key_add(m, "M-C-Chr-_", &emacs_redo);
- key_add(m, "emCX-C-Chr-F", &comm_findfile);
- key_add(m, "emCX4-C-Chr-F", &comm_findfile);
- key_add(m, "emCX4-Chr-f", &comm_findfile);
- key_add(m, "File Found", &comm_findfile);
- key_add(m, "File Found Other Window", &comm_findfile);
+ key_add(m, "emCX-C-Chr-F", &emacs_findfile);
+ key_add(m, "emCX4-C-Chr-F", &emacs_findfile);
+ key_add(m, "emCX4-Chr-f", &emacs_findfile);
+ key_add(m, "File Found", &emacs_findfile);
+ key_add(m, "File Found Other Window", &emacs_findfile);
- key_add(m, "emCX-Chr-b", &comm_finddoc);
- key_add(m, "emCX4-Chr-b", &comm_finddoc);
- key_add(m, "Doc Found", &comm_finddoc);
- key_add(m, "Doc Found Other Window", &comm_finddoc);
- key_add(m, "emCX-C-Chr-B", &comm_viewdocs);
+ key_add(m, "emCX-Chr-b", &emacs_finddoc);
+ key_add(m, "emCX4-Chr-b", &emacs_finddoc);
+ key_add(m, "Doc Found", &emacs_finddoc);
+ key_add(m, "Doc Found Other Window", &emacs_finddoc);
+ key_add(m, "emCX-C-Chr-B", &emacs_viewdocs);
- key_add(m, "emCX-Chr-k", &comm_kill_doc);
+ key_add(m, "emCX-Chr-k", &emacs_kill_doc);
- key_add(m, "C-Chr-S", &comm_search);
- key_add(m, "Search String", &comm_search);
+ key_add(m, "C-Chr-S", &emacs_search);
+ key_add(m, "Search String", &emacs_search);
- key_add_range(m, "M-Chr-0", "M-Chr-9", &comm_num);
+ key_add_range(m, "M-Chr-0", "M-Chr-9", &emacs_num);
emacs_map = m;
}
-static int do_mode_emacs(struct command *c, struct cmd_info *ci)
+DEF_CMD(mode_emacs)
{
return key_lookup(emacs_map, ci);
}
-DEF_CMD(mode_emacs, do_mode_emacs);
void emacs_search_init(struct editor *ed);
void edlib_init(struct editor *ed)
};
static struct map *dr_map;
-static void render_dir_attach(struct pane *parent, struct point **ptp);
+static void do_render_dir_attach(struct pane *parent, struct point **ptp);
static int put_str(struct pane *p, char *buf, char *attrs, int x, int y)
{
return start;
}
-static int do_render_dir_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_handle)
{
struct pane *p = ci->home;
struct dir_data *dd = p->data;
struct pane *parent = ci->focus;
struct pane *c;
- render_dir_attach(parent, NULL);
+ do_render_dir_attach(parent, NULL);
c = pane_child(p);
if (c)
return pane_clone(c, parent->focus);
}
return 0;
}
-DEF_CMD(render_dir_handle, do_render_dir_handle);
-static int render_dir_notify(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_notify)
{
- struct dir_data *dd = container_of(c, struct dir_data, type);
+ struct dir_data *dd = container_of(ci->comm, struct dir_data, type);
if (strcmp(ci->key, "Replace") == 0) {
if (ci->mark == dd->top)
return 0;
}
-static int render_dir_move(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_move)
{
struct pane *p = ci->home;
int rpt = RPT_NUM(ci);
pane_damaged(p, DAMAGED_CONTENT);
return 1;
}
-DEF_CMD(comm_move, render_dir_move);
-static int render_dir_follow_point(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_follow_point)
{
struct pane *p = ci->home;
struct dir_data *dd = p->data;
}
return 0;
}
-DEF_CMD(comm_follow, render_dir_follow_point);
-static int render_dir_set_cursor(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_set_cursor)
{
struct pane *p = ci->home;
struct point *pt = *ci->pointp;
pane_focus(p);
return 1;
}
-DEF_CMD(comm_cursor, render_dir_set_cursor);
-static int render_dir_move_line(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_move_line)
{
struct point *pt = *ci->pointp;
struct dir_data *dd = ci->home->data;
return 1;
}
-DEF_CMD(comm_line, render_dir_move_line);
-static int render_dir_move_horiz(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_move_horiz)
{
/* Horizonal movement - adjust ->rpos within fields, or
* move to next line
}
return 1;
}
-DEF_CMD(comm_horiz, render_dir_move_horiz);
-static int render_dir_open(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_open)
{
struct cmd_info ci2 = *ci;
ci2.str = "hex";
return key_handle_focus(&ci2);
}
-DEF_CMD(comm_open, render_dir_open);
-static int render_dir_reload(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_dir_reload)
{
struct point **ptp = ci->pointp;
struct doc *d;
d->ops->load_file(d, NULL, -1, NULL);
return 1;
}
-DEF_CMD(comm_reload, render_dir_reload);
-
static void render_dir_register_map(void)
{
dr_map = key_alloc();
- key_add_range(dr_map, "Move-", "Move-\377", &comm_follow);
- key_add(dr_map, "Move-View-Small", &comm_move);
- key_add(dr_map, "Move-View-Large", &comm_move);
- key_add(dr_map, "Move-CursorXY", &comm_cursor);
- key_add(dr_map, "Click-1", &comm_cursor);
- key_add(dr_map, "Press-1", &comm_cursor);
- key_add(dr_map, "Move-Line", &comm_line);
- key_add(dr_map, "Move-Char", &comm_horiz);
- key_add(dr_map, "Move-Word", &comm_horiz);
- key_add(dr_map, "Move-WORD", &comm_horiz);
-
- key_add(dr_map, "Replace", &comm_follow);
-
- key_add(dr_map, "Chr-f", &comm_open);
- key_add(dr_map, "Chr-h", &comm_open);
- key_add(dr_map, "Chr-g", &comm_reload);
+ key_add_range(dr_map, "Move-", "Move-\377", &render_dir_follow_point);
+ key_add(dr_map, "Move-View-Small", &render_dir_move);
+ key_add(dr_map, "Move-View-Large", &render_dir_move);
+ key_add(dr_map, "Move-CursorXY", &render_dir_set_cursor);
+ key_add(dr_map, "Click-1", &render_dir_set_cursor);
+ key_add(dr_map, "Press-1", &render_dir_set_cursor);
+ key_add(dr_map, "Move-Line", &render_dir_move_line);
+ key_add(dr_map, "Move-Char", &render_dir_move_horiz);
+ key_add(dr_map, "Move-Word", &render_dir_move_horiz);
+ key_add(dr_map, "Move-WORD", &render_dir_move_horiz);
+
+ key_add(dr_map, "Replace", &render_dir_follow_point);
+
+ key_add(dr_map, "Chr-f", &render_dir_open);
+ key_add(dr_map, "Chr-h", &render_dir_open);
+ key_add(dr_map, "Chr-g", &render_dir_reload);
}
-static void render_dir_attach(struct pane *parent, struct point **ptp)
+static void do_render_dir_attach(struct pane *parent, struct point **ptp)
{
struct dir_data *dd = malloc(sizeof(*dd));
struct pane *p;
dd->top = NULL;
dd->bot = NULL;
dd->ignore_point = 0;
- dd->type.func = render_dir_notify;
+ dd->type = render_dir_notify;
dd->typenum = doc_add_view((*ptp)->doc, &dd->type);
p = pane_register(parent, 0, &render_dir_handle, dd, NULL);
dd->pane = p;
if (!dr_map)
render_dir_register_map();
}
-static int do_render_dir_attach(struct command *c, struct cmd_info *ci)
+
+DEF_CMD(render_dir_attach)
{
- render_dir_attach(ci->focus, ci->pointp);
+ do_render_dir_attach(ci->focus, ci->pointp);
return 1;
}
-DEF_CMD(comm_attach, do_render_dir_attach);
void edlib_init(struct editor *ed)
{
- key_add(ed->commands, "render-dir-attach", &comm_attach);
+ key_add(ed->commands, "render-dir-attach", &render_dir_attach);
}
};
static struct map *he_map;
-static void render_hex_attach(struct pane *parent, struct point **ptp);
+static void do_render_hex_attach(struct pane *parent, struct point **ptp);
static int put_str(struct pane *p, char *buf, char *attrs, int x, int y)
{
return 0;
}
-static int do_render_hex_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_handle)
{
struct pane *p = ci->home;
struct he_data *he = p->data;
struct pane *parent = ci->focus;
struct pane *c;
- render_hex_attach(parent, NULL);
+ do_render_hex_attach(parent, NULL);
c = pane_child(p);
if (c)
return pane_clone(c, parent->focus);
return hex_refresh(ci);
return 0;
}
-DEF_CMD(render_hex_handle, do_render_hex_handle);
-static int render_hex_notify(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_notify)
{
- struct he_data *he = container_of(c, struct he_data, type);
+ struct he_data *he = container_of(ci->comm, struct he_data, type);
if (strcmp(ci->key, "Replace") == 0) {
if (he->bot == NULL || ci->mark == NULL ||
return 0;
}
-static int render_hex_move(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_move)
{
struct pane *p = ci->home;
int rpt = RPT_NUM(ci);
pane_damaged(p, DAMAGED_CONTENT);
return 1;
}
-DEF_CMD(comm_move, render_hex_move);
-static int render_hex_follow_point(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_follow_point)
{
struct pane *p = ci->home;
struct he_data *he = p->data;
}
return 0;
}
-DEF_CMD(comm_follow, render_hex_follow_point);
-static int render_hex_set_cursor(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_set_cursor)
{
struct pane *p = ci->home;
struct point *pt = *ci->pointp;
pane_focus(p);
return 1;
}
-DEF_CMD(comm_cursor, render_hex_set_cursor);
-static int render_hex_move_line(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_move_line)
{
/* MV_CHAR 16 times repeat count */
struct cmd_info ci2 = {0};
return key_handle_focus(&ci2);
}
-DEF_CMD(comm_line, render_hex_move_line);
-static int render_hex_eol(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_hex_eol)
{
struct point *pt = *ci->pointp;
wint_t ch = 1;
he->ignore_point = 0;
return 1;
}
-DEF_CMD(comm_eol, render_hex_eol);
static void render_hex_register_map(void)
{
he_map = key_alloc();
- key_add_range(he_map, "Move-", "Move-\377", &comm_follow);
- key_add(he_map, "Move-View-Small", &comm_move);
- key_add(he_map, "Move-View-Large", &comm_move);
- key_add(he_map, "Move-CursorXY", &comm_cursor);
- key_add(he_map, "Click-1", &comm_cursor);
- key_add(he_map, "Press-1", &comm_cursor);
- key_add(he_map, "Move-Line", &comm_line);
+ key_add_range(he_map, "Move-", "Move-\377", &render_hex_follow_point);
+ key_add(he_map, "Move-View-Small", &render_hex_move);
+ key_add(he_map, "Move-View-Large", &render_hex_move);
+ key_add(he_map, "Move-CursorXY", &render_hex_set_cursor);
+ key_add(he_map, "Click-1", &render_hex_set_cursor);
+ key_add(he_map, "Press-1", &render_hex_set_cursor);
+ key_add(he_map, "Move-Line", &render_hex_move_line);
- key_add(he_map, "Move-EOL", &comm_eol);
- key_add(he_map, "Replace", &comm_follow);
+ key_add(he_map, "Move-EOL", &render_hex_eol);
+ key_add(he_map, "Replace", &render_hex_follow_point);
}
-static void render_hex_attach(struct pane *parent, struct point **ptp)
+static void do_render_hex_attach(struct pane *parent, struct point **ptp)
{
struct he_data *he = malloc(sizeof(*he));
struct pane *p;
he->top = NULL;
he->bot = NULL;
he->ignore_point = 0;
- he->type.func = render_hex_notify;
+ he->type = render_hex_notify;
he->typenum = doc_add_view((*ptp)->doc, &he->type);
p = pane_register(parent, 0, &render_hex_handle, he, NULL);
he->pane = p;
if (!he_map)
render_hex_register_map();
}
-static int do_render_hex_attach(struct command *c, struct cmd_info *ci)
+
+DEF_CMD(render_hex_attach)
{
- render_hex_attach(ci->focus, ci->pointp);
+ do_render_hex_attach(ci->focus, ci->pointp);
return 1;
}
-DEF_CMD(comm_attach, do_render_hex_attach);
void edlib_init(struct editor *ed)
{
- key_add(ed->commands, "render-hex-attach", &comm_attach);
+ key_add(ed->commands, "render-hex-attach", &render_hex_attach);
}
};
static struct map *rt_map;
-static void render_text_attach(struct pane *p, struct point **pt);
+static void do_render_text_attach(struct pane *p, struct point **pt);
static int rt_fore(struct doc *d, struct pane *p, struct mark *m, int *x, int *y, int draw)
{
return 0;
}
-static int do_render_text_handle(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_handle)
{
struct pane *p = ci->home;
struct rt_data *rt = p->data;
struct pane *parent = ci->focus;
struct pane *c;
- render_text_attach(parent, NULL);
+ do_render_text_attach(parent, NULL);
c = pane_child(p);
if (c)
return pane_clone(c, parent->focus);
return text_refresh(ci);
return 0;
}
-DEF_CMD(render_text_handle, do_render_text_handle);
-static int render_text_notify(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_notify)
{
- struct rt_data *rt = container_of(c, struct rt_data, type);
+ struct rt_data *rt = container_of(ci->comm, struct rt_data, type);
if (strcmp(ci->key, "Replace") == 0) {
if (ci->mark == rt->top)
return 0;
}
-static int render_text_move(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_move)
{
struct pane *p = ci->home;
int rpt = RPT_NUM(ci);
pane_damaged(p, DAMAGED_CONTENT);
return 1;
}
-DEF_CMD(comm_move, render_text_move);
-static int render_text_move_pos(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_move_pos)
{
struct pane *p = ci->home;
struct rt_data *rt = p->data;
pane_damaged(p, DAMAGED_CONTENT);
return 1;
}
-DEF_CMD(comm_move_pos, render_text_move_pos);
-static int render_text_follow_point(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_follow_point)
{
struct pane *p = ci->home;
struct rt_data *rt = p->data;
}
return 0;
}
-DEF_CMD(comm_follow, render_text_follow_point);
-static int render_text_set_cursor(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_set_cursor)
{
struct pane *p = ci->home;
struct point *pt = *ci->pointp;
pane_focus(p);
return 1;
}
-DEF_CMD(comm_cursor, render_text_set_cursor);
-static int render_text_move_line(struct command *c, struct cmd_info *ci)
+DEF_CMD(render_text_move_line)
{
struct pane *p = ci->home;
/* MV_EOL repeatedly, then move to match cursor */
pane_damaged(p, DAMAGED_CURSOR);
return 1;
}
-DEF_CMD(comm_line, render_text_move_line);
static void render_text_register_map(void)
{
rt_map = key_alloc();
- key_add_range(rt_map, "Move-", "Move-\377", &comm_follow);
- key_add(rt_map, "Move-View-Small", &comm_move);
- key_add(rt_map, "Move-View-Large", &comm_move);
- key_add(rt_map, "Move-View-Pos", &comm_move_pos);
- key_add(rt_map, "Move-CursorXY", &comm_cursor);
- key_add(rt_map, "Click-1", &comm_cursor);
- key_add(rt_map, "Press-1", &comm_cursor);
- key_add(rt_map, "Move-Line", &comm_line);
+ key_add_range(rt_map, "Move-", "Move-\377", &render_text_follow_point);
+ key_add(rt_map, "Move-View-Small", &render_text_move);
+ key_add(rt_map, "Move-View-Large", &render_text_move);
+ key_add(rt_map, "Move-View-Pos", &render_text_move_pos);
+ key_add(rt_map, "Move-CursorXY", &render_text_set_cursor);
+ key_add(rt_map, "Click-1", &render_text_set_cursor);
+ key_add(rt_map, "Press-1", &render_text_set_cursor);
+ key_add(rt_map, "Move-Line", &render_text_move_line);
- key_add(rt_map, "Replace", &comm_follow);
+ key_add(rt_map, "Replace", &render_text_follow_point);
}
-static void render_text_attach(struct pane *parent, struct point **ptp)
+static void do_render_text_attach(struct pane *parent, struct point **ptp)
{
struct rt_data *rt = malloc(sizeof(*rt));
struct pane *p;
rt->bot = NULL;
rt->ignore_point = 0;
rt->target_x = -1;
- rt->type.func = render_text_notify;
+ rt->type = render_text_notify;
rt->typenum = doc_add_view((*ptp)->doc, &rt->type);
p = pane_register(parent, 0, &render_text_handle, rt, NULL);
rt->pane = p;
if (!rt_map)
render_text_register_map();
}
-static int do_render_text_attach(struct command *c, struct cmd_info *ci)
+
+DEF_CMD(render_text_attach)
{
- render_text_attach(ci->focus, ci->pointp);
+ do_render_text_attach(ci->focus, ci->pointp);
return 1;
}
-DEF_CMD(comm_attach, do_render_text_attach);
void edlib_init(struct editor *ed)
{
- key_add(ed->commands, "render-text-attach", &comm_attach);
+ key_add(ed->commands, "render-text-attach", &render_text_attach);
}