FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

prompt_toolkit ignores .inputrc · Issue #9388 · ipython/ipython · GitHub

Repository navigation

prompt_toolkit ignores .inputrc #9388

Open

Description

For as long as IPython used readline, users' .inputrc settings were respected at the input prompt.

This does not appear to be the case - as prompt_toolkit does not currently support .inputrc.

Can we add a note about this? I actually don't see anything in what's new for 5.x - only 4.x notes in there.

vi users will want to turn this off, or at least know how to turn on prompt_toolkit's vi mode (I think it has one?).

I get the impression that @takluyver @jonathanslenders seem to be closest to this.

Activity

  1. jonathanslenders commented on Apr 9, 2016

    Contributor

    Hi all,

    prompt-toolkit does not process .inputrc yet. Mainly because there was no obvious 1-to-1 mapping of the readline and the prompt-toolkit functionality. Especially because the readline configuration uses vt100 escape codes to define key bindings. This is for historical reasons and not platform independent.

    However, detecting whether the editing-mode is vi (set editing-mode vi), or whether the user has interest in history-search-backward (e.g.:"\e[A":history-search-backward) is not going to be difficult.

    The crash guys are doing this: https://github.com/crate/crash/blob/d8e49c0aec8f1c70c49fe56e7f3e967bde1f44a3/src/crate/crash/command.py#L415
    See also: prompt-toolkit/python-prompt-toolkit#56

    Jonathan

  2. takluyver commented on Apr 9, 2016

    Member

    Hi Paul! I wondered when we'd be seeing you after this change ;-). You're right, we should definitely mention it in the release notes.

    I don't think we should try to do any interpretation of inputrc: I'd rather be able to say unambiguously 'no, that no longer affects input in IPython, here are the new ways to configure things', rather than dealing with a situation where some entries in there work and others don't.

    For reference, the config option to enable vi mode is now TerminalInteractiveShell.vi_mode (which is a boolean).

  3. added this to the 5.0 milestone on Apr 30, 2016
  4. Carreau commented on Apr 30, 2016

    Member

    Marking as 5.0 to, at least, document it.

  5. Carreau commented on May 27, 2016

    Member

    documented in #9497, bumbing to 6.0 to reevaluate.

  6. modified the milestones: 6.0, 5.0 on May 27, 2016
  7. MarkLodato commented on Sep 18, 2016

    So, how do you configure "\e[A":history-search-backward? And how do you get up arrow to be normal up arrow and not history search? In old versions I could do

    c.TerminalInteractiveShell.readline_parse_and_bind = ['tab: complete']

    but that no longer works.

  8. takluyver commented on Sep 19, 2016

    Member

    We should make history search (the behaviour of the up and down arrows) configurable - I've just opened #9961 for that.

    For adding custom shortcuts, see the docs. Unfortunately at present you have to go digging in the prompt_toolkit code to find/write a function that does what you want. The normal behaviour of the up-arrow key is defined here and here.

  9. wavexx commented on Nov 9, 2016

    prompt-toolkit introduces several editing regressions compared to readline :/. For example, forward/backward-word do not work anymore in urxvt, and there's no way to configure the different escape sequences without editing the internal bindings.

  10. takluyver commented on Nov 9, 2016

    Member

    Forward/backward word works OK in my terminal; I don't see urxvt in my repos to test with.

  11. wavexx commented on Nov 9, 2016

    On Wed, Nov 09 2016, Thomas Kluyver wrote:

    Forward/backward word works OK in my terminal; I don't see urxvt in my repos to test with.

    On debian it's rxvt-unicode/rxvt-unicode-*.

    See prompt-toolkit/python-prompt-toolkit#415

  12. MarkLodato commented on Nov 9, 2016

    I agree with @wavexx. I have stopped using the new version of IPython because the prompt is so much worse. Although readline is not perfect, it uses my standard ~/.inputrc and I'm happy. The new version of IPython is unusable because of prompt-toolkit. If I were you, I'd revert that change.

  13. jonathanslenders commented on Nov 9, 2016

    Contributor

    @MarkLodato Could you share your inputrc? Are you missing some functionality, or do you have custom key bindings? I plan to support .inputrc at some point, but it won't be in the near future. (Takes more time than I expected.)

  14. 6 remaining items

  15. takluyver commented on Nov 9, 2016

    Member

    @jonathanslenders thanks, that's a good start. I might look into ways to scrape that list of names to offer a list in the docs.

  16. DanielO commented on Jan 19, 2017

    Is there a handy cut & paste to get reverse/forward history search with esc-p / esc-n? :)

  17. rsvp commented on Jan 29, 2017

    What would be the IPython equivalent to set editing-mode vi in an .inputrc Linux readline config file?

    @takluyver wrote:

    Sorry, we're not about to revert it. We expected there would be some rough edges with a change this big, but prompt_toolkit allows us to do things we couldn't with readline: live syntax highlighting, and proper multiline editing. It also makes installation simpler on Windows and Mac, because we don't need pyreadline and gnureadline (respectively).

    If vi mode cannot be supported via readline, what are the instructions and tips
    for the forementioned multiline editing -- how does it work?
    Can one call vim into the IPython environment to make edits?

  18. takluyver commented on Jan 29, 2017

    Member

    In IPython config, the relevant option is TerminalInteractiveShell.editing_mode. Setting it to the string 'vi' should give you prompt_toolkit's vi bindings.

    Can one call vim into the IPython environment to make edits?

    In 5.2 (coming very soon, we hope), you can press F2 at the IPython prompt to jump into $EDITOR.

  19. takluyver commented on Jan 29, 2017

    Member

    Multiline editing in the prompt means that if you type e.g. for a in rage(5):<enter>, you can press up-arrow and go back to the line above, without having to cancel the input. It may sound trivial, but previous versions of IPython couldn't do that.

  20. rsvp commented on Jan 30, 2017

    hi @takluyver Thanks very much for your prompt :) support !

    Just to clarify for other users...

    Setting IPython (v5+) PROMPT to vi-mode

    This works like Linux vi-mode for readline, except the developers
    have crafted a cross-platform solution.

    • Go to your .ipython/profile_FOO directory
    • Add the following line to ipython_config.py:
      c.TerminalInteractiveShell.editing_mode = 'vi'

    P.S. is it possible to reassign the ESC key in vi-mode?
    I have been using semi-colon for this purpose.

    P.S.S. since PromptManager is deprecated, what is the correct way
    to set PromptManager.in_template?


    Edit: Updated solutions posted here: https://git.io/ipython_config.py

  21. takluyver commented on Jan 30, 2017

    Member

    P.S. is it possible to reassign the ESC key in vi-mode?

    See custom keyboard shortcuts - though at present, you'll have to dig around in the prompt_toolkit source code to find what function to call to do the action.

    P.S.S. since PromptManager is deprecated, what is the correct way to set PromptManager.in_template?

    See custom prompts. :-)

  22. rsvp commented on Jan 30, 2017

    @takluyver Thanks for your tremendous help. I've summarized the solutions so far here:
    https://git.io/ipython_config.py

    It is a gist which was adapted from your gist of five months ago.
    Unlike the official documentation sample code, the execution_count
    number has been included in the custom In and Out prompts.

    I will update my gist as I discover new v5+ features.

  23. takluyver commented on Jan 30, 2017

    Member

    Thanks for that summary 🍪

  24. modified the milestones: 6.0, 7.0 on Mar 13, 2017
  25. removed this from the 7.0 milestone on Aug 28, 2018
  26. mrrech commented on Apr 4, 2019

    Not sure if this can be still of any help to anyone, but I just figured out how to get alt-p/alt-n bound to history backward and forward respectively (as @DanielO and @MarkLodato were asking a couple of years ago). Since I haven't found any reference about this other than this old issue, I'll leave it here hoping can be of help.

    from IPython import get_ipython                                                 
    from prompt_toolkit.enums import DEFAULT_BUFFER                                 
    from prompt_toolkit.filters import HasFocus                                     
                                                                                    
    ip = get_ipython()                                                              
                                                                                    
    def history_fwd(event):                                                         
        event.current_buffer.history_forward(count=event.arg)                       
                                                                                    
    def history_back(event):                                                        
        event.current_buffer.history_backward(count=event.arg)                      
                                                                                    
    # Register the shortcut if IPython is using prompt_toolkit                      
    if getattr(ip, 'pt_app', None):                                                 
        registry = ip.pt_app.key_bindings                                           
        registry.add_binding('escape', 'p',                                         
                             filter=HasFocus(DEFAULT_BUFFER))(history_back)         
        registry.add_binding('escape', 'n',                                         
                             filter=HasFocus(DEFAULT_BUFFER))(history_fwd)

    If you save this in the startup directory of your default ipython profile, it should work (at least it works for me). Of course it would be nice to get this easily without having to understand part of the internals of both IPython and prompt_toolkit.

    HTH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL