Skip to content

Commit

Permalink
Prevent failures of libedit programs
Browse files Browse the repository at this point in the history
Programs linked with libedit (editline) lack rl_bind_keyseq and
will fail if it's executed. To avoid this, first test if the
function is available.
  • Loading branch information
dspinellis committed Nov 14, 2023
1 parent 8026a3d commit fc34812
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ai_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ setup(void)
// Add named function, making it available to the user
rl_add_defun("query-ai", query_ai, -1);

// Bind it to Emacs and vi
if (config.binding_emacs)
/*
* Bind the function to Emacs and vi.
* Programs linked with libedit (editline) lack rl_bind_keyseq and
* will fail if it's executed. To avoid this, first test if the
* function i* s available.
*/
if (config.binding_emacs && dlsym(RTLD_DEFAULT, "rl_bind_keyseq"))
rl_bind_keyseq(config.binding_emacs, query_ai);
if (config.binding_vi)
rl_bind_key_in_map(*config.binding_vi, query_ai, vi_movement_keymap_ptr);
Expand Down

0 comments on commit fc34812

Please sign in to comment.