bpo-13631: Fix the order of initialization for readline libedit on ma… · python/cpython@c2f082e (original) (raw)

5 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -17,24 +17,32 @@ made using this module affect the behaviour of both the interpreter's
17 17 interactive prompt and the prompts offered by the built-in :func:`input`
18 18 function.
19 19
20 +Readline keybindings may be configured via an initialization file, typically
21 +``.inputrc`` in your home directory. See `Readline Init File
22 +https://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html#SEC9`_
23 +in the GNU Readline manual for information about the format and
24 +allowable constructs of that file, and the capabilities of the
25 +Readline library in general.
26 +
20 27 .. note::
21 28
22 29 The underlying Readline library API may be implemented by
23 30 the ``libedit`` library instead of GNU readline.
24 - On MacOS X the :mod:`readline` module detects which library is being used
31 + On macOS the :mod:`readline` module detects which library is being used
25 32 at run time.
26 33
27 34 The configuration file for ``libedit`` is different from that
28 35 of GNU readline. If you programmatically load configuration strings
29 36 you can check for the text "libedit" in :const:`readline.__doc__`
30 37 to differentiate between GNU readline and libedit.
31 38
32 -Readline keybindings may be configured via an initialization file, typically
33 -``.inputrc`` in your home directory. See `Readline Init File
34 -https://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html#SEC9`_
35 -in the GNU Readline manual for information about the format and
36 -allowable constructs of that file, and the capabilities of the
37 -Readline library in general.
39 + If you use *editline*/``libedit`` readline emulation on macOS, the
40 + initialization file located in your home directory is named
41 + ``.editrc``. For example, the following content in ``~/.editrc`` will
42 + turn ON *vi* keybindings and TAB completion::
43 +
44 + python:bind -v
45 + python:bind ^I rl_complete
38 46
39 47
40 48 Init file
Original file line number Diff line number Diff line change
@@ -187,6 +187,8 @@ library/profile,,:lineno,filename:lineno(function)
187 187 library/pyexpat,,:elem1,<py:elem1 />
188 188 library/pyexpat,,:py,"xmlns:py = """ title="undefined" rel="noopener noreferrer">http://www.python.org/ns/"">"
189 189 library/random,,:len,new_diff = mean(combined[:len(drug)]) - mean(combined[len(drug):])
190 +library/readline,,:bind,"python:bind -v"
191 +library/readline,,:bind,"python:bind ^I rl_complete"
190 192 library/smtplib,,:port,method must support that as well as a regular host:port
191 193 library/socket,,::,'5aef:2b::8'
192 194 library/socket,,:can,"return (can_id, can_dlc, data[:can_dlc])"
Original file line number Diff line number Diff line change
@@ -1229,6 +1229,7 @@ Gabriel de Perthuis
1229 1229 Tim Peters
1230 1230 Benjamin Peterson
1231 1231 Joe Peterson
1232 +Zvezdan Petkovic
1232 1233 Ulrich Petri
1233 1234 Chris Petrilli
1234 1235 Roumen Petrov
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1 +The .editrc file in user's home directory is now processed correctly during
2 +the readline initialization through editline emulation on macOS.
Original file line number Diff line number Diff line change
@@ -1078,6 +1078,9 @@ setup_readline(readlinestate *mod_state)
1078 1078 Py_FatalError("not enough memory to save locale");
1079 1079 #endif
1080 1080
1081 +/* The name must be defined before initialization */
1082 +rl_readline_name = "python";
1083 +
1081 1084 #ifdef __APPLE__
1082 1085 /* the libedit readline emulation resets key bindings etc
1083 1086 * when calling rl_initialize. So call it upfront
@@ -1099,7 +1102,6 @@ setup_readline(readlinestate *mod_state)
1099 1102
1100 1103 using_history();
1101 1104
1102 -rl_readline_name = "python";
1103 1105 /* Force rebind of TAB to insert-tab */
1104 1106 rl_bind_key('\t', rl_insert);
1105 1107 /* Bind both ESC-TAB and ESC-ESC to the completion function */