mirror of https://github.com/python/cpython
Only set rl_completion_display_matches_hook if there
is a Python hook function. Fixes #1425.
This commit is contained in:
parent
abfe45368c
commit
f354894e7b
|
@ -38,6 +38,10 @@
|
|||
extern char **completion_matches(char *, rl_compentry_func_t *);
|
||||
#endif
|
||||
|
||||
static void
|
||||
on_completion_display_matches_hook(char **matches,
|
||||
int num_matches, int max_length);
|
||||
|
||||
|
||||
/* Exported function to send one line to readline's init file parser */
|
||||
|
||||
|
@ -208,8 +212,17 @@ static PyObject *pre_input_hook = NULL;
|
|||
static PyObject *
|
||||
set_completion_display_matches_hook(PyObject *self, PyObject *args)
|
||||
{
|
||||
return set_hook("completion_display_matches_hook",
|
||||
PyObject *result = set_hook("completion_display_matches_hook",
|
||||
&completion_display_matches_hook, args);
|
||||
#ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK
|
||||
/* We cannot set this hook globally, since it replaces the
|
||||
default completion display. */
|
||||
rl_completion_display_matches_hook =
|
||||
completion_display_matches_hook ?
|
||||
(rl_compdisp_func_t *)on_completion_display_matches_hook : 0;
|
||||
#endif
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(doc_set_completion_display_matches_hook,
|
||||
|
@ -668,7 +681,6 @@ static void
|
|||
on_completion_display_matches_hook(char **matches,
|
||||
int num_matches, int max_length)
|
||||
{
|
||||
if (completion_display_matches_hook != NULL) {
|
||||
int i;
|
||||
PyObject *m, *s;
|
||||
PyObject *r;
|
||||
|
@ -701,7 +713,6 @@ on_completion_display_matches_hook(char **matches,
|
|||
PyGILState_Release(gilstate);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* C function to call the Python completer. */
|
||||
|
@ -781,10 +792,6 @@ setup_readline(void)
|
|||
rl_bind_key_in_map ('\t', rl_complete, emacs_meta_keymap);
|
||||
rl_bind_key_in_map ('\033', rl_complete, emacs_meta_keymap);
|
||||
/* Set our hook functions */
|
||||
#ifdef HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK
|
||||
rl_completion_display_matches_hook =
|
||||
(rl_compdisp_func_t *)on_completion_display_matches_hook;
|
||||
#endif
|
||||
rl_startup_hook = (Function *)on_startup_hook;
|
||||
#ifdef HAVE_RL_PRE_INPUT_HOOK
|
||||
rl_pre_input_hook = (Function *)on_pre_input_hook;
|
||||
|
|
Loading…
Reference in New Issue