@@ -17,6 +17,21 @@ made using this module affect the behaviour of both the interpreter's
1717interactive prompt and the prompts offered by the built-in :func: `input `
1818function.
1919
20+ Compatible keybindings
21+ ----------------------
22+
23+ To support compatible keybindings between GNU readline and Libedit, use the
24+ following backslashed escape sequences or octal escape sequences in quotes. ::
25+
26+ \a bell
27+ \b backspace
28+ \f form feed
29+ \n newline
30+ \r carriage return
31+ \t horizontal tab
32+ \v vertical tab
33+ \nnn octal escape sequences
34+
2035Readline keybindings may be configured via an initialization file, typically
2136``.inputrc `` in your home directory. See `Readline Init File
2237<https://tiswww.cwru.edu/php/chet/readline/rluserman.html#Readline-Init-File> `_
@@ -39,10 +54,10 @@ Readline library in general.
3954 If you use *editline */``libedit `` readline emulation on macOS, the
4055 initialization file located in your home directory is named
4156 ``.editrc ``. For example, the following content in ``~/.editrc `` will
42- turn ON *vi * keybindings and TAB completion::
57+ turn ON *vi * keybindings and " \\ t"( :kbd: ` tab `) completion::
4358
4459 python:bind -v
45- python:bind ^I rl_complete
60+ python:bind "\t" rl_complete
4661
4762
4863Init file
@@ -56,6 +71,16 @@ The following functions relate to the init file and user configuration:
5671 Execute the init line provided in the *string * argument. This calls
5772 :c:func: `rl_parse_and_bind ` in the underlying library.
5873
74+ .. note ::
75+ The syntax and command of *string * argument may be different depends on the readline library.
76+
77+ For GNU readline::
78+
79+ readline.parse_and_bind(r'"\t": complete')
80+
81+ For Libedit::
82+
83+ readline.parse_and_bind(r'bind "\t" rl_complete')
5984
6085.. function :: read_init_file([filename])
6186
@@ -348,7 +373,12 @@ support history save/restore. ::
348373 self.init_history(histfile)
349374
350375 def init_history(self, histfile):
351- readline.parse_and_bind("tab: complete")
376+
377+ readline_doc = getattr(readline, '__doc__', '')
378+ if readline_doc is not None and 'libedit' in readline_doc:
379+ readline.parse_and_bind(r'bind "\t" rl_complete')
380+ else:
381+ readline.parse_and_bind(r'"\t": complete')
352382 if hasattr(readline, "read_history_file"):
353383 try:
354384 readline.read_history_file(histfile)
0 commit comments