degesch: fix binding to our own fns from inputrc

This commit is contained in:
Přemysl Eric Janouch 2016-03-10 00:06:28 +01:00
parent dc248b8840
commit a1c4a1ef3a
1 changed files with 16 additions and 4 deletions

View File

@ -186,6 +186,7 @@ free_terminal (void)
struct input
{
struct input_vtable *vtable; ///< Virtual methods
void (*add_functions) (void *); ///< Define functions for binding
void *user_data; ///< User data for callbacks
};
@ -461,6 +462,9 @@ input_rl_start (void *input, const char *program_name)
rl_attempted_completion_function = app_readline_completion;
hard_assert (self->prompt != NULL);
// The inputrc is read before any callbacks are called, so we need to
// register all functions that our user may want to map up front
self->super.add_functions (self->super.user_data);
rl_callback_handler_install (self->prompt, on_readline_input);
self->prompt_shown = 1;
@ -2056,6 +2060,7 @@ app_context_init (struct app_context *self)
free (encoding);
self->input = input_new ();
self->input->user_data = self;
str_vector_init (&self->pending_input);
str_init (&self->input_buffer);
@ -11830,10 +11835,10 @@ on_start_paste_mode (int count, int key, void *user_data)
}
static void
bind_common_keys (struct app_context *ctx)
input_add_functions (void *user_data)
{
struct input *self = ctx->input;
#define XX(...) CALL_ (self, register_fn, __VA_ARGS__, ctx);
struct app_context *ctx = user_data;
#define XX(...) CALL_ (ctx->input, register_fn, __VA_ARGS__, ctx);
XX ("previous-buffer", "Previous buffer", on_previous_buffer)
XX ("next-buffer", "Next buffer", on_next_buffer)
XX ("goto-buffer", "Go to buffer", on_goto_buffer)
@ -11847,7 +11852,12 @@ bind_common_keys (struct app_context *ctx)
XX ("insert-attribute", "mIRC formatting", on_insert_attribute)
XX ("start-paste-mode", "Bracketed paste", on_start_paste_mode)
#undef XX
}
static void
bind_common_keys (struct app_context *ctx)
{
struct input *self = ctx->input;
CALL_ (self, bind_control, 'p', "previous-buffer");
CALL_ (self, bind_control, 'n', "next-buffer");
@ -12064,8 +12074,9 @@ app_editline_init (struct input_el *self)
el_wset (self->editline, EL_ADDFN,
L"complete", L"Complete word", on_editline_complete);
bind_common_keys (g_ctx);
struct input *input = &self->super;
input->add_functions (input->user_data);
bind_common_keys (g_ctx);
// Move native history commands
CALL_ (input, bind_meta, 'p', "ed-prev-history");
@ -12825,6 +12836,7 @@ main (int argc, char *argv[])
// Initialize input so that we can switch to new buffers
refresh_prompt (&ctx);
ctx.input->add_functions = input_add_functions;
CALL_ (ctx.input, start, argv[0]);
toggle_bracketed_paste (true);
reset_autoaway (&ctx);