Skip to content
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

Can't set keymap using table with action option #2111

Closed
zubrailx opened this issue Aug 6, 2022 · 3 comments
Closed

Can't set keymap using table with action option #2111

zubrailx opened this issue Aug 6, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@zubrailx
Copy link
Contributor

zubrailx commented Aug 6, 2022

Description

When customizing mapping using table with telescope action field the following error occurs:

E5108: Error executing lua ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:338: attempt to call local 'key_func' (a table value)
stack traceback:
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:338: in function 'execute_keymap'
        [string ":lua"]:1: in main chunk

Neovim version

NVIM v0.7.2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

Gentoo Base System release 2.8 x86_64

Telescope version / branch / rev

latest using packer.nvim

checkhealth telescope

## Checking for required plugins
  - OK: plenary installed.
  - OK: nvim-treesitter installed.

## Checking external dependencies
  - OK: rg: found ripgrep 13.0.0
  - OK: fd: found fd 8.2.1

## ===== Installed extensions =====

Steps to reproduce

  1. nvim -nu minimal.lua
  2. Open telescope using :Telescope
  3. Go to normal mode using <esc>
  4. Press <esc> again

Expected behavior

Telescope window is closed

Actual behavior

Getting an error:

E5108: Error executing lua ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:338: attempt to call local 'key_func' (a table value)
stack traceback:
        ...k/packer/start/telescope.nvim/lua/telescope/mappings.lua:338: in function 'execute_keymap'
        [string ":lua"]:1: in main chunk

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        'nvim-telescope/telescope.nvim',
        requires = {
          'nvim-lua/plenary.nvim',
          { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' },
        },
      },
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end

_G.load_config = function()
  local telescope = require("telescope")
  local actions = require("telescope.actions")
  telescope.setup({
    defaults = {
      mappings = {
        i = {
        },
        n = {
          ["<esc>"] = { action = actions.close, opts = { silent = true, nowait = true } }, -- error when trying to press escape

          -- ["<esc>"] = {
          --   "<cmd>lua require('telescope.actions').close(vim.api.nvim_get_current_buf())<cr>",
          --   type = "command", opts = { silent = true, nowait = true }
          -- }, -- works fine
          
          -- ["<esc>"] = actions.close, -- also fine
        }
      }
    },
  })
  require('telescope').load_extension('fzf')
  -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]
@zubrailx zubrailx added the bug Something isn't working label Aug 6, 2022
@fdschmidt93
Copy link
Member

fdschmidt93 commented Aug 9, 2022

I've briefly looked at the code and I think the docs are wrong.

Does

["<esc>"] = { actions.close, kind = "action", opts = { silent = true, nowait = true } }, -- error when trying to press escape

work as intended for you?

@zubrailx
Copy link
Contributor Author

zubrailx commented Aug 10, 2022

This

["<esc>"] = { actions.close, type = "action", opts = { silent = true, nowait = true } }, -- error when trying to press escape

works fine, thank you for the response. Should it be mentioned in the documentation?

@Conni2461
Copy link
Member

yes, do mind posting a PR that updates the documentation? should be updated here:

--- action = actions.move_selection_next,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants