windwp / nvim-autopairs

autopairs for neovim written in lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docs: Document the default behavior of pairs or how to remove it

Dioprz opened this issue · comments

commented

Is your feature request related to a problem? Please describe.
Yes. After an hour searching through code and documentation I managed to solve a problem that I think it would be good to have documented somewhere:

In my configuration I added the following:

return {
  'windwp/nvim-autopairs',
  config = function()
    local npairs = require('nvim-autopairs')
    local Rule = require('nvim-autopairs.rule')
    local cond = require('nvim-autopairs.conds')
    npairs.setup()
    npairs.add_rules({
      Rule('(', ')', { 'typst' })
           :with_pair(cond.not_before_text('a')),
    })
  end,
}

Although it worked fine for adding parentheses inside strings (ej: a|bc -> a(|bc), typing a( at the end of the line continued to expand the ) pair, which was exactly the behavior I wanted to remove.

After a lot of searching I found the remove_rule('(') option, and by adding it as

    ...
    local cond = require('nvim-autopairs.conds')
    npairs.setup()
    npairs.remove_rule('(')
    npairs.add_rules({
    ....

Everything works as it should.

Describe the solution you'd like

I would like to leave it to your consideration to add one of the following options as I don't know which one is more appropriate

  1. Add to the documentation a warning that if you want to modify the behavior of a 'default' pair, you should use npairs.remove_rules('<open_pair>') to remove any interference from the default configured rules.

  2. Explain what the default rules are for each pre-configured pair (or simply where to find them), and how they can be modified or removed in a punctual way (in my case it would have been enough for me to remove the rule that autocompletes at the end of the line, if such a rule exists.... Or, in any case, the one that made my first configuration not work).

Describe alternatives you've considered
Mentioned above!

Additional context
Thank you very much for building this plugin. Today for the first time I'm exploring it, and you created an amazing API that allowed me to correct overlaps with some sinippets. Many successes!

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.