jake-stewart/multicursor.nvim

[Bug] attempt to index local 'cursor' (a nil value)

Closed this issue · 3 comments

After updating the plugin today, I get this error spammed

...a/.local/share/nvim/lazy/nui.nvim/lua/nui/split/init.lua:169: Error executing lua: ...a/.local/share/nvim/lazy/nui.nvim/lua/nui/split/init.lua:170: WinLeave Autocommands for "*": Vim(append):Error executing lua callback: ...multicursor.nvim/lua/multicursor-nvim/cursor-manager.lua:1058: attempt to index local 'cursor' (a nil value)
stack traceback:
	...multicursor.nvim/lua/multicursor-nvim/cursor-manager.lua:1058: in function 'cursorCopy'
	...multicursor.nvim/lua/multicursor-nvim/cursor-manager.lua:1429: in function 'clear'
	...multicursor.nvim/lua/multicursor-nvim/cursor-manager.lua:1945: in function 'clear'
	...nvim/lazy/multicursor.nvim/lua/multicursor-nvim/core.lua:33: in function <...nvim/lazy/multicursor.nvim/lua/multicursor-nvim/core.lua:32>
	[C]: in function 'nvim_command'
	...a/.local/share/nvim/lazy/nui.nvim/lua/nui/split/init.lua:170: in function <...a/.local/share/nvim/lazy/nui.nvim/lua/nui/split/init.lua:169>
	[C]: in function 'nvim_win_call'
	...a/.local/share/nvim/lazy/nui.nvim/lua/nui/split/init.lua:169: in function '_open_window'
	...a/.local/share/nvim/lazy/nui.nvim/lua/nui/split/init.lua:257: in function 'mount'
	....local/share/nvim/lazy/noice.nvim/lua/noice/view/nui.lua:107: in function 'mount'
	....local/share/nvim/lazy/noice.nvim/lua/noice/view/nui.lua:94: in function 'create'
	...
	[C]: in function 'xpcall'
	...local/share/nvim/lazy/noice.nvim/lua/noice/util/call.lua:149: in function <...local/share/nvim/lazy/noice.nvim/lua/noice/util/call.lua:134>
	...local/share/nvim/lazy/noice.nvim/lua/noice/view/init.lua:163: in function 'display'
	.../share/nvim/lazy/noice.nvim/lua/noice/message/router.lua:214: in function <.../share/nvim/lazy/noice.nvim/lua/noice/message/router.lua:148>
	[C]: in function 'xpcall'
	...local/share/nvim/lazy/noice.nvim/lua/noice/util/call.lua:149: in function <...local/share/nvim/lazy/noice.nvim/lua/noice/util/call.lua:134>
	[C]: in function 'pcall'
	...local/share/nvim/lazy/noice.nvim/lua/noice/util/init.lua:146: in function ''
	vim/_editor.lua: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>
stack traceback:
	[C]: in function 'nvim_command'
	...a/.local/share/nvim/lazy/nui.nvim/lua/nui/split/init.lua:170: in function <...a/.local/share/nvim/lazy/nui.nvim/lua/nui/split/init.lua:169>
	[C]: in function 'nvim_win_call'
	...a/.local/share/nvim/lazy/nui.nvim/lua/nui/split/init.lua:169: in function '_open_window'
	...a/.local/share/nvim/lazy/nui.nvim/lua/nui/split/init.lua:257: in function 'mount'
	....local/share/nvim/lazy/noice.nvim/lua/noice/view/nui.lua:107: in function 'mount'
	....local/share/nvim/lazy/noice.nvim/lua/noice/view/nui.lua:94: in function 'create'
	....local/share/nvim/lazy/noice.nvim/lua/noice/view/nui.lua:271: in function 'show'
	...local/share/nvim/lazy/noice.nvim/lua/noice/view/init.lua:156: in function <...local/share/nvim/lazy/noice.nvim/lua/noice/view/init.lua:154>
	[C]: in function 'xpcall'
	...local/share/nvim/lazy/noice.nvim/lua/noice/util/call.lua:149: in function <...local/share/nvim/lazy/noice.nvim/lua/noice/util/call.lua:134>
	...local/share/nvim/lazy/noice.nvim/lua/noice/view/init.lua:163: in function 'display'
	.../share/nvim/lazy/noice.nvim/lua/noice/message/router.lua:214: in function <.../share/nvim/lazy/noice.nvim/lua/noice/message/router.lua:148>
	[C]: in function 'xpcall'
	...local/share/nvim/lazy/noice.nvim/lua/noice/util/call.lua:149: in function <...local/share/nvim/lazy/noice.nvim/lua/noice/util/call.lua:134>
	[C]: in function 'pcall'
	...local/share/nvim/lazy/noice.nvim/lua/noice/util/init.lua:146: in function ''
	vim/_editor.lua: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>

Heres my setup:

modules["jake-stewart/multicursor.nvim"] = {
  commit = funcs.get_commit("multicursor.nvim", plugins_snapshot),
  config = function()
    local mc = require("multicursor-nvim")
    local wk = require("which-key")

    mc.setup()

    wk.add({
      mode = { "n", "v" },
      {
        "<C-Down>",
        function()
          mc.addCursor("j")
        end,
        desc = "Add cursor below",
      },
      {
        "<C-Up>",
        function()
          mc.addCursor("k")
        end,
        desc = "Add cursor above",
      },
      {
        "mm",
        function()
          mc.addCursor("*")
        end,
        desc = "Add cursor word below",
      },
      {
        "mM",
        function()
          mc.skipCursor("*")
        end,
        desc = "Add skip cursor next",
      },
      {
        "mp",
        function()
          mc.addCursor("#")
        end,
        desc = "Add cursor word above",
      },
      {
        "mP",
        function()
          mc.skipCursor("#")
        end,
        desc = "Add skip cursor word above",
      },
      {
        "ma",
        function()
          mc.matchAllAddCursors()
        end,
        desc = "Add cursor all matches",
      },
      -- {
      --   "<c-n>",
      --   function()
      --     mc.addCursor("*")
      --   end,
      --  desc = "Add cursor and jump to next word",
      -- },
      -- { "<left>", mc.nextCursor, "Rotate to next cursor" },
      -- { "<right>", mc.prevCursor, "Rotate to previous cursor" },
      -- { "<leader>x", mc.deleteCursor, "Delete main cursor" },
      -- {
      --   "<c-q>",
      --   function()
      --     if mc.cursorsEnabled() then
      --       mc.disableCursors()
      --     else
      --       mc.addCursor()
      --     end
      --   end,
      --   "Toggle cursor movement",
      -- },
    })

    wk.add({
      mode = "n",
      { "<M-LeftMouse>", mc.handleMouse, desc = "Add/remove cursor with mouse" },
      {
        "<esc>",
        function()
          if not mc.cursorsEnabled() then
            mc.enableCursors()
          elseif mc.hasCursors() then
            mc.clearCursors()
          else
            -- Default <esc> handler
            vim.cmd("noh")
          end
        end,
        desc = "Enable/clear cursors or default action",
      },
      -- { "mA", mc.alignCursors, desc = "Align cursor columns" },
    })

    wk.add({
      mode = "v",
      -- { "S", mc.splitCursors,desc = "Split visual selections by regex" },
      { "I", mc.insertVisual, desc = "Insert for each line of visual selections" },
      { "A", mc.appendVisual, desc = "Append for each line of visual selections" },
      -- { "M", mc.matchCursors, desc ="Match new cursors within visual selections" },
      -- {
      --   "<leader>t",
      --   function()
      --     mc.transposeCursors(1)
      --   end,
      --   "Rotate visual selection contents forward",
      -- },
      -- {
      --   "<leader>T",
      --   function()
      --     mc.transposeCursors(-1)
      --   end,
      --   desc ="Rotate visual selection contents backward",
      -- },
    })

    -- Customize how cursors look.
    vim.api.nvim_set_hl(0, "MultiCursorCursor", { link = "Cursor" })
    vim.api.nvim_set_hl(0, "MultiCursorVisual", { link = "Visual" })
    vim.api.nvim_set_hl(0, "MultiCursorSign", { link = "SignColumn" })
    vim.api.nvim_set_hl(0, "MultiCursorDisabledCursor", { link = "Visual" })
    vim.api.nvim_set_hl(0, "MultiCursorDisabledVisual", { link = "Visual" })
    vim.api.nvim_set_hl(0, "MultiCursorDisabledSign", { link = "SignColumn" })
  end,
}

I've not changed my config and the plugin was working before

@Ajaymamtora are you on the latest update? try updating again

@Ajaymamtora are you on the latest update? try updating again

Thanks, just updated again and its sorted :)

sorry about that. introduced it while adding the new mc.restoreCursors()