prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.29k stars 715 forks source link

Confusion between unix-word-rubout and backward-kill-word #426

Open vfaronov opened 7 years ago

vfaronov commented 7 years ago

GNU Readline has commands:

The difference between these two commands is very useful. For example, suppose I have typed:

some-command --some-option /some/very/long/path

then realize that the path is wrong. I can then erase the entire path by pressing Ctrl+W, or erase it part-by-part by pressing Alt+Bksp.

However, prompt_toolkit binds both unix-word-rubout and backward-kill-word to the same action, which behaves more like backward-kill-word but not exactly (e.g. considers underscores as parts of words), and then binds both Ctrl+W and Alt+Bksp to unix-word-rubout by default.

Is there any specific reason for this divergence from Readline? Would you consider making prompt_toolkit behave the same as Readline here?

jonathanslenders commented 7 years ago

Hi @vfaronov,

Thanks a lot for pointing this out! This was indeed not yet implemented. It should be fixed in this commit: https://github.com/jonathanslenders/python-prompt-toolkit/commit/44e571b68e84d5007c6f5ab416771e7abbf25a64

Could you try with the latest "master" commit, and let me know whether it now works correctly? Whenever possible, we should follow GNU readline by default.

Thanks, Jonathan

vfaronov commented 7 years ago

This is great, thank you!

It’s still not quite the same as Readline, though. Readline’s backward-kill-word deletes any non-word characters after a word, so if you’re at the end of /foo/bar/ and press Alt+Bksp, you get /foo/. Whereas with your commit the result is /foo/bar.

Also, as I mentioned earlier, Readline does not consider the underscore _ as part of a word.

But for me personally, this is not a big deal. What’s important is that now I can delete back to whitespace with a single keystroke.