Skip to content
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

Trigger abbreviations when inserting pair signs #1259

Open
2 tasks done
Valentin-Guillet opened this issue Oct 6, 2024 · 7 comments
Open
2 tasks done

Trigger abbreviations when inserting pair signs #1259

Valentin-Guillet opened this issue Oct 6, 2024 · 7 comments
Labels
feature-request Request for a feature to existing module mini.pairs

Comments

@Valentin-Guillet
Copy link

Contributing guidelines

Module(s)

mini.pairs

Description

mini.pairs remaps all pair signs in insert mode, which breaks the default abbreviation expansion in Neovim.
I think one simple way to solve this would be to add <C-]> at the beginning of mappings in the MiniPairs.open function to manually trigger abbreviation expansion.
Would this modification be compatible with the rest of the plugin ?
Thanks !

@Valentin-Guillet Valentin-Guillet added the feature-request Request for a feature to existing module label Oct 6, 2024
@echasnovski
Copy link
Owner

Thanks for the suggestion!

I am having hard time understanding the exact issue here. Would you mind sharing a setup and/or workflow with which you find 'mini.pairs' and abbreviations are in conflict?

@Valentin-Guillet
Copy link
Author

Of course !
I have a few abbreviations set-up to correct spelling mistakes, such as the breakpoint() debug python function that I always mistype, which looks like this : vim.cmd([[inoreabbrev <buffer> brekapoint breakpoint]]).
By default, (neo-)vim expands abbreviations when a character typed is not in the iskeyword option, such as the usual pair signs (, [, {, "...
However, by mapping them in insert mode for mini.pairs, this overwrites the default behavior and typing a bracket does not expand abbreviations anymore, so for instance typing brekapoint( does not fix it anymore.
The abbreviation expansion can be triggered manually with <C-]>, so adding it before the pair character is enough to make everything work again (I think in MiniPairs.open line 290), although I'm not sure if that could potentially break other part of the plugin (I don't see why, but I did not test it as I'm not entirely familiar with the plugin inner workings).

@echasnovski
Copy link
Owner

Ah, I see now the problem. Thanks for the follow up!

I don't think prepending <C-] in outputs of open() and closeopen() is a good solution, as it adds extra actions to perform which will be actually needed far more rarely than not.

At the moment it looks to me like an upstream Vim (yes, not even Neovim) issue. I'll try to look and ask around about this.

@Valentin-Guillet
Copy link
Author

I understand your concern about performance, but to provide some context, I think this operation is already executed by default each time a character is typed.
Without the remapping of mini.pairs, this seems to be exactly what Vim does internally when a bracket, space, or any character not in iskeyword is entered, so invoking it manually shouldn't differ from the default behavior (this can be observed in the Vim source code here, though I'm not entirely certain).
That said, I haven't tested it thoroughly, so I understand if it's a concern, and there may be more efficient approaches!

@echasnovski
Copy link
Owner

Without the remapping of mini.pairs, this seems to be exactly what Vim does internally when a bracket, space, or any character not in iskeyword is entered, so invoking it manually shouldn't differ from the default behavior (this can be observed in the Vim source code here, though I'm not entirely certain).

And I think it should still do that even if the character comes as a result of mapping. As in 'mini.pairs' pressing ( should be fully equivalent to pressing (, ), and <Left>. I'll ask around if this is an unexpected behavior and if yes - file an issue.

@Valentin-Guillet
Copy link
Author

If this can help, from what I've been able to test, it would appear that abbreviation expansion is not activated when using noremap, but still works with a recursive mapping, although I also don't know if this an expected behavior or not.
Thanks for taking a look anyway !

@echasnovski
Copy link
Owner

echasnovski commented Oct 7, 2024

This indeed looks like an issue on Vim side. I've created vim/vim#15820 to see if it can be resolved there. If not, I'll consider prepending <C-]> to mappings. The problem here is that it has to also check if the first character is not a keyword character, which is kind of costly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for a feature to existing module mini.pairs
Projects
None yet
Development

No branches or pull requests

2 participants