]> granicus.if.org Git - python/commitdiff
bpo-13631: Fix the order of initialization for readline libedit on macOS. (GH-6915)
authorZvezdan Petkovic <zpetkovic@acm.org>
Thu, 17 May 2018 06:45:10 +0000 (02:45 -0400)
committerNed Deily <nad@python.org>
Thu, 17 May 2018 06:45:10 +0000 (02:45 -0400)
The editline emulation needs to be initialized *after* the name is
defined. This fixes the long open issue.

Doc/library/readline.rst
Doc/tools/susp-ignored.csv
Misc/ACKS
Misc/NEWS.d/next/macOS/2018-05-16-13-25-58.bpo-13631.UIjDyY.rst [new file with mode: 0644]
Modules/readline.c

index 837816e952ad566954c664b7b563df5615efbed8..16c28cf7d02fb958137c23e77533f39c8f442ce2 100644 (file)
@@ -17,11 +17,18 @@ made using  this module affect the behaviour of both the interpreter's
 interactive prompt  and the prompts offered by the built-in :func:`input`
 function.
 
+Readline keybindings may be configured via an initialization file, typically
+``.inputrc`` in your home directory.  See `Readline Init File
+<https://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html#SEC9>`_
+in the GNU Readline manual for information about the format and
+allowable constructs of that file, and the capabilities of the
+Readline library in general.
+
 .. note::
 
   The underlying Readline library API may be implemented by
   the ``libedit`` library instead of GNU readline.
-  On MacOS X the :mod:`readline` module detects which library is being used
+  On macOS the :mod:`readline` module detects which library is being used
   at run time.
 
   The configuration file for ``libedit`` is different from that
@@ -29,12 +36,13 @@ function.
   you can check for the text "libedit" in :const:`readline.__doc__`
   to differentiate between GNU readline and libedit.
 
-Readline keybindings may be configured via an initialization file, typically
-``.inputrc`` in your home directory.  See `Readline Init File
-<https://cnswww.cns.cwru.edu/php/chet/readline/rluserman.html#SEC9>`_
-in the GNU Readline manual for information about the format and
-allowable constructs of that file, and the capabilities of the
-Readline library in general.
+  If you use *editline*/``libedit`` readline emulation on macOS, the
+  initialization file located in your home directory is named
+  ``.editrc``. For example, the following content in ``~/.editrc`` will
+  turn ON *vi* keybindings and TAB completion::
+
+    python:bind -v
+    python:bind ^I rl_complete
 
 
 Init file
index cfdd5266c51c042e633c31da4d9d2ad63d67f47f..33cd48f3d81ef4d321d2afc8b4bf3d518bfae37b 100644 (file)
@@ -187,6 +187,8 @@ library/profile,,:lineno,filename:lineno(function)
 library/pyexpat,,:elem1,<py:elem1 />
 library/pyexpat,,:py,"xmlns:py = ""http://www.python.org/ns/"">"
 library/random,,:len,new_diff = mean(combined[:len(drug)]) - mean(combined[len(drug):])
+library/readline,,:bind,"python:bind -v"
+library/readline,,:bind,"python:bind ^I rl_complete"
 library/smtplib,,:port,method must support that as well as a regular host:port
 library/socket,,::,'5aef:2b::8'
 library/socket,,:can,"return (can_id, can_dlc, data[:can_dlc])"
index 5c05ee7d5aa19f1990f4c3716d2bb0dfd3b80695..b1f1e8a4b8de31418d16cac2c34da455a24c45c9 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1229,6 +1229,7 @@ Gabriel de Perthuis
 Tim Peters
 Benjamin Peterson
 Joe Peterson
+Zvezdan Petkovic
 Ulrich Petri
 Chris Petrilli
 Roumen Petrov
diff --git a/Misc/NEWS.d/next/macOS/2018-05-16-13-25-58.bpo-13631.UIjDyY.rst b/Misc/NEWS.d/next/macOS/2018-05-16-13-25-58.bpo-13631.UIjDyY.rst
new file mode 100644 (file)
index 0000000..d9d505e
--- /dev/null
@@ -0,0 +1,2 @@
+The .editrc file in user's home directory is now processed correctly during
+the readline initialization through editline emulation on macOS.
index 811fca8cd92a7233512781a484292349835e24f7..7756e6b2bc75b380452cb0d3c97b8d72283d6cd7 100644 (file)
@@ -1078,6 +1078,9 @@ setup_readline(readlinestate *mod_state)
         Py_FatalError("not enough memory to save locale");
 #endif
 
+    /* The name must be defined before initialization */
+    rl_readline_name = "python";
+
 #ifdef __APPLE__
     /* the libedit readline emulation resets key bindings etc
      * when calling rl_initialize.  So call it upfront
@@ -1099,7 +1102,6 @@ setup_readline(readlinestate *mod_state)
 
     using_history();
 
-    rl_readline_name = "python";
     /* Force rebind of TAB to insert-tab */
     rl_bind_key('\t', rl_insert);
     /* Bind both ESC-TAB and ESC-ESC to the completion function */