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

<CR> compatibility with autopairs.nvim #77

Open
musjj opened this issue Jul 7, 2023 · 6 comments
Open

<CR> compatibility with autopairs.nvim #77

musjj opened this issue Jul 7, 2023 · 6 comments

Comments

@musjj
Copy link

musjj commented Jul 7, 2023

In the recent update, autolist depecrated the custom mapping function in favor for native mapping. But this change caused some regressions.

Previously resolved issues with autopairs (#43) is now a problem again.

Any straightforward way to fix this? Why not bring back the custom mapping functions? I honestly don't see how the "native" method is better in this context.

@gaoDean
Copy link
Owner

gaoDean commented Jul 10, 2023

With vim.keymap.set, you can set a lua function that just calls whichever function is being overrided. If autolist is being overrided, you can do the vim.keymap.del, you can delete it if autolist is being overrided, or you can call autolist when you are mapping another plugin.

In my opinion, this is much more configurable and easier to setup for niche cases.

@gaoDean
Copy link
Owner

gaoDean commented Jul 10, 2023

what am i saying. i think ill add a resolve_conflict mapping or smth that detects for any conflict

@gaoDean
Copy link
Owner

gaoDean commented Jul 10, 2023

wait i got a good idea (tell me if this is a bad idea) ill just add a new_bullet_hook that can run whatever function u want

@gaoDean
Copy link
Owner

gaoDean commented Jul 10, 2023

sorry I'm just using you as a rubber ducky heres a solution if u want

      vim.keymap.set("i", "<CR>", function()
        -- run autolist-new-bullet after the <cr> of nvim-autopairs-cr
        -- timeout of 0ms delays enough for my computer but u might need to adjust
        local timeoutms = 0
        vim.loop.new_timer():start(timeoutms, 0, vim.schedule_wrap(function()
          require("autolist").new_bullet()
        end))

        return require("nvim-autopairs").autopairs_cr()
      end, { expr = true, noremap = true })

@camarayol
Copy link

sorry I'm just using you as a rubber ducky heres a solution if u want

      vim.keymap.set("i", "<CR>", function()
        -- run autolist-new-bullet after the <cr> of nvim-autopairs-cr
        -- timeout of 0ms delays enough for my computer but u might need to adjust
        local timeoutms = 0
        vim.loop.new_timer():start(timeoutms, 0, vim.schedule_wrap(function()
          require("autolist").new_bullet()
        end))

        return require("nvim-autopairs").autopairs_cr()
      end, { expr = true, noremap = true })

I use "ZhiyuanLck/smart-pairs" have the same problem, I tried this and it worked, thanks!

require("pairs"):setup({
    enter = {
        enable_mapping  = true,
        enable_cond     = false,
        enable_fallback = function()
            -- https://github.com/gaoDean/autolist.nvim/issues/77
            vim.loop.new_timer():start(0, 0, vim.schedule_wrap(function()
                require("autolist").new_bullet()
            end))

            require('pairs.utils').feedkeys('<cr>')
        end,
    },
})

@Tainted-Fool
Copy link

sorry I'm just using you as a rubber ducky heres a solution if u want

      vim.keymap.set("i", "<CR>", function()
        -- run autolist-new-bullet after the <cr> of nvim-autopairs-cr
        -- timeout of 0ms delays enough for my computer but u might need to adjust
        local timeoutms = 0
        vim.loop.new_timer():start(timeoutms, 0, vim.schedule_wrap(function()
          require("autolist").new_bullet()
        end))

        return require("nvim-autopairs").autopairs_cr()
      end, { expr = true, noremap = true })

I am experiencing the same issue (autolist and autopairs) and adding this makes <CR> do nothing. I tried changing timeoutms to various number and it still the same. I checked my keybinds for any other <CR> and its only binded to completion_confirm(). Is there an alternative way to make this work with autopairs?

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

No branches or pull requests

4 participants