]> git.neil.brown.name Git - edlib.git/commitdiff
All ed->commands to be accessed by key_handle
authorNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:15:44 +0000 (13:15 +1100)
committerNeilBrown <neil@brown.name>
Thu, 10 Dec 2015 02:54:09 +0000 (13:54 +1100)
This makes sense and means we don't need to find the 'ed'.

Signed-off-by: NeilBrown <neil@brown.name>
core-editor.c
edlib.c
emacs-search.c
lang-python.c
lib-line-count.c
lib-view.c
mode-emacs.c
render-hex.c

index cad2ef85503fac5667bc36c11bb559d261fd7e1d..6b91d0e25d38dda1346a82e67bfed8b852e3748b 100644 (file)
 
 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 877ee22636c0c18eb01bcd5b308327ba85ad9242..c50cb7344c6b057cf40d163903d24661196c96d0 100644 (file)
--- 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);
index 6dfb09b933b8119a2824b7fdf81f2abdea006c89..2c3e69a082760a3ebb3034fa50460a43d93c7dca 100644 (file)
@@ -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) {
index 29a56ff53e226f5c9f8416082649cae9ca6a374b..ed2f344b967673437c946cb99753a0694f5142cf 100644 (file)
@@ -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();
index 045c9153a1b95f1658fbd3e18ada6435e681042e..1b85c3390c3efce9e759dde16b7c70c468c48265 100644 (file)
@@ -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);
index 3b6b94f11597c69df500e9e7716ff326871cd801..811e4c6c35cf97ae527c85f81087ed5f12c8ec66 100644 (file)
@@ -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");
index 4479d48047ed6663187b3912f317e7ccf8287e19..2d1b0921d52082e08905d39994b1f14a4fb80aa2 100644 (file)
@@ -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);
 
index c052937b710ded0dc00458e9e79e7b10d642a58f..9148169d90599a679f51ebcba1e4348ace51d02d 100644 (file)
@@ -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;