Skip to content

Commit

Permalink
Add iter to VimBuffer
Browse files Browse the repository at this point in the history
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())
  • Loading branch information
idbrii committed Jan 8, 2025
1 parent 49dc8cb commit fb16fad
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pythonx/UltiSnips/vim_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit fb16fad

Please # to comment.