From c87869bef7553199a874a7af304d2a4b13f0f689 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Tue, 13 Oct 2020 20:30:03 +0200 Subject: Cleanup Prevent the last fuck-up from happening again. --- json-rpc-shell.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/json-rpc-shell.c b/json-rpc-shell.c index 2ddb95c..adcf310 100644 --- a/json-rpc-shell.c +++ b/json-rpc-shell.c @@ -663,6 +663,14 @@ input_el_install_prompt (struct input_el *self) static unsigned char input_el_on_complete (EditLine *editline, int key); +static void +input_el_addbind (EditLine *editline, const char *name, const char *desc, + unsigned char (*function) (EditLine *, int), const char *binding) +{ + el_set (editline, EL_ADDFN, name, desc, function); + el_set (editline, EL_BIND, binding, name, NULL); +} + static void input_el_start (struct input *input, const char *program_name) { @@ -681,20 +689,15 @@ input_el_start (struct input *input, const char *program_name) el_set (self->editline, EL_BIND, "^u", "vi-kill-line-prev", NULL); // It's probably better to handle these ourselves - el_set (self->editline, EL_ADDFN, - "send-line", "Send line", input_el_on_return); - el_set (self->editline, EL_BIND, "\n", "send-line", NULL); - el_set (self->editline, EL_ADDFN, - "run-editor", "Run editor to edit line", input_el_on_run_editor); - el_set (self->editline, EL_BIND, "M-e", "run-editor", NULL); - - el_set (self->editline, EL_ADDFN, - "complete", "Complete word", input_el_on_complete); - el_set (self->editline, EL_BIND, "\t", "complete", NULL); - - el_set (self->editline, EL_ADDFN, - "newline-insert", "Insert a newline", input_el_on_newline_insert); - el_set (self->editline, EL_BIND, "M-\n", "newline-insert", NULL); + input_el_addbind (self->editline, "send-line", "Send line", + input_el_on_return, "\n"); + input_el_addbind (self->editline, "run-editor", "Run editor to edit line", + input_el_on_run_editor, "M-e"); + + input_el_addbind (self->editline, "complete", "Complete word", + input_el_on_complete, "\t"); + input_el_addbind (self->editline, "newline-insert", "Insert a newline", + input_el_on_newline_insert, "M-\n"); // Source the user's defaults file el_source (self->editline, NULL); -- cgit v1.2.3-70-g09d2