Skip to content

Commit 52d1b4e

Browse files
committed
#9907: call rl_initialize early when using editline on OSX
editline rl_initialize apparently discards any mappings done before it is called, which makes tab revert to file completion instead of inserting a tab. So now on OSX we call rl_initialize first if we are using readline, and then re-read the users .editrc (if any) afterward so they can still override our defaults. Patch by Ned Deily, modified by Ronald Oussoren.
1 parent c539a2a commit 52d1b4e

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Core and Builtins
2020
Library
2121
-------
2222

23+
- Issue $9907: Fix tab handling on OSX when using editline by calling
24+
rl_initialize first, then setting our custom defaults, then reading .editrc.
25+
2326
- Issue #4188: Avoid creating dummy thread objects when logging operations
2427
from the threading module (with the internal verbose flag activated).
2528

Modules/readline.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,14 @@ setup_readline(void)
889889
Py_FatalError("not enough memory to save locale");
890890
#endif
891891

892+
#ifdef __APPLE__
893+
/* the libedit readline emulation resets key bindings etc
894+
* when calling rl_initialize. So call it upfront
895+
*/
896+
if (using_libedit_emulation)
897+
rl_initialize();
898+
#endif /* __APPLE__ */
899+
892900
using_history();
893901

894902
rl_readline_name = "python";
@@ -920,8 +928,13 @@ setup_readline(void)
920928
* XXX: A bug in the readline-2.2 library causes a memory leak
921929
* inside this function. Nothing we can do about it.
922930
*/
923-
rl_initialize();
924-
931+
#ifdef __APPLE__
932+
if (using_libedit_emulation)
933+
rl_read_init_file(NULL);
934+
else
935+
#endif /* __APPLE__ */
936+
rl_initialize();
937+
925938
RESTORE_LOCALE(saved_locale)
926939
}
927940

0 commit comments

Comments
 (0)