]> git.neil.brown.name Git - edlib.git/commitdiff
Add key_lookup_prefix and use for module loading.
authorNeilBrown <neil@brown.name>
Thu, 24 Mar 2016 06:32:41 +0000 (17:32 +1100)
committerNeilBrown <neil@brown.name>
Thu, 24 Mar 2016 06:40:25 +0000 (17:40 +1100)
This will allow other module loaders to register.

Signed-off-by: NeilBrown <neil@brown.name>
core-editor.c
core-keymap.c
core.h

index 36903719fc615cbbb335dddce3790fd1b9e083ed..da829a47993d07672a3c12b9060332728cadb2ab 100644 (file)
@@ -60,6 +60,7 @@ DEF_CMD(global_get_command)
 
 DEF_CMD(editor_load_module)
 {
+       struct map *map = ci->home->data;
        char *name = ci->str;
        char buf[PATH_MAX];
        void *h;
@@ -72,13 +73,14 @@ DEF_CMD(editor_load_module)
         *
         */
        h = dlopen(buf, RTLD_NOW | RTLD_GLOBAL);
-       if (!h)
-               return 0;
-       s = dlsym(h, "edlib_init");
-       if (!s)
-               return 0;
-       s(ci->home);
-       return 1;
+       if (h) {
+               s = dlsym(h, "edlib_init");
+               if (s) {
+                       s(ci->home);
+                       return 1;
+               }
+       }
+       return key_lookup_prefix(map, ci);
 }
 
 struct pane *editor_new(void)
@@ -97,4 +99,3 @@ struct pane *editor_new(void)
 
        return ed;
 }
-
index f9663f9940d5eb0e8b7828f3719999b479f151bd..2afceee47e5d904fa258ffc792fb34fbd3968c53 100644 (file)
@@ -286,6 +286,26 @@ int key_lookup(struct map *m, const struct cmd_info *ci)
        return comm->func(ci);
 }
 
+int key_lookup_prefix(struct map *m, const struct cmd_info *ci)
+{
+       int pos = key_find(m, ci->key);
+       struct command *comm, *prev = NULL;
+       int len = strlen(ci->key);
+
+       while (pos < m->size && strncmp(m->keys[pos], ci->key, len) == 0) {
+               comm = GETCOMM(m->comms[pos]);
+               if (comm && comm != prev) {
+                       int ret;
+                       ((struct cmd_info*)ci)->comm = comm;
+                       ret = comm->func(ci);
+                       if (ret)
+                               return ret;
+                       prev = comm;
+               }
+       }
+       return 0;
+}
+
 int key_lookup_cmd_func(const struct cmd_info *ci)
 {
        struct lookup_cmd *l = container_of(ci->comm, struct lookup_cmd, c);
diff --git a/core.h b/core.h
index fe19c3b2c426d8c6d3944e459a92b52acba574a0..6146e646a1c7b002ee3392e4f71346c47e0987c3 100644 (file)
--- a/core.h
+++ b/core.h
@@ -282,6 +282,7 @@ struct map *key_alloc(void);
 void key_free(struct map *m);
 int key_handle(const struct cmd_info *ci);
 int key_lookup(struct map *m, const const struct cmd_info *ci);
+int key_lookup_prefix(struct map *m, const const struct cmd_info *ci);
 struct command *key_lookup_cmd(struct map *m, char *c);
 void key_add(struct map *map, char *k, struct command *comm);
 void key_add_range(struct map *map, char *first, char *last,