-
Notifications
You must be signed in to change notification settings - Fork 6
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> not working with autopairs plugin #43
Comments
Yeah good pickup, I’ll have to install an auto pairs plugin tmr to see what the issue is. |
I noticed a similar issue with autopairs. I didn't get an error but I noticed that autopairs overrides autolist's local function create_mapping_hook(mode, mapping, hook, alias)
vim.keymap.set(
mode,
mapping,
function(motion)
local keys = hook(motion, alias or mapping)
if not keys then keys = '' end
return keys
end,
{ expr = true, buffer = true }
)
end Perhaps this should be changed in the README since this is the desired behaviour. |
@mawkler : I tried adding Peek.2023-01-02.20-28.mp4The expected behavior is like this: I'm not sure if this is possible as |
@goingtosleep I tried using windwp's autopairs but with your example, it does the expected behavior even with and without the autopairs plugin. I tried disabling treesitter and autolist, but the expected behavior still arises. Is there any more complex autopairs-specific behavior that I can try? |
Okay I tried
whereas without autopairs, the result was
Even if I turned on autolist, nothing changed |
Here's my config with lazy.nvim and default lazy.nvim settings: {
"windwp/nvim-autopairs",
config = true,
enabled = true,
},
{
"gaoDean/autolist.nvim",
dev = true,
enabled = true, -- doesn't matter if this is false
ft = {
"markdown",
"txt",
},
config = function()
require("autolist").setup()
function create_mapping_hook(mode, mapping, hook, alias)
vim.keymap.set(
mode,
mapping,
function(motion)
local keys = hook(motion, alias or mapping)
if not keys then keys = "" end
return keys
end,
{ expr = true}
)
end
create_mapping_hook("i", "<cr>", require("autolist").new)
create_mapping_hook("i", "<tab>", require("autolist").indent)
create_mapping_hook("i", "<s-tab>", require("autolist").indent, "<c-d>")
create_mapping_hook("n", "dd", require("autolist").force_recalculate)
create_mapping_hook("n", "o", require("autolist").new)
create_mapping_hook("n", "O", require("autolist").new_before)
create_mapping_hook("n", ">>", require("autolist").indent)
create_mapping_hook("n", "<<", require("autolist").indent)
create_mapping_hook("n", "<c-r>", require("autolist").force_recalculate)
create_mapping_hook("n", "<leader>x", require("autolist").invert_entry, "")
end,
}
|
oh I see, I wasn't using the |
@mawkler For me, |
@mawkler @goingtosleep Okay so temporary fix, just set autolist's priority to be very high |
Alright, more permanent fix, add |
whoops didnt mean to close it, but try it out now |
Just tried with the latest commit @gaoDean, but it seems the issue is still there 🥲. Sometimes autopairs works and autolist doesn't: Sometimes the reversed: I tried using the |
@goingtosleep ohh, I see the problem. They are probably competing for the "" mapping, and when autolist wins, it still presses |
even with this: vim.keymap.set("n", "<cr>", function()
print("test1")
return "<cr>"
end, { expr = true, remap = true })
vim.keymap.set("n", "<cr>", function()
print("test2")
return "<cr>"
end, { expr = true, remap = true }) only the second one runs, so I can't really see a way to do this. |
The only way I can see is to get the function that is mapped to "" (nvim_buf_get_keymap) in create_mapping_hook, and then call that function, and then do the autolist funtcion. |
@goingtosleep ok im really close with this now but my dad says i gotta go to bed lmao (this is all in the config function
you must make sure that autopairs is loaded first nvim-autopairs is annoying cus it uses nvim_buf_set... so theres no callback function, theres only a "v:lua" string you can see it nearly working if you replace the ending local autolist = require("autolist")
autolist.setup()
local function mapping_hook(mode, mapping, hook, alias)
-- if the requested mapping is occupied, add current function to it
local additional_map = nil
local maps = vim.api.nvim_get_keymap(mode)
for _, map in ipairs(maps) do
if map.lhs == mapping then
if map.rhs then
additional_map = map.rhs:gsub("^v:lua%.", "", 1)
else
additional_map = map.callback
end
pcall(vim.keymap.del, mode, mapping)
end
end
vim.keymap.set(
mode,
mapping,
function(motion)
if additional_map then
if type(additional_map) == "string" then
local ok, res = pcall(load("return " .. additional_map))
if ok then
vim.fn.feedkeys(res, "nt")
end
else
vim.fn.feedkeys(additional_map(), "nt")
end
end
return hook(motion, alias or mapping) or ""
end,
{ expr = true, remap = true }
)
end
mapping_hook("i", "<CR>", require("autolist").new)
|
@goingtosleep try this local plugins = {
"folke/tokyonight.nvim",
{
"gaoDean/autolist.nvim",
ft = {
"markdown",
"text"
},
config = function()
local autolist = require("autolist")
autolist.setup()
local function mapping_hook(mode, mapping, hook, alias)
local additional_function = nil
local maps = vim.api.nvim_get_keymap(mode)
for _, map in ipairs(maps) do
if map.lhs == mapping then
if map.rhs then
additional_function = map.rhs:gsub("^v:lua%.", "", 1)
else
additional_function = map.callback
end
pcall(vim.keymap.del, mode, mapping)
end
end
vim.keymap.set(
mode,
mapping,
function(motion)
local additional_map = nil
if additional_function then
if type(additional_function) == "string" then
local ok, res = pcall(load("return " .. additional_function))
if ok then
additional_map = res or ""
end
else
additional_map = additional_function() or ""
end
end
return hook(motion, additional_map or mapping) or ""
end,
{ expr = true, buffer = true }
)
end
mapping_hook("i", "<CR>", autolist.new)
mapping_hook("n", "o", require("autolist").new)
end,
dependencies = {
{
"windwp/nvim-autopairs",
config = true,
event = "VeryLazy"
},
},
},
}
|
i might add this to autolist so the user wont have to copy in a massive function |
okay 2nd revision because for the above one, autopairs wont work for filetypes that are not markdown and text local plugins = {
"folke/tokyonight.nvim",
{
"windwp/nvim-autopairs",
config = true,
priority = 2,
},
{
"gaoDean/autolist.nvim",
priority = 1, -- load after autopairs
branch = "dev2",
ft = {
"markdown",
"text"
},
config = function()
local autolist = require("autolist")
autolist.setup()
autolist.create_mapping_hook("i", "<CR>", autolist.new)
autolist.create_mapping_hook("n", "o", autolist.new)
end,
},
} |
Nice @gaoDean, the |
When I set
create_mapping_hook("i", "<cr>", require("autolist").new)
, it will kind of override the of autopairs plugins (like auto-pairs) and results in the following error:It was still working fine with commit 761e0f9, but that commit has the annoying space in the beginning of the new line.
My setup:
lazy.nvim
nvim-autopairs
, the autopairs feature when doesn't work without showing any error.Reproduce
Run
nvim -u repro.lua tmp.md
. The filerepro.lua
is given below.repro.lua
The text was updated successfully, but these errors were encountered: