Skip to content

Conversation

@WindSoilder
Copy link
Contributor

Currently ctrl-k runs CutToLineEnd, I think it can be improved.
Because in emacs, ctrl-k not only CutToLineEnd, but also removes the line if the cursor is at the end of the line.


fn kill_line(&mut self) {
if self.line_buffer.insertion_point() == self.line_buffer.find_current_line_end() {
self.cut_char()
Copy link
Member

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?)

Copy link
Contributor Author

@WindSoilder WindSoilder Apr 2, 2025

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)

Copy link
Member

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?

Copy link
Contributor Author

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(),
Copy link
Member

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

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 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.

Copy link
Member

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)

@WindSoilder
Copy link
Contributor Author

Hi, @sholderbach . Is there something still missing? I want to get it in next release.

@sholderbach
Copy link
Member

Let's land it, don't forget to add the mapping in Nushell so you can bind it manually.

@sholderbach sholderbach merged commit 75f2c50 into nushell:main Apr 22, 2025
6 checks passed
Comment on lines +292 to +304
#[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]));
}
Copy link
Member

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.

sholderbach added a commit to sholderbach/nushell that referenced this pull request Jul 22, 2025
sholderbach added a commit to nushell/nushell that referenced this pull request Jul 22, 2025
# 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`
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Aug 25, 2025
# 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`
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