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

Provide a lua API instead of a string command #61

Closed
rudenkornk opened this issue Mar 12, 2023 · 1 comment
Closed

Provide a lua API instead of a string command #61

rudenkornk opened this issue Mar 12, 2023 · 1 comment

Comments

@rudenkornk
Copy link

Hi! Thanks for this awesome plugin!
I set up this plugin in my config and found a little inconvenience. Readme suggests to set up keybindings this way:

vim.keymap.set("n", "<C-a>", require("dial.map").inc_normal(), {noremap = true})

As I understand inc_normal returns a strings instead of actually executing a command. But it does not play well with Packer's lazy loading, because it requires dial to load at the beginning.
I tried to wrap it with a function calling vim.command(...) and using keys entry in Packer triggers, but none of that worked.
The most reliable way I found is using module trigger and then calling dial inside some function. But this requies inc_normal to be an action.
So, is it possible to provide such interface?

@rudenkornk
Copy link
Author

Oh, never mind, I figured that out. I just have to use expr = true. In my nvchad-based config it looks like this:

M.dial = {
  n = {
    ["<C-a>"] = {
      function()
        return require("dial.map").inc_normal()
      end,
      opts = { expr = true },
    },
    ["<C-x>"] = {
      function()
        return require("dial.map").dec_normal()
      end,
      opts = { expr = true },
    },
  },
  v = {
    ["<C-a>"] = {
      function()
        return require("dial.map").inc_visual()
      end,
      opts = { expr = true },
    },
    ["<C-x>"] = {
      function()
        return require("dial.map").dec_visual()
      end,
      opts = { expr = true },
    },
    ["g<C-a>"] = {
      function()
        return require("dial.map").inc_gvisual()
      end,
      opts = { expr = true },
    },
    ["g<C-x>"] = {
      function()
        return require("dial.map").dec_gvisual()
      end,
      opts = { expr = true },
    },
  },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant