Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2f082e

Browse files
zvezdanned-deily
authored andcommitted
bpo-13631: Fix the order of initialization for readline libedit on macOS. (GH-6915)
The editline emulation needs to be initialized *after* the name is defined. This fixes the long open issue.
1 parent 64fddc4 commit c2f082e

5 files changed

Lines changed: 23 additions & 8 deletions

File tree

Doc/library/readline.rst

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,32 @@ made using this module affect the behaviour of both the interpreter's
1717
interactive prompt and the prompts offered by the built-in :func:`input`
1818
function.
1919

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+
2027
.. note::
2128

2229
The underlying Readline library API may be implemented by
2330
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
2532
at run time.
2633

2734
The configuration file for ``libedit`` is different from that
2835
of GNU readline. If you programmatically load configuration strings
2936
you can check for the text "libedit" in :const:`readline.__doc__`
3037
to differentiate between GNU readline and libedit.
3138

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
3846

3947

4048
Init file

Doc/tools/susp-ignored.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ library/profile,,:lineno,filename:lineno(function)
187187
library/pyexpat,,:elem1,<py:elem1 />
188188
library/pyexpat,,:py,"xmlns:py = ""http://www.python.org/ns/"">"
189189
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"
190192
library/smtplib,,:port,method must support that as well as a regular host:port
191193
library/socket,,::,'5aef:2b::8'
192194
library/socket,,:can,"return (can_id, can_dlc, data[:can_dlc])"

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,7 @@ Gabriel de Perthuis
12291229
Tim Peters
12301230
Benjamin Peterson
12311231
Joe Peterson
1232+
Zvezdan Petkovic
12321233
Ulrich Petri
12331234
Chris Petrilli
12341235
Roumen Petrov
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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.

Modules/readline.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,9 @@ setup_readline(readlinestate *mod_state)
10781078
Py_FatalError("not enough memory to save locale");
10791079
#endif
10801080

1081+
/* The name must be defined before initialization */
1082+
rl_readline_name = "python";
1083+
10811084
#ifdef __APPLE__
10821085
/* the libedit readline emulation resets key bindings etc
10831086
* when calling rl_initialize. So call it upfront
@@ -1099,7 +1102,6 @@ setup_readline(readlinestate *mod_state)
10991102

11001103
using_history();
11011104

1102-
rl_readline_name = "python";
11031105
/* Force rebind of TAB to insert-tab */
11041106
rl_bind_key('\t', rl_insert);
11051107
/* Bind both ESC-TAB and ESC-ESC to the completion function */

0 commit comments

Comments
 (0)