-
Notifications
You must be signed in to change notification settings - Fork 90
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
Conversation
lib/reline/line_editor.rb
Outdated
@@ -1654,6 +1654,12 @@ def finish | |||
end | |||
alias_method :next_history, :ed_next_history | |||
|
|||
private def end_of_history(key) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
test/reline/test_key_actor_emacs.rb
Outdated
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 |
There was a problem hiding this comment.
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", ""
?
test/reline/test_key_actor_emacs.rb
Outdated
input_key_by_symbol(:end_of_history) | ||
assert_line_around_cursor('', '') | ||
input_keys("\C-p") | ||
assert_line_around_cursor('dabc', '') |
There was a problem hiding this comment.
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
)
lib/reline/line_editor.rb
Outdated
@history_pointer = Reline::HISTORY.size - 1 | ||
@line_backup_in_history ||= '' | ||
ed_next_history(key) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used
line: :end
👍
5d871ab
to
7748af0
Compare
There was a problem hiding this 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
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.