vim

FlavaDave 2024-06-17T03:51:50.714299Z

I'm having trouble using the register method for which key to register key bindings for nvim-paredit. I can get most of them to work but when I want to register commands that normally take extra options upon setup I am having a hard time setting them without errors. For example in the nvim-paredit docs you see this example:

["af"] = {
      paredit.api.select_around_form,
      "Around form",
      repeatable = false,
      mode = { "o", "v" }
    },
    ["if"] = {
      paredit.api.select_in_form,
      "In form",
      repeatable = false,
      mode = { "o", "v" }
    },
    ["aF"] = {
      paredit.api.select_around_top_level_form,
      "Around top level form",
      repeatable = false,
      mode = { "o", "v" }
    },
    ["iF"] = {
      paredit.api.select_in_top_level_form,
      "In top level form",
      repeatable = false,
      mode = { "o", "v" }
I am trying remap those keybindings with register and have tried something like this as a first pass and got errors (not surprised)
[{1 :julienvincent/nvim-paredit
  :ft [:clojure :fennel]
  :config (fn []
            (let [paredit (require :nvim-paredit)
                  wk (require :which-key)]
              (paredit.setup {:keys {}})))
  :init (fn []
          (let [paredit (require :nvim-paredit)
                wk (require :which-key)]
            (wk.register {:<leader> {
                                     ,,,
                                     :a {:name "[a]round"
                                         :f {1 paredit.api.select_around_form
                                             2 "[f]orm"
                                             :repeatable false
                                             :mode [:o :v]}
                                         :F {1 paredit.api.select_around_top_level_form
                                             2 "top level [F]orm"
                                             :repeatable false
                                             :mode [:o :v]}
                                         :e {1 paredit.api.select_element
                                             2 "[e]lement"
                                             :repeatable false
                                             :mode [:o :v]}}
                                         ,,,
                                   }})))}
 {1 :julienvincentnvim-paredit-fennel
  :dependencies [:julienvincent/nvim-paredit]
  :lazy true
  :ft [:fennel]
  :config (fn []
            (let [paredit-fnl (require :nvim-paredit-fennel)]
              (paredit-fnl.setup)))}]
I know that I could do this with the setup method in the nvim-paredit suggested in the docs but I like being able to name my intermediate keys and would prefer to use the same method to map my keys across the board. Can anyone help me out?

2024-06-17T13:36:10.223019Z

i don't know how which-key.register works, but I was able to do this using the nvim-paredit.setup function

2024-06-17T13:38:57.419119Z

i define some local functions and then call

...
    paredit.setup({
      use_default_keys = true,
      filetypes = { "clojure", "scheme", "lisp", "fennel" },
      cursor_behaviour = "follow",
      keys = {
        -- Wrap enclosing form in given type, enter insert mode at start or end
        ["i"] = {
          enclosing_wrapper_maker({"( ", ")"}, "inner_start"),
          "Wrap form round, insert head",
        },
...

2024-06-17T13:40:29.450709Z

adding the docstring makes it show up in which-key's pop-up, so maybe if you switch to using nvim-paredit.setup, it'll work for you?