gh-146044: Fix ctrl-w (unix-word-rubout) to use whitespace word boundaries#146174
gh-146044: Fix ctrl-w (unix-word-rubout) to use whitespace word boundaries#146174kimimgo wants to merge 3 commits intopython:mainfrom
Conversation
…on#146044) The unix-word-rubout command (ctrl-w) was using syntax_table-based word boundaries (bow()), which treats punctuation as word separators. This differs from bash/readline's unix-word-rubout which uses only whitespace as word boundaries. Add bow_whitespace() method that uses whitespace-only boundaries, and use it in unix_word_rubout instead of bow(). The existing bow() method (used by backward-kill-word/M-Backspace) is unchanged. Example: with 'foo.bar baz' and cursor at end: - Before (bow): ctrl-w deletes 'baz', then 'bar', then 'foo' - After (bow_whitespace): ctrl-w deletes 'baz', then 'foo.bar'
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Add a check in Parse() to prevent calls when in_callback is true, as this violates expat's requirements and can cause crashes. Now raises RuntimeError with a clear message. Add tests to verify the fix and ensure normal parsing still works.
Add a check in Parse() to prevent calls when in_callback is true, as this violates expat's requirements and can cause crashes. Now raises RuntimeError with a clear message. Add tests to verify the fix and ensure normal parsing still works.
Add a check in Parse() to prevent calls when in_callback is true, as this violates expat's requirements and can cause crashes. Now raises RuntimeError with a clear message. Add tests to verify the fix and ensure normal parsing still works.
Add a check in Parse() to prevent calls when in_callback is true, as this violates expat's requirements and can cause crashes. Now raises RuntimeError with a clear message. Add tests to verify the fix and ensure normal parsing still works.
Add a check in Parse() to prevent calls when in_callback is true, as this violates expat's requirements and can cause crashes. Now raises RuntimeError with a clear message. Add tests to verify the fix and ensure normal parsing still works.
Add a check in Parse() to prevent calls when in_callback is true, as this violates expat's requirements and can cause crashes. Now raises RuntimeError with a clear message. Add tests to verify the fix and ensure normal parsing still works.
Add a check in Parse() to prevent calls when in_callback is true, as this violates expat's requirements and can cause crashes. Now raises RuntimeError with a clear message. Add tests to verify the fix and ensure normal parsing still works.
Add a check in Parse() to prevent calls when in_callback is true, as this violates expat's requirements and can cause crashes. Now raises RuntimeError with a clear message. Add tests to verify the fix and ensure normal parsing still works.
Add a check in Parse() to prevent calls when in_callback is true, as this violates expat's requirements and can cause crashes. Now raises RuntimeError with a clear message. Add tests to verify the fix and ensure normal parsing still works.
|
I personally prefer stopping at separators rather than whitespaces. I think zsh stops at punctuations. So I would first open a DPO thread about this before changing anything. |
|
Thanks for the feedback @picnixz! The distinction I'm making is between two different readline commands:
The current code maps Ctrl-W to This PR keeps That said, I'm happy to open a Discourse thread if you think this needs broader discussion first. |
|
I am a bit torn here... I would say M-backspace is... less convenient to type but at the same time if ctrl+w is meant to emulate the Unix one then I guess it may be better to ensure this. What is the behavior on the old REPL? (in 3.12?) |
ctrl-w (unix-word-rubout) uses whitespace boundaries on bash, zsh, and fish on macOS. |
ctrl-w stops on whitespace boundaries in the 3.12 REPL.
|
Fixes #146044
Summary
The
unix-word-ruboutcommand (ctrl-w) was usingbow()which treatspunctuation as word separators via the syntax table. This differs from
bash/readline's
unix-word-ruboutwhich uses only whitespace as boundaries.Changes
reader.py: Addbow_whitespace()method — same asbow()but onlyconsiders spaces and newlines as word boundaries
commands.py:unix_word_ruboutnow callsbow_whitespace()instead ofbow()test_reader.py: AddTestBowWhitespaceclass with 4 tests verifyingthe whitespace-only behavior and the difference from
bow()Example
With buffer
foo.bar bazand cursor at end:baz, thenbar, thenfoo(3 operations)baz, thenfoo.bar(2 operations, matching bash)The existing
bow()method used bybackward-kill-word(M-Backspace) is unchanged.