b0o/mapx.nvim

`v:lua` string doesn't work

Closed this issue · 4 comments

I have the following code to be converted.

local escape = function(str)
  return vim.api.nvim_replace_termcodes(str, true, true, true)
end

-- HACK
function _G.enhance_align()
  if not packer_plugins["vim-easy-align"].loaded then
    vim.cmd [[packadd vim-easy-align]]
  end
  return escape "<Plug>(EasyAlign)"
end

function M.setup_easy_align()
  vim.api.nvim_set_keymap("n", "ga", "v:lua.enhance_align()", { expr = true })
  vim.api.nvim_set_keymap("x", "ga", "v:lua.enhance_align()", { expr = true })
end

First I tried the following, which doesn't work

  mapx.nmap("ga", "v:lua.enhance_align()", mapx.expr)
  mapx.xmap("ga", "v:lua.enhance_align()", mapx.expr)

Then I make it work using the following

  mapx.nmap("ga", enhance_align, mapx.expr)
  mapx.xmap("ga", enhance_align, mapx.expr)

I am not sure whether this is a bug.

A related problem is that if I add whichkey labels

  local label = "EasyAlign"
  mapx.nmap("ga", enhance_align, mapx.expr, label)
  mapx.xmap("ga", enhance_align, mapx.expr, label)

it fails with the error

mapx.nvim/lua/mapx/mapper.lua:139: invalid key: 1"
b0o commented

First I tried the following, which doesn't work

Can you elaborate on this, is there an error message? Using v:lua works for me.

A related problem is that if I add whichkey labels

Is this the same issue as #7?

The second one may be related to that issue.
Though it raises an error while not in the issue.

After update to the newest version, it doesn't raise an error.
When execute ga on the following example, it output <|> 124, Hex 7c, Oct 174, Digr !!. It just seems the map doesn't take effect, which is the same in issue #7.

| asdfaf| |
| --0- | --- |

In the newest version, the v:lua works for me.