highlight-undo.nvim icon indicating copy to clipboard operation
highlight-undo.nvim copied to clipboard

Recent changes broke the `u` binding?

Open farzadmf opened this issue 1 year ago • 3 comments

Hi @tzachar , I've been using your plugin for quite a while, and I'm a big fan!

But the recent changes (specially 9cf8f05) seems to have broken u, and pressing it doesn't do anything.

This is my config that I haven't touched for a while (I'm using lazy.nvim):

{
  'tzachar/highlight-undo.nvim',
  url = 'https://github.com/tzachar/highlight-undo.nvim.git',
  event = {
    'BufNew',
    'BufNewFile',
    'BufReadPost',
  },
  opts = {},
}

Do I need to change anything because of the recent changes?

farzadmf avatar Sep 30 '24 13:09 farzadmf

No. Your config looks ok and work in my setup. What is the output of :nmap u ?

tzachar avatar Oct 01 '24 08:10 tzachar

Hey @tzachar ; thank you for your reply; this is the output of :verbose nmap u:

n  u           * <Lua 1095: ~/.local/share/nvim/nvim_lzv/data/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:130>
	Last set from Lua (run Nvim with -V1 for more details)

farzadmf avatar Oct 01 '24 13:10 farzadmf

Update on this: seems to be an issue when using mini.starter, I put some prints in highlight-undo, and when I press u it ends up in lines 148-149

highlight-undo seems to assume rhs is a key (if I'm not mistaken), but when I print org_mapping.rhs, I have

<Cmd>lua MiniStarter.add_to_query("u")<CR>

So, that's probably why it's not working (I may be totally wrong!)

farzadmf avatar Oct 01 '24 16:10 farzadmf

This is strange. Ending up in line 148 means that you set the rhs in your config of the plugins, which seems to not be the case as you left the config as default. Are you sure you are on the latest version? Can you also dump the entire opts and org_mapping on entry to this function?

tzachar avatar Oct 06 '24 05:10 tzachar

Running into the same thing. Recently updated my plugins via lazy and this stopped working. I tried 2 different configs:

Default config

  {
    'tzachar/highlight-undo.nvim',
    keys = { { "u" }, { "<C-r>" } },
  },

Nothing happens when I press u or <C-r>. As in, my undo changes aren't highlighted.

:nmap u
n  u           * <Lua 59: /home/hqkhan/.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/handler/keys.lua:121>

My original config

  {
    'tzachar/highlight-undo.nvim',
    event = "VeryLazy",
    config = function()
      require('highlight-undo').setup({
        hlgroup = 'HighlightUndo',
        duration = 300,
        keymaps = {
          { 'n', 'u',     'undo', {} },
          { 'n', '<C-r>', 'redo', {} },
        }
      })
    end
  },

This gives me the error of:

Failed to run `config` for highlight-undo.nvim

...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:142: attempt to index field 'opts' (a nil value)

Line 142 looks for opts. The hijack function should be called per hijacked keymap correct?

hqkhan avatar Nov 04 '24 15:11 hqkhan

On second thought, I was incorrect, it's working for me after I changed config to the following:

  {
    'tzachar/highlight-undo.nvim',
    event = "VeryLazy",
    config = function()
      require('highlight-undo').setup({
        duration = 300,
        keymaps = {
          undo = {
            desc = "undo",
            hlgroup = 'HighlightUndo',
            mode = 'n',
            lhs = 'u',
            rhs = nil,
            opts = {},
          },
          redo = {
            desc = "redo",
            hlgroup = 'HighlightUndo',
            mode = 'n',
            lhs = '<C-r>',
            rhs = nil,
            opts = {},
          },
        },
      })
    end
  },

Needed opts.

hqkhan avatar Nov 04 '24 16:11 hqkhan

It also affects p paste. The feature is not working as expected.

The commit where the issue is introduced is 9cf8f052e86a5a323b16d17bad12f7cb73b248eb, if I go back to 1ea1c79372d7d93c88fd97543880927b7635e3d2 everything works correctly.

Zeioth avatar Nov 11 '24 19:11 Zeioth

It also affects p paste. The feature is not working as expected.

The commit where the issue is introduced is 9cf8f05, if I go back to 1ea1c79 everything works correctly.

Same here.

chapeupreto avatar Nov 12 '24 02:11 chapeupreto

The change introduced in 9cf8f05 is a major rewrite of the hijacking logic. Can you attach your configs which fail to catch p ?

tzachar avatar Nov 12 '24 08:11 tzachar

I have the same issue. I could not undo till I disabled undo-highlight plugin

khalidchawtany avatar Nov 16 '24 11:11 khalidchawtany

I'm seeing a similar problem, except with the l key.

$ nvim --version

NVIM v0.10.2 Build type: RelWithDebInfo LuaJIT 2.1.1727870382 Run "nvim -V1 -v" for more info

$ git co 9cf8f052e86a5a323b16d17bad12f7cb73b248eb~

:nmap l

No mapping found

$ git co 9cf8f052e86a5a323b16d17bad12f7cb73b248eb

:nmap l

n lhs * <Lua 78: ~/.local/share/nvim/site/pack/myplugins/start/highlight-undo.nvim/lua/highlight-undo.lua:130>

My ~/.config/nvim/plugin/highlight-undo.lua is the same config as this https://github.com/tzachar/highlight-undo.nvim#setup

When I comment-out the Keymap_name table, the problem goes away.

planet36 avatar Nov 20 '24 22:11 planet36

Hey! i have same issue. i updated today and i can't undo with u neither C-R keymap

My log:

E5108: Error executing lua: vim/_editor.lua:0: nvim_exec2(): Vim(redo):E21: No se pudo modificar, 'modifiable' está desactivado
stack traceback:
	[C]: in function 'nvim_exec2'
	vim/_editor.lua: in function 'cmd'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:38: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:169: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function <...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:143>

My plugin config file (using nvim-lazy plugin manager)

return {
  'tzachar/highlight-undo.nvim',
  opts = {},
}

Output of nmap u:

n  u           * <Lua 50: ~/.local/share/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:143>

thanks in advance!

holic-cl avatar Dec 13 '24 07:12 holic-cl

@holic-cl I can't reproduce this. Which other plugins are you using? Which nvim version?

tzachar avatar Dec 15 '24 06:12 tzachar

@tzachar

My nvim version:

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1713484068

My plugins

alpha-nvim
bufferline.nvim
catppuccint
cmp-buffercmp
cmp-nvim-lsp
cmp-path
cmp_luasnip
Comment.nvim
dressing.nvim
flash.nvim
friendly-snippets
fzf-lua
gitsigns.nvim
highlight-undo.nvim
indent-blankline.nvim
jump-tag
lazy.nvim
lazydev.nvim
lspkind.nvim
lualine.nvim
LuaSnip
mason-lspconfig.nvim
mason-tool-installer.nvim
mason.nvim
noice.nvim
nui.nvim
nvim-autopairs
nvim-cmp
nvim-colorizer.lua
nvim-lint
nvim-lsp-file-operations
nvim-lspconfig
nvim-notify
nvim-spider
nvim-surround
nvim-tree.lua
nvim-treesitter
nvim-treesitter-textobjects
nvim-ts-autotag
nvim-ts-context-commentstring
nvim-web-devicons
plenary.nvim
scope.nvim
snacks.nvim
substitute.nvim
tailwind-tools
telescope-fzf-native.nvim
telescope.nvim
tiny-inline-diagnostic.nvim
todo-comments.nvim
tokyonight.nvim
vim-visual-multi
which-key.nvim
conform.nvim
grug-far.nvim
harpoon
lazygit.nvim
nvim-bqf
nvim-rip-substitute
package-info.nvim
qf_helper.nvim
trouble.nvim
vim-maximizer
yanky.nvim

holic-cl avatar Dec 18 '24 03:12 holic-cl

which-key.nvim does something similar to this plugin. try to make sure this plugin is loaded last.

tzachar avatar Dec 18 '24 08:12 tzachar

A similar problem is with the hardtime.nvim plugin. If I do not load these the plugin works as expected. But if I try to load it after them it does not work and sometimes throws a stack overflow error. When I load it before these two it does not throw but the highlighting does not work. If i revert back to 1ea1c79 the highlighting does not work with these two enabled. I am not sure if this is the same issue or not though.

kunzaatko avatar Dec 18 '24 18:12 kunzaatko

I am having a hard time recreating these bugs. Can someone please share a minimal working configuration which reliably trigger these issues? @kunzaatko @farzadmf @holic-cl ? Thanks

tzachar avatar Dec 19 '24 08:12 tzachar

I also have this issue, below is the stacktrace, not sure if that is of any help....

Error  18:06:49 msg_show.emsg E5108: Error executing lua: stack overflow
stack traceback:
	[C]: in function '__index'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:147: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function <...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:143>

tlvenn avatar Feb 04 '25 10:02 tlvenn

Try changing the order in which you load plugins. The stack trace above can happen when a different plugin also hijacks the keybinding.

tzachar avatar Feb 04 '25 14:02 tzachar

I know I'm being a bit forward, but you might want to try https://github.com/aileot/emission.nvim. The plugin is a fork of this highlight-undo.nvim, but any keymaps are irrelevant there.

(sorry for the manner to the original author, but plugin loading order is almost implicitly handled by plugin manager so that such reports due to the keymap conflicts would not be going away...)

aileot avatar Feb 05 '25 14:02 aileot

I know I'm being a bit forward, but you might want to try https://github.com/aileot/emission.nvim. The plugin is a fork of this highlight-undo.nvim, but any keymaps are irrelevant there.

(sorry for the manner to the original author, but plugin loading order is almost implicitly handled by plugin manager so that such reports due to the keymap conflicts would not be going away...)

@aileot I Would have greatly appreciated any pull requests to fix these issues.

tzachar avatar Feb 06 '25 14:02 tzachar

Well, though I don't like the following approach, mapping keys buffer-locally on every BufEnter event would be a workaround to avoid keymap conflicts.

vim.schedule or vim.defer_fn could also help avoid keymap conflicts due to lazily-loaded plugins on BufEnter.

aileot avatar Feb 06 '25 15:02 aileot

This will not fix the issue in all cases. There is no mechanism to ensure our plugin is loaded last.

tzachar avatar Feb 09 '25 06:02 tzachar

You are right. So did I comment. I don't mean to pick a fight.

aileot avatar Feb 09 '25 07:02 aileot

Just looking for ideas for solving this issue.

tzachar avatar Feb 09 '25 10:02 tzachar

I also have this issue, below is the stacktrace, not sure if that is of any help....

Error  18:06:49 msg_show.emsg E5108: Error executing lua: stack overflow
stack traceback:
	[C]: in function '__index'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:147: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function 'callback'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:148: in function 'command'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:111: in function 'highlight_undo'
	...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:144: in function <...are/nvim/lazy/highlight-undo.nvim/lua/highlight-undo.lua:143>

Update config https://github.com/tzachar/highlight-undo.nvim/commit/9cf8f052e86a5a323b16d17bad12f7cb73b248eb#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R33 Like this. I have same issue before update

{
    "tzachar/highlight-undo.nvim",
    opts = {
        duration = 300,
        keymaps = {
            undo = {
                desc = "undo",
                hlgroup = "HighlightUndo",
                mode = "n",
                lhs = "u",
                rhs = nil,
                opts = {},
            },
            redo = {
                desc = "redo",
                hlgroup = "HighlightRedo",
                mode = "n",
                lhs = "<C-r>",
                rhs = nil,
                opts = {},
            },
        },
    },
}

yorik1984 avatar Feb 10 '25 19:02 yorik1984

I think the solution would be to ditch the notion of binding to specific keys, and just track changes when not in insert mode. Can you guys try the global tracking branch

tzachar avatar Feb 11 '25 11:02 tzachar

fixed by #38

tzachar avatar Feb 13 '25 15:02 tzachar

Thank you very much @tzachar ; I can finally reuse the plugin again ❤

farzadmf avatar Feb 14 '25 04:02 farzadmf