Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement end-of-history #826

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

Merged
merged 2 commits into from
May 19, 2025
Merged

Implement end-of-history #826

merged 2 commits into from
May 19, 2025

Conversation

etiennebarrie
Copy link
Contributor

After using incremental search, I sometime want to go back to the end of history.

Reline is missing an implementation for end-of-history from Readline.

This adds it.

@@ -1654,6 +1654,12 @@ def finish
end
alias_method :next_history, :ed_next_history

private def end_of_history(key)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure of the naming convention. Should this be named ed_end_of_history? It seem like Editline supports that.

Copy link
Member

Choose a reason for hiding this comment

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

ed_end_of_history looks good 👍. And we need to alias it to end_of_history

Reline::HISTORY.concat(['abc', '123'])
input_keys("\C-rab\C-jd")
assert_line_around_cursor('d', 'abc')
# \M->: clear input, move history to end, keep edited line as previous history
Copy link
Member

Choose a reason for hiding this comment

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

Looks like \M-> in GNU Readline does not clear input. \C-rab is clearing the input and moves history pointer.
Can you change the test case to input "def", UP key, \M-> and check line around cursor to be "def", ""?

input_key_by_symbol(:end_of_history)
assert_line_around_cursor('', '')
input_keys("\C-p")
assert_line_around_cursor('dabc', '')
Copy link
Member

Choose a reason for hiding this comment

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

It should be '123', ''
I tested with irb --readline (Readline::VERSION #=> 8.2)

Comment on lines 1658 to 1660
@history_pointer = Reline::HISTORY.size - 1
@line_backup_in_history ||= ''
ed_next_history(key)
Copy link
Member

Choose a reason for hiding this comment

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

move_history(Reline::HISTORY.size, line: :start, cursor: :end) is better.
Using move_history, we don't need to think of @line_index @line_backup_in_history and other internal structures.

Copy link
Member

Choose a reason for hiding this comment

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

\M-< (beginning-of-history) is a pair of \M-> so implementing both would be awesome.
It could be in this pull request, separate pull request is also fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used line: :end because Readline moves the cursor at the end too, and to match the assertion you shared in #826 (comment).
Also implemented beginning-of-history.
I removed the assertions about the edited history lines, because the code doesn't touch that actually. And the fact that history lines can be edited can be configured with Readline with revert-all-at-newline. It's annoying when you edit a history line, run it, and you lose the original history line. Since it's something I'd like to have, I'd rather not hard-code that behavior in an unrelated test.

Copy link
Member

Choose a reason for hiding this comment

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

I used line: :end

👍

Copy link
Member

@tompng tompng left a comment

Choose a reason for hiding this comment

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

Looks good! thank you

@tompng tompng merged commit 7d9ff21 into ruby:master May 19, 2025
44 checks passed
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.

2 participants