Olical / aniseed

Neovim configuration and plugins in Fennel (Lisp compiled to Lua)
https://discord.gg/wXAMr8F
The Unlicense
610 stars 28 forks source link

Can't set auto-pairs to be empty table #108

Closed D00mch closed 2 years ago

D00mch commented 2 years ago

Don't sure if the question is appropriate here, but may be you will be able to answer it immediately:

In your dotfiles you have dotfilnves.plugin.auto-pairs where you use nvim.g.AutoPairs like this:

(defn init []
  (let [auto-pairs nvim.g.AutoPairs]
    (tset auto-pairs "'" nil)
    (tset auto-pairs "`" nil)
    (set nvim.b.AutoPairs auto-pairs)))

I tried to use jusn an empty table (as it works without this plugin in lisps) with code

(defn init []
  (let [d {}] 
    (set nvim.b.AutoPairs d)))

But I get the error:

Error detected while processing function AutoPairsTryInit[62]..AutoPairsInit:  
line   22:
E715: Dictionary required
E1098: String, List or Blob required

On line 22 of autoPairs there is this line

image

which doesn't tell me anything.

And before I have this line in vimrc and it worked just fine: au Filetype clojure let b:AutoPairs={}

Olical commented 2 years ago

This looks like it's a Lua -> VimL conversion issue. An empty Lua table is ambiguous, it can be a sequential or an associative structure so Vim is probably converting it to a list rather than a dict. Not sure how we force this to produce a dict instead of a list... maybe there's a function under :h api or anywhere else in nvim that allows you to create an empty dict and force it to be a dict 🤔

I'm not at a laptop right now but that's my thinking and where I'd look, I'd look for a function that creates a table that's maybe annotated in such a way that nvim knows to convert the lua table to a dict, not a list, as it crosses the boundary.

Olical commented 2 years ago

Ah yeah, vim.empty_dict() looks like what you want. I just searched for "neovim lua pass empty dict" for context.