sjl / splice.vim

A Vim plugin for managing three-way merges.
MIT License
235 stars 21 forks source link

SpliceInit; bufferlib.py: Value must be greater than zero. #17

Open Profpatsch opened 11 years ago

Profpatsch commented 11 years ago

When using git mergetool and opening gvim, I get the following stacktrace:

Error detected while processing function splice#SpliceInit:
line    2:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/philip/.vim/bundle/splice.vim/autoload/splice.py", line 13, in <module>
    import splicelib.init as splice
  File "/home/philip/.vim/bundle/splice.vim/autoload/splicelib/init.py", line 2, in <module>
    import modes
  File "/home/philip/.vim/bundle/splice.vim/autoload/splicelib/modes.py", line 894, in <module>
    compare = CompareMode()
  File "/home/philip/.vim/bundle/splice.vim/autoload/splicelib/modes.py", line 512, in __init__
    self._current_buffer_first = buffers.original
  File "/home/philip/.vim/bundle/splice.vim/autoload/splicelib/util/bufferlib.py", line 37, in original
    return Buffer(0)
  File "/home/philip/.vim/bundle/splice.vim/autoload/splicelib/util/bufferlib.py", line 10, in __init__
    self._buffer = vim.buffers[i]
ValueError: number must be greater then zero
line    3:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'SpliceInit' is not defined

gvim 7.3.1287-1

Profpatsch commented 11 years ago

It looks like Bram is actively building at the python interface atm…

bufferlib.py:

class Buffer(object):
    def __init__(self, i):
        self.number = i + 1
        # In vim version 7/4/2013 buffers start from 1!!
        self._buffer = vim.buffers[i + 1]
        self.name = self._buffer.name

BRAM, WHY U DO DIS?!

I leave this here because I don’t know how to handle vim versions (I guess no system besides Arch and Gentoo are going to get this version in the near future).

dwijnand commented 11 years ago

Just been hit by this too :(

Profpatsch commented 11 years ago

Just make the change in the first comment and you should be fine.

@xoi, you found the same reason but you forgot to tell the basic truth behind it: The array is indexed from 1 instead of 0. ;)

sotte commented 11 years ago

Same here with vim 7.4a.39.

I guess one could check the vim version and change the self._buffer accordingly.

OT: I think the util functions (and some more) should be part of vanilla vim, so handy :)

WishCow commented 11 years ago

I made the change described in @Profpatsch's comment, but now I'm getting:

Error detected while processing function splice#SpliceInit:
line    3:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/w/.vim/bundle/splice/autoload/splice.py", line 19, in SpliceInit
    splice.init()
  File "/home/w/.vim/bundle/splice/autoload/splicelib/init.py", line 101, in init
    process_result()
  File "/home/w/.vim/bundle/splice/autoload/splicelib/init.py", line 13, in process_result
    buffers.result.open()
  File "/home/w/.vim/bundle/splice/autoload/splicelib/util/bufferlib.py", line 16, in open
    vim.command('%dbuffer' % self.number)
vim.error: Vim(buffer):E325: ATTENTION
jgelens commented 11 years ago

@Profpatsch change worked for me using the latest 7.4 stable release

Vimmer commented 11 years ago

This code was always wrong. have a look at

https://groups.google.com/forum/#!topic/vim_dev/HgKdV33Jy5I

It explains why and gives a correct implementation for all versions.

Profpatsch commented 11 years ago

Then it would be great if you could fix it and open a pull request.

Vimmer commented 11 years ago

This could be a possible solution without using internal vim structures. But maybe it would be better

to increase performance.

--- util.orig\bufferlib.py  2013-08-23 08:22:19.604507800 +0200
+++ util\bufferlib.py   2013-08-26 08:14:20.162800900 +0200
@@ -6,8 +6,13 @@

 class Buffer(object):
     def __init__(self, i):
-        self.number = i + 1
-        self._buffer = vim.buffers[i+1]
+        self.number = i
+
+        for b in vim.buffers:
+            if b.number == self.number:
+                self._buffer = b
+                break
+
         self.name = self._buffer.name

     def open(self, winnr=None):
@@ -34,23 +39,33 @@
 class _BufferList(object):
     @property
     def original(self):
-        return Buffer(0)
+        i = iter(vim.buffers)
+        return Buffer(next(i).number)

     @property
     def one(self):
-        return Buffer(1)
+        i = iter(vim.buffers)
+        next(i)
+        return Buffer(next(i).number)

     @property
     def two(self):
-        return Buffer(2)
+        i = iter(vim.buffers)
+        next(i)
+        next(i)
+        return Buffer(next(i).number)

     @property
     def result(self):
-        return Buffer(3)
+        i = iter(vim.buffers)
+        next(i)
+        next(i)
+        next(i)
+        return Buffer(next(i).number)

     @property
     def hud(self):
-        return Buffer(int(vim.eval("bufnr('__Splice_HUD__')")) - 1)
+        return Buffer(int(vim.eval("bufnr('__Splice_HUD__')")))

     @property