Python integration in Vim 8.0 provides a handful of useful python objects in
vim module. In particular, there are per-buffer objects accessible via
vim.buffers list and
vim.current.buffer. One can set or read per-buffer variables and options by accessing
b.options dict-like objects, where
b is that buffer object.
However, Vim variables are necessarily strings and one cannot store arbitrary python objects in there. How do I store an arbitrary per-buffer python object?
I tried adding a custom attribute on the buffer object via
setattr(b, ...) or via assigning to
b.__dict__[...] but that does not work (these objects have no
__setattr__()), same for subobjects.
It is also possible to have a global dictionary indexed by buffer number (
b.number) and hook into the BufDelete autocmd for cleanup. This is what I use right now, but that feels kludgy and I seek a better solution, if there is one.