-
Notifications
You must be signed in to change notification settings - Fork 194
editor: introduce a KillLine command, and bind it to ctrl_k in emacs #901
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
|
|
||
| fn kill_line(&mut self) { | ||
| if self.line_buffer.insertion_point() == self.line_buffer.find_current_line_end() { | ||
| self.cut_char() |
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.
Does the emacs version kill a whole line of preceding chars as well or just the trailing new line character (also don't know of the top of my head if we harmonize \r\n / \n?)
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 just kill the trailing new line character. And find_current_line_end will return the position of \n or \r\n(on the first byte)
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.
Is cut_char removing both?
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.
Yup. I added a test named test_with_windows_newline to cover it
| EditCommand::CutFromLineStart => self.cut_from_line_start(), | ||
| EditCommand::CutToEnd => self.cut_from_end(), | ||
| EditCommand::CutToLineEnd => self.cut_to_line_end(), | ||
| EditCommand::KillLine => self.kill_line(), |
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.
For consistency, does it make sense to have the same Cut prefix? We don't have anything else using the emacsism kill
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 don't think so, because it also contains the CutCurrentLine command, which cuts the whole line. It will be more confusing if we have both CutLine and CutCurrentLine.
Personally I think KillLine will be a more appropriate name, as it is more familiar to emacs users.
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.
Yeah, can get around to that. We should probably move towards having cleaner things for emacs style mode and separate logic for the vi mode (that emulation and shared command chaining is biting us way too often :D)
|
Hi, @sholderbach . Is there something still missing? I want to get it in next release. |
|
Let's land it, don't forget to add the mapping in Nushell so you can bind it manually. |
| #[test] | ||
| fn kill_line() { | ||
| let mut emacs = Emacs::default(); | ||
|
|
||
| let ctrl_k = ReedlineRawEvent::try_from(Event::Key(KeyEvent::new( | ||
| KeyCode::Char('k'), | ||
| KeyModifiers::CONTROL, | ||
| ))) | ||
| .unwrap(); | ||
| let result = emacs.parse_event(ctrl_k); | ||
|
|
||
| assert_eq!(result, ReedlineEvent::Edit(vec![EditCommand::KillLine])); | ||
| } |
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.
This test wouldn't have been necessary, testing that the explicit data is the explicit data feels a bit redundant. The rest solves specific problems.
Follow-up to nushell/reedline#901 Closes nushell/reedline#935
# Description Follow-up to nushell/reedline#901 Closes nushell/reedline#935 # User-Facing Changes You can now use `{edit: KillLine}` to mimic emacs `Ctrl-K` behavior`
# Description Follow-up to nushell/reedline#901 Closes nushell/reedline#935 # User-Facing Changes You can now use `{edit: KillLine}` to mimic emacs `Ctrl-K` behavior`
Currently
ctrl-krunsCutToLineEnd, I think it can be improved.Because in emacs,
ctrl-knot onlyCutToLineEnd, but also removes the line if the cursor is at the end of the line.