]> git.neil.brown.name Git - edlib.git/commitdiff
Create a command for defining new named commands.
authorNeilBrown <neil@brown.name>
Thu, 3 Dec 2015 22:48:35 +0000 (09:48 +1100)
committerNeilBrown <neil@brown.name>
Wed, 9 Dec 2015 09:02:59 +0000 (20:02 +1100)
Signed-off-by: NeilBrown <neil@brown.name>
core-editor.c
core.h
display-ncurses.c

index 0e5ccdd8d495338b65b6014dd0752467c1c45497..f181dd092565d11db03c189b0f1be8154580da35 100644 (file)
@@ -25,6 +25,14 @@ DEF_CMD(global_set_attr)
        return 1;
 }
 
+DEF_CMD(global_set_command)
+{
+       struct editor *ed = container_of(ci->home, struct editor, root);
+
+       key_add(ed->commands, ci->str, ci->comm2);
+       return 1;
+}
+
 struct pane *editor_new(void)
 {
        struct editor *ed = calloc(sizeof(*ed), 1);
@@ -32,6 +40,7 @@ struct pane *editor_new(void)
        if (!ed_map) {
                ed_map = key_alloc();
                key_add(ed_map, "global-set-attr", &global_set_attr);
+               key_add(ed_map, "global-set-command", &global_set_command);
        }
 
        pane_init(&ed->root, NULL, NULL);
diff --git a/core.h b/core.h
index 0c06a99eda9864831826642358b12d5bb63b0242..1fe45535797fb5892051be58c427101b7628fbdb 100644 (file)
--- a/core.h
+++ b/core.h
@@ -492,6 +492,21 @@ static inline int call5(char *key, struct pane *focus, int numeric, struct mark
        return key_handle_focus(&ci);
 }
 
+static inline int call_comm(char *key, struct pane *focus, int numeric, struct mark *m,
+                           char *str, int extra, struct command *comm)
+{
+       struct cmd_info ci = {0};
+
+       ci.key = key;
+       ci.focus = focus;
+       ci.numeric = numeric;
+       ci.mark = m;
+       ci.str = str;
+       ci.extra = extra;
+       ci.comm2 = comm;
+       return key_handle_focus(&ci);
+}
+
 static inline struct mark *call_mark(char *key, struct pane *focus, int numeric,
                                     struct mark *m, int extra)
 {
index 438427ac3637dfebdc3b222c3b9f24de396afa66..f694e974ee7eaef13ea2a99416501d67e39e98fe 100644 (file)
@@ -399,5 +399,6 @@ DEF_CMD(display_ncurses)
 
 void edlib_init(struct editor *ed)
 {
-       key_add(ed->commands, "display-ncurses", &display_ncurses);
+       call_comm("global-set-command", &ed->root, 0, NULL, "display-ncurses",
+                 0, &display_ncurses);
 }