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

feat: plugin interface for key events via ya.which() #617

Merged
merged 2 commits into from
Feb 2, 2024
Merged

Conversation

sxyazi
Copy link
Owner

@sxyazi sxyazi commented Feb 2, 2024

In async plugins, you can use ya.which() to prompt users with a set of available keys:

return {
  entry = function()
    local key = ya.which {
      cands = {
        { on = "a" },
        { on = "b", desc = "optional description" },
        { on = "<C-c>", desc = "key combination" },
        { on = { "d", "e" }, desc = "multiple keys" },
      },
      -- silent = true, -- If you don't want to show the UI of key indicator
    }

    ya.err(key)
  end,
}

When the user clicks a valid candidate, ya.which returns the 1-based index of that "cand"; otherwise, it returns nil, indicating that the user has canceled the key operation.

ya.which.mp4

If you want to use the key in a sync plugin, you can awaken the plugin in an async plugin by:

ya.manager_emit("plugin", { "your-sync-plugin", sync = "", args = tostring(key) })

The next target will allow direct calls of sync code within async plugins, making it much simpler. For now, please proceed with this approach.

@sxyazi sxyazi merged commit b51d1f2 into main Feb 2, 2024
3 checks passed
@sxyazi sxyazi deleted the pr-a34834a4 branch February 2, 2024 17:09
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant