Open Profpatsch opened 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).
Just been hit by this too :(
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. ;)
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 :)
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
@Profpatsch change worked for me using the latest 7.4 stable release
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.
Then it would be great if you could fix it and open a pull request.
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
When using
git mergetool
and openinggvim
, I get the following stacktrace:gvim 7.3.1287-1