Repository: ipython/ipython

Issue:
mapping ctrl-L to something else other then clear-screen doesn't work in readline file ~/.inputrc
environtment:
OS: ubuntu14.04
python: 2.7.6 and 3.4.1
ipython: 2.1.0

i put these settings to the readline file ~/.inputrc, what i want to do is to use `ctrl-L/H` to move forward/backward a char when i am editing command line in `ipython` interpreter.

``` bash
$if python
    "\C-l": forward-char
    "\C-h": backward-char
$endif
```

`ctrl-H` do works fine and it is able to move backward a char, whereas `ctrl-L` doesn't work, it clear screen as its default action.

this issue only occurs on `ipython` interpreter. if i am runing `python` on terminal, it works fine. `ctrl-H/L` are able to move backward/forward a  char in `python` interpreter..



Discussion:
IPython [binds](https://github.com/ipython/ipython/blob/rel-2.1.0/IPython/core/interactiveshell.py#L377) a few readline shortcuts after loading inputrc, and one of them is C-l. You can prevent this with:

```
c.InteractiveShell.readline_parse_and_bind = []
```

in your ipython_config.py, which should let your shortcut be used.

i appreciate your reply, sir. things get fixed as per your response.


Resolving patch:
diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py
--- a/IPython/core/interactiveshell.py
+++ b/IPython/core/interactiveshell.py
@@ -393,8 +393,15 @@ def _prompt_trait_changed(self, name, old, new):
             '"\e[B": history-search-forward',
             '"\C-k": kill-line',
             '"\C-u": unix-line-discard',
-        ], allow_none=False, config=True)
-
+        ], config=True)
+    
+    _custom_readline_config = False
+    
+    def _readline_parse_and_bind_changed(self, name, old, new):
+        # notice that readline config is customized
+        # indicates that it should have higher priority than inputrc
+        self._custom_readline_config = True
+    
     ast_node_interactivity = Enum(['all', 'last', 'last_expr', 'none'],
                                   default_value='last_expr', config=True, 
                                   help="""
@@ -1877,6 +1884,17 @@ def init_readline(self):
             else:
                 self.readline_startup_hook = readline.set_startup_hook
 
+            # Readline config order:
+            # - IPython config (default value)
+            # - custom inputrc
+            # - IPython config (user customized)
+            
+            # load IPython config before inputrc if default
+            # skip if libedit because parse_and_bind syntax is different
+            if not self._custom_readline_config and not readline.uses_libedit:
+                for rlcommand in self.readline_parse_and_bind:
+                    readline.parse_and_bind(rlcommand)
+
             # Load user's initrc file (readline config)
             # Or if libedit is used, load editrc.
             inputrc_name = os.environ.get('INPUTRC')
@@ -1891,14 +1909,10 @@ def init_readline(self):
                 except:
                     warn('Problems reading readline initialization file <%s>'
                          % inputrc_name)
-
-            # Configure readline according to user's prefs
-            # This is only done if GNU readline is being used.  If libedit
-            # is being used (as on Leopard) the readline config is
-            # not run as the syntax for libedit is different.
-            if not readline.uses_libedit:
+            
+            # load IPython config after inputrc if user has customized
+            if self._custom_readline_config:
                 for rlcommand in self.readline_parse_and_bind:
-                    #print "loading rl:",rlcommand  # dbg
                     readline.parse_and_bind(rlcommand)
 
             # Remove some chars from the delimiters list.  If we encounter


Test patch: