Skip to content

Repeating some moves gives "Vim(normal):E523: Not allowed here" error on main #775

@michelesr

Description

@michelesr

Describe the bug
In the main branch, now you need to set {expr = true} when mapping the ;, , repeat functions, so that you can also configure repeat for builtins f,F,t,T.

-- Repeat movement with ; and ,
-- ensure ; goes forward and , goes backward regardless of the last direction
vim.keymap.set({ "n", "x", "o" }, ";", ts_repeat_move.repeat_last_move_next, { expr = true })
vim.keymap.set({ "n", "x", "o" }, ",", ts_repeat_move.repeat_last_move_previous, { expr = true })

By doing this, moves that make use of :normal commands return error.

To Reproduce
Steps to reproduce the behavior:

  1. configure mapping for repeat_last_move_next and repeat_last_move_previous
  2. try a repeatable action, for example "go to next start of @function.outer" (e.g. ]m)
  3. try to repeat with ;, ,

Expected behavior
The action should be repeated without errors.

** What happens **

E5108: Error executing lua: vim/_editor.lua:0: nvim_exec2(), line 1: Vim(normal):E523: Not allowed here
stack traceback:
        [C]: in function 'nvim_exec2'
        vim/_editor.lua: in function 'cmd'
        ...ter-textobjects/lua/nvim-treesitter-textobjects/move.lua:16: in function 'goto_node'
        ...ter-textobjects/lua/nvim-treesitter-textobjects/move.lua:135: in function <...ter-textobjects/lua/nvim-treesitter-textobjects/move.lua:41>

Output of nvim --version

NVIM v0.11.1
Build type: Release
LuaJIT 2.1.1744318430

** Additional info **

When I was trying to make my own repetable function work, I noticed that wrapping with vim.schedule() bypasses the issue:

  local diag_move = require('nvim-treesitter-textobjects.repeatable_move').make_repeatable_move(function(opts)
    if opts.forward then
      -- schedule() prevents Vim(normal):E523: Not allowed here
      -- that would arise because ; , are mapped with { expr = true }
      vim.schedule(function() vim.diagnostic.jump({count = 1}) end)
    else
      vim.schedule(function() vim.diagnostic.jump({count = -1}) end)
    end
  end)

Metadata

Metadata

Assignees

No one assigned

    Labels

    NEXTissues and PRs relating to the 1.0 refactor on `main`bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions