Skip to content

feat: add support for auto-pairs#1114

Draft
altacountbabi wants to merge 2 commits into
nushell:mainfrom
altacountbabi:auto-pairs
Draft

feat: add support for auto-pairs#1114
altacountbabi wants to merge 2 commits into
nushell:mainfrom
altacountbabi:auto-pairs

Conversation

@altacountbabi

Copy link
Copy Markdown

Adds InsertPair and BackspacePair edit commands

@kronberger-droid

Copy link
Copy Markdown
Collaborator

@altacountbabi
Love it, great idea thanks.

We are close to a code freeze before the next release tho, so I think it makes sense to wait until after to merge.
@fdncred or do you think its worth propagating it into Nushell before the release?

@fdncred

fdncred commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

@kronberger-droid I'd probably wait on this one until after the release. I'd also like to see a nushell counterpart PR to this one that enables or disables this feature.

@eitsupi

eitsupi commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

I've independently implemented auto-pairs in a reedline-based project (https://github.com/eitsupi/arf), so I'd like to share some issues I encountered.

Two known pitfalls with this design

History selection leaves orphan closing chars

When the cursor is inside a pair (e.g. foo(|)) and the user selects a history entry, reedline's replace_in_buffer uses span.end = cursor_pos, so it replaces only foo( with foo(), leaving the original ) behind → foo()|). The engine would need a post-replacement cleanup step when auto-pairs is active.

Paste duplicates closing chars

Pasting () produces ()). This requires use_bracketed_paste(true) to avoid; the example and docs should call this out explicitly (or with_auto_pairs() could enable it implicitly).

Design suggestion

The AutoPairs struct has no way to skip insertion based on context, e.g., don't insert inside a string literal. A predicate like:

pub fn with_skip_if<F: Fn(&str, usize, char) -> bool + Send + Sync + 'static>(mut self, f: F) -> Self

would let callers inject language-specific logic without shadow state.
Without it, projects with quote-awareness will still need to work around this at the keybinding layer.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

@fdncred
I am really tempted, since I think it was definitely a missing piece. But I don't have enough time until the release to test out the blast radius, so lets wait.

But @eitsupi comment makes waiting even more reasonable.

@fdncred

fdncred commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

But @eitsupi comment makes waiting even more reasonable.

Ya, I'd like to see some code to help with this. I've experienced this in code editors and it's a pain sometimes, "NO, I ALREADY HAD A CLOSING PAREN. DON'T ADD ANOTHER!!!!"

I probably wouldn't want to land this without something helping with it aggressively closing pairs.

@kronberger-droid

Copy link
Copy Markdown
Collaborator

"NO, I ALREADY HAD A CLOSING PAREN. DON'T ADD ANOTHER!!!!"

Haha very relatable.

Yeah let's try to get this right.
@eitsupi every input is welcome!

@kronberger-droid kronberger-droid marked this pull request as draft June 30, 2026 13:44
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.

4 participants