From fb16fadd642fa6a37ff1abc1cd60e5710250f2a2 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Mon, 6 Jan 2025 15:10:14 -0800 Subject: [PATCH] Add iter to VimBuffer Fix #1041: iterating over snip.buffer fails in neovim. Use __iter__() to defer iteration of a buffer to the underlying object. Test * Run this code in neovim and vim: import vim import UltiSnips.vim_helper as helper def dump(b): for line in b: print(line.upper()) # This works fine in both nvim and vim. dump(vim.current.buffer) # In nvim, the iteration previously failed with "pynvim.api.common.NvimError: Index out of bounds" dump(helper.VimBuffer()) --- pythonx/UltiSnips/vim_helper.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pythonx/UltiSnips/vim_helper.py b/pythonx/UltiSnips/vim_helper.py index e295abcc..19feec7f 100755 --- a/pythonx/UltiSnips/vim_helper.py +++ b/pythonx/UltiSnips/vim_helper.py @@ -28,6 +28,9 @@ def __setitem__(self, idx, text): def __len__(self): return len(vim.current.buffer) + def __iter__(self): + return iter(vim.current.buffer) + @property def line_till_cursor(self): # pylint:disable=no-self-use """Returns the text before the cursor."""