Skip to content

Commit

Permalink
feat(wrapper): add keymap/set-maps! for runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
aileot committed Oct 30, 2022
1 parent 5b94287 commit fc2a1e1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
23 changes: 22 additions & 1 deletion fnl/nvim-laurel/wrapper.fnl
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
;; Note: Define wrapper functions to deal with values hidden in compile time.
;; Wrappers make it easier to debug in compiled lua codes.

(local {: keymap/->compatible-opts!} (require :nvim-laurel.utils))

(macro str? [x]
"Check if `x` is of string type."
`(= :string (type ,x)))

(lambda merge-api-opts [?api-opts ?extra-opts]
"Merge `?api-opts` into `?extra-opts`.
Expand All @@ -12,4 +18,19 @@
(values k v))
(or ?api-opts ?extra-opts {})))

{: merge-api-opts}
(lambda keymap/set-maps! [modes extra-opts lhs rhs ?api-opts]
(let [?bufnr extra-opts.buffer
api-opts (merge-api-opts ?api-opts
(keymap/->compatible-opts! extra-opts))
set-keymap (if ?bufnr
(lambda [mode]
(vim.api.nvim_buf_set_keymap ?bufnr mode lhs rhs
api-opts))
(lambda [mode]
(vim.api.nvim_set_keymap mode lhs rhs api-opts)))]
(if (str? modes)
(set-keymap modes)
(each [_ m (ipairs modes)]
(set-keymap m)))))

{: merge-api-opts : keymap/set-maps!}
25 changes: 23 additions & 2 deletions lua/nvim-laurel/wrapper.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fc2a1e1

Please sign in to comment.