From 2959139960c4ebad04cc78aeecb17b61eb887e55 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Thu, 10 Dec 2015 13:15:44 +1100 Subject: [PATCH] All ed->commands to be accessed by key_handle This makes sense and means we don't need to find the 'ed'. Signed-off-by: NeilBrown --- core-editor.c | 13 +++++++++++-- edlib.c | 4 ++-- emacs-search.c | 2 +- lang-python.c | 2 +- lib-line-count.c | 2 +- lib-view.c | 3 +-- mode-emacs.c | 2 +- render-hex.c | 7 +++---- 8 files changed, 21 insertions(+), 14 deletions(-) diff --git a/core-editor.c b/core-editor.c index cad2ef85..6b91d0e2 100644 --- a/core-editor.c +++ b/core-editor.c @@ -12,7 +12,16 @@ struct map *ed_map; -DEF_LOOKUP_CMD(ed_handle, ed_map); +DEF_CMD(ed_handle) +{ + struct editor *ed = container_of(ci->home, struct editor, root); + int ret; + + ret = key_lookup(ed_map, ci); + if (ret) + return ret; + return key_lookup(ed->commands, ci); +} DEF_CMD(null_display_handle) { @@ -44,7 +53,7 @@ struct pane *editor_new(void) } pane_init(&ed->root, NULL, NULL); - ed->root.handle = &ed_handle.c; + ed->root.handle = &ed_handle; ed->root.data = NULL; /* The first child of the root is the 'null_display' diff --git a/edlib.c b/edlib.c index 877ee226..c50cb734 100644 --- a/edlib.c +++ b/edlib.c @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) cr.c = take_pane; cr.p = NULL; ci.comm2 = &cr.c; - if (!key_lookup(ed->commands, &ci)) + if (key_handle(&ci) <= 0) exit(1); root = cr.p; global = pane_attach(root, "messageline", NULL, NULL); @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) ci.home = ci.focus = p; ci.key = "python-load"; ci.str = "python/test.py"; - key_lookup(ed->commands, &ci); + key_handle(&ci); pane_refresh(&ed->root); event_base_dispatch(base); diff --git a/emacs-search.c b/emacs-search.c index 6dfb09b9..2c3e69a0 100644 --- a/emacs-search.c +++ b/emacs-search.c @@ -195,7 +195,7 @@ REDEF_CMD(search_again) str = doc_getstr(esi->search, NULL); ci2.str = str; ci2.key = "text-search"; - ret = key_lookup(pane2ed(esi->target)->commands, &ci2); + ret = key_handle(&ci2); if (ret == 0) pfx = "Search (unavailable): "; else if (ret == -2) { diff --git a/lang-python.c b/lang-python.c index 29a56ff5..ed2f344b 100644 --- a/lang-python.c +++ b/lang-python.c @@ -87,7 +87,7 @@ DEF_CMD(python_load) Ed = Pane_Frompane(&ed->root); PyDict_SetItemString(globals, "editor", Ed); - PyDict_SetItemString(globals, "pane", Pane_Frompane(ci->home)); + PyDict_SetItemString(globals, "pane", Pane_Frompane(ci->focus)); PyDict_SetItemString(globals, "edlib", EdlibModule); PyRun_FileExFlags(fp, fname, Py_file_input, globals, globals, 0, NULL); PyErr_Print(); diff --git a/lib-line-count.c b/lib-line-count.c index 045c9153..1b85c339 100644 --- a/lib-line-count.c +++ b/lib-line-count.c @@ -218,7 +218,7 @@ done: DEF_CMD(count_lines) { - struct doc *d = doc_from_pane(ci->home); + struct doc *d = doc_from_pane(ci->focus); /* FIXME optimise this away most of the time */ count_calculate(d, NULL, NULL); diff --git a/lib-view.c b/lib-view.c index 3b6b94f1..811e4c6c 100644 --- a/lib-view.c +++ b/lib-view.c @@ -48,7 +48,6 @@ static int view_refresh(struct cmd_info *ci) char msg[100]; int i; int mid; - struct editor *ed = pane2ed(ci->home); struct doc *d = doc_from_pane(ci->home); pane_check_size(p); @@ -65,7 +64,7 @@ static int view_refresh(struct cmd_info *ci) ci2.key = "CountLines"; ci2.home = ci2.focus = p; ci2.mark = m; - key_lookup(ed->commands, &ci2); + key_handle(&ci2); ln = attr_find_int(*mark_attr(m), "lines"); l = attr_find_int(d->attrs, "lines"); diff --git a/mode-emacs.c b/mode-emacs.c index 4479d480..2d1b0921 100644 --- a/mode-emacs.c +++ b/mode-emacs.c @@ -573,7 +573,7 @@ DEF_CMD(emacs_search) ci2.mark = m; ci2.str = ci->str; ci2.key = "text-search"; - ret = key_lookup(pane2ed(ci->focus)->commands, &ci2); + ret = key_handle(&ci2); if (ret > 1) call3("Move-to", ci->focus, 0, m); diff --git a/render-hex.c b/render-hex.c index c052937b..9148169d 100644 --- a/render-hex.c +++ b/render-hex.c @@ -81,7 +81,6 @@ DEF_CMD(render_hex_notify) DEF_CMD(render_hex_eol) { struct doc *d = doc_from_pane(ci->home); - struct editor *ed = pane2ed(ci->home); wint_t ch = 1; int rpt = RPT_NUM(ci); int pos; @@ -90,7 +89,7 @@ DEF_CMD(render_hex_eol) ci2.key = "CountLines"; ci2.home = ci2.focus = ci->home; ci2.mark = ci->mark; - key_lookup(ed->commands, &ci2); + key_handle(&ci2); pos = attr_find_int(*mark_attr(ci->mark), "chars"); pos = attr_find_int(*mark_attr(ci->mark), "chars"); @@ -135,7 +134,7 @@ DEF_CMD(render_line) ci2.key = "CountLines"; ci2.home = ci2.focus = ci->home; ci2.mark = ci->mark; - key_lookup(d->ed->commands, &ci2); + key_handle(&ci2); pos = attr_find_int(*mark_attr(ci->mark), "chars"); buf_init(&ret); @@ -200,7 +199,7 @@ DEF_CMD(render_line_prev) ci2.key = "CountLines"; ci2.home = ci2.focus = ci->home; ci2.mark = ci->mark; - key_lookup(d->ed->commands, &ci2); + key_handle(&ci2); from = attr_find_int(*mark_attr(ci->mark), "chars"); to = from & ~0xF; -- 2.39.5