Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't error when transposing an empty buffer #46925

Merged

Conversation

perryprog
Copy link
Contributor

This fixes an issue where transposing an empty buffer in the REPL with ^T would cause an error.

Fixes #45417—for real this time! (See also #45420, which introduced this bug.)

@@ -1101,7 +1101,7 @@ end

function edit_transpose_chars(buf::IOBuffer)
# Moving left but not transpoing anything is intentional, and matches Emacs's behavior
eof(buf) && char_move_left(buf)
eof(buf) && position(buf) !== 0 && char_move_left(buf)
position(buf) == 0 && return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just swap this and the line above rather than duplicating the condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the original logic that led to #45417 being filed—what will happen is if the buffer's position is at 1, with a length of 1, then we'll try to read past the end of the buffer.

Since I figured that it'd be best to be as close to Emacs as possible, I went with just flipping those two lines (hence the comment).

In this PR, I'm not sure there's a good way to get around the duplication of the position(buf) stuff unless I'm missing something obvious (which isn't unlikely)—we ultimately need to check it twice, first time to make sure we can move left, and then again to make sure we aren't at the start of the buffer. One other idea could be something like this though, but I'm not sure which I prefer (probably this version, but I'm curious what you think):

function edit_transpose_chars(buf::IOBuffer)
    content(buf) == "" && return false

    # Moving left but not transpoing anything is intentional, and matches Emacs's behavior
    eof(buf) && char_move_left(buf)
    position(buf) == 0 && return false 
    # ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see char_move_left might update the buf position. Alright, seems reasonable I suppose

@KristofferC KristofferC added the backport 1.8 Change should be backported to release-1.8 label Sep 27, 2022
@KristofferC KristofferC merged commit 757f21e into JuliaLang:master Sep 27, 2022
KristofferC pushed a commit that referenced this pull request Sep 30, 2022
@KristofferC KristofferC mentioned this pull request Sep 30, 2022
37 tasks
KristofferC pushed a commit that referenced this pull request Oct 28, 2022
@KristofferC KristofferC removed the backport 1.8 Change should be backported to release-1.8 label Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EOFError in the REPL on pressing ctrl+t after typing a single character
3 participants