gaoDean / autolist.nvim

Automatic list continuation and formatting for neovim, powered by lua
MIT License
248 stars 6 forks source link

bug with tab indent #56

Closed axieax closed 1 year ago

axieax commented 1 year ago
- line 1|

Cursor on |.

Expected behaviour after pressing <CR>, getting the auto bullet and pressing <Tab>:

- line 1
    - |

However, one gets this error:

E5108: Error executing lua: ...cal/share/nvim/lazy/autolist.nvim/lua/autolist/utils.lua:209: attempt to index local 'entry'
 (a nil value)
stack traceback:
        ...cal/share/nvim/lazy/autolist.nvim/lua/autolist/utils.lua:209: in function 'is_list'
        ...ocal/share/nvim/lazy/autolist.nvim/lua/autolist/auto.lua:171: in function 'func'
        ...ocal/share/nvim/lazy/autolist.nvim/lua/autolist/init.lua:35: in function 'callback'
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:173: in function 'solve'
        ....local/share/nvim/lazy/nvim-cmp/lua/cmp/utils/keymap.lua:148: in function <....local/share/nvim/lazy/nvim-cmp/lu
a/cmp/utils/keymap.lua:147>

Not sure if this is due to nvim-cmp conflicts.

axieax commented 1 year ago

Update: I'm using lazy.nvim and yes this is due to nvim-cmp conflicts. Managed to resolve this by putting nvim-cmp on InsertEnter and autolist.nvim on InsertCharPre to ensure this plugin's mappings get set after nvim-cmp. However, this causes issues with Telescope and other non-related filetypes due to loading, so it isn't the most preferable solution. Are there better ways?

gaoDean commented 1 year ago

@axieax For the non-related filetypes problem, I recommend using the ft lazy loading to only load on specific filetypes like in the readme, and then using the priority to load after your other plugins. I would like lazy.nvim to support ft and event, so you can control the plugins to load one after the other, but idk, my workaround is just using ft and priority.

axieax commented 1 year ago

I'm using ft and just tried priority of 2 for this plugin, but I still get this issue.

gaoDean commented 1 year ago

Is autolist loading after the conflicting plugin?

axieax commented 1 year ago

Seems like it isn't, since ft seems to occur before nvim-cmp's InsertEnter, even if I add event = "InsertEnter" for autolist.

gaoDean commented 1 year ago

Try to use priority to load autolist.nvim nvim-cmp. For example, set nvim-cmp's priority to 2, and then set autolist.nvim's priority to 1

goingtosleep commented 1 year ago

@axieax For the non-related filetypes problem, I recommend using the ft lazy loading to only load on specific filetypes like in the readme, and then using the priority to load after your other plugins. I would like lazy.nvim to support ft and event, so you can control the plugins to load one after the other, but idk, my workaround is just using ft and priority.

ft + event is possible. Mine is like this:

{ 'hrsh7th/nvim-cmp', event = {'InsertEnter', 'CmdlineEnter'}, ... }
{ 'windwp/nvim-autopairs', event = 'InsertEnter', ... },
{
  'gaoDean/autolist.nvim', 
  event = 'CursorHold *.md', 
  dependencies = 'windwp/nvim-autopairs',
  ...
},

<Tab> worked for me with this loading order. If not maybe try adding 'gaoDean/autolist.nvim' to the dependencies list of nvim-cmp.

axieax commented 1 year ago

Hmm, I'm still getting this issue even with both of your suggestions :/

axieax commented 1 year ago

@axieax For the non-related filetypes problem, I recommend using the ft lazy loading to only load on specific filetypes like in the readme, and then using the priority to load after your other plugins. I would like lazy.nvim to support ft and event, so you can control the plugins to load one after the other, but idk, my workaround is just using ft and priority.

ft + event is possible. Mine is like this:

{ 'hrsh7th/nvim-cmp', event = {'InsertEnter', 'CmdlineEnter'}, ... }
{ 'windwp/nvim-autopairs', event = 'InsertEnter', ... },
{
  'gaoDean/autolist.nvim', 
  event = 'CursorHold *.md', 
  dependencies = 'windwp/nvim-autopairs',
  ...
},

<Tab> worked for me with this loading order. If not maybe try adding 'gaoDean/autolist.nvim' to the dependencies list of nvim-cmp.

For some reason, the CursorHold *.md doesn't even load the plugin for me

goingtosleep commented 1 year ago

Hmm, how about event = 'InsertEnter *.md' for autolist @axieax? Seems like the recent change for VeryLazy event makes CursorHold behavior change. CursorHold *.md doesn't work on my local too, but InsertEnter *.md works.

repro.lua ```lua local root = vim.fn.fnamemodify("./.repro", ":p") -- set stdpaths to use .repro for _, name in ipairs({ "config", "data", "state", "cache" }) do vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name end -- bootstrap lazy local lazypath = root .. "/plugins/lazy.nvim" if not vim.loop.fs_stat(lazypath) then vim.fn.system({ "git", "clone", "--filter=blob:none", "--single-branch", "https://github.com/folke/lazy.nvim.git", lazypath, }) end vim.opt.runtimepath:prepend(lazypath) -- install plugins local plugins = { "folke/tokyonight.nvim", { "windwp/nvim-autopairs", config = true, event = "InsertEnter", }, { "gaoDean/autolist.nvim", event = "InsertEnter *.md", dependencies = "windwp/nvim-autopairs", config = function() local autolist = require("autolist") autolist.setup() autolist.create_mapping_hook("i", "", autolist.new) autolist.create_mapping_hook("n", "o", autolist.new) autolist.create_mapping_hook('i', '', autolist.indent) autolist.create_mapping_hook('i', '', autolist.indent, '') end, }, } require("lazy").setup(plugins, { defaults = { lazy = true }, root = root .. "/plugins", }) -- add anything else here vim.opt.termguicolors = true -- do not remove the colorscheme! vim.cmd([[colorscheme tokyonight]]) ```
axieax commented 1 year ago

InsertEnter loads the plugin now which is great, but the issue still occurs, even though the ordering is correct. The issue is primarily with nvim-cmp and autolist's mapping of <Tab>. I've set nvim-cmp as a dependency of autolist which seems to resolve the loading order as well, but the main issue with the error still occurs (nil entry).

image
gaoDean commented 1 year ago

@axieax oh I had that problem as well from a bad commit, just update and it should be fine

goingtosleep commented 1 year ago

A bit strange. I tried to reproduce with cmp, autopairs and autolist (see the repro.lua below) and it seems ok 🤔:

https://user-images.githubusercontent.com/47395035/212244312-2e33ce44-1899-4b5b-aba1-5b9ec5beea7b.mp4

repro.lua

```lua local root = vim.fn.fnamemodify("./.repro", ":p") -- set stdpaths to use .repro for _, name in ipairs({ "config", "data", "state", "cache" }) do vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name end -- bootstrap lazy local lazypath = root .. "/plugins/lazy.nvim" if not vim.loop.fs_stat(lazypath) then vim.fn.system({ "git", "clone", "--filter=blob:none", "--single-branch", "https://github.com/folke/lazy.nvim.git", lazypath, }) end vim.opt.runtimepath:prepend(lazypath) -- install plugins local plugins = { "folke/tokyonight.nvim", { 'hrsh7th/nvim-cmp', config = function() local cmp = require("cmp") cmp.setup { sources = cmp.config.sources( { { name = 'buffer' }, } ), mapping = { [""] = { i = function(fallback) if cmp.visible() then cmp.select_next_item() else fallback() end end, }, [""] = { i = function(fallback) if cmp.visible() then cmp.select_prev_item() else fallback() end end, }, } } end, event = {'InsertEnter', 'CmdlineEnter'}, dependencies = { 'hrsh7th/cmp-buffer' }, }, { "windwp/nvim-autopairs", config = true, event = "InsertEnter", }, { "gaoDean/autolist.nvim", event = "InsertEnter *.md", dependencies = "windwp/nvim-autopairs", config = function() local autolist = require("autolist") autolist.setup() autolist.create_mapping_hook("i", "", autolist.new) autolist.create_mapping_hook("n", "o", autolist.new) autolist.create_mapping_hook('i', '', autolist.indent) autolist.create_mapping_hook('i', '', autolist.indent, '') end, }, } require("lazy").setup(plugins, { defaults = { lazy = true }, root = root .. "/plugins", }) -- add anything else here vim.opt.termguicolors = true -- do not remove the colorscheme! vim.cmd([[colorscheme tokyonight]]) ```
gaoDean commented 1 year ago

@goingtosleep

and it seems ok

yeah, fixed in #59 (i hope)

* f8b4c11 (HEAD -> main, origin/main, origin/HEAD) mappings: don't use buffer local mappings (#62)
* 6bf8833 (tag: v2.3.0) docs: add recal autocmd to recommended mappings (#60)
* 2ea640d indent: fix older change (#59)
axieax commented 1 year ago

That fixed the issue perfectly! Thank you so much @gaoDean and @goingtosleep :))

~Edit: is it possible to extend the event InsertEnter *.md to also include text and tex files? I'm trying something like InsertEnter *.md,*.txt,*.tex but it doesn't seem to work~ (nvm this is a lazy.nvim issue).

axieax commented 1 year ago

Actually, I was a bit confused about this issue because it seems that autolist doesn't work if I press <CR> too quickly after entering insert mode, and inserts <esc>g@la. However, this issue does not occur if I wait a bit after entering insert mode and pressing <CR>. Not sure if this issue is caused by autolist.nvim or lazy.nvim though. Would like to see if you guys can reproduce it!

Note: it's difficult to reproduce because sometimes this happens after very quickly pressing <CR>, but other times it doesn't even happen. I find it happens more often when I enter insert mode with A. Also, refreshing the buffer with :e doesn't even fix it, perhaps since it doesn't trigger another InsertEnter event, so nvim will need to be reopened each time. I'm guessing this may be caused by the TextChanged autocmd for force recalculate, but that's just a hunch.

gaoDean commented 1 year ago

@axieax I'm not too sure, because my keypresses are loaded even before the ui is loaded if i manage to press them really quickly, but the problem could be due to your autolist being loaded on InsertEnter, and the plugin requires time to load, so when you press i it must first load the plugin, then you can use it. Perhaps choose a different event?

axieax commented 1 year ago

I've managed to resolve the mapping issue by adding both nvim-cmp and nvim-autopairs as a dependency. However, the <Esc>g@la issue still appears if <CR> is pressed too soon in insert mode after the plugin loads. Is there anything that can be done to remedy this issue?