Nico Raffo wrote: > On Jul 24, 8:02=A0am, Bram Moolenaar <[email protected]> wrote: > > Nico Raffo wrote: > > > Due to a syntax change between python 2 and python 3, there is no way > > > to insert a new line at an arbitrary line number into a buffer using > > > the python interface without using undocumented parameters in the > > > buffer.append() method. > > > > > In the existing python 2 interface, the way to insert a line according > > > to the documentation is: > > > > > :py b[n:n] =3D ["a new line at line number n"] > > > > > In python 3 you are no longer allowed to assign to a slice, so this > > > doesn't work anymore. > > > > > There is an undocumented second parameter to buffer.append() which > > > allows you to add a line number where the new line should be added. > > > However this diverges from the standard set of python list methods. If > > > the vim module wants to emulate a python list, it should have > > > buffer.insert(n, "new line at n"). Otherwise the extra param in > > > append() should be documented. > > > > > I'll throw in a patch for the new buffer.insert() method if people > > > think it's a good idea. > > > > Why not document the extra argument to append()? > > > > =A0 =A0 =A0 =A0 :py vim.current.buffer.append(["foobar"], 239) > > > > Seems to work as expected. > > > > Either option (add documentation for append() or implementing the > standard list method .insert()) seems fine to me. It would be nice if > the buffer object supported more of the python list methods, but that > can wait for another Vim version. > > However, looking at the code this morning I realized the issue is not > in fact a syntax difference between python 2 and 3. Python 3 does > support > > some_list[i:j] =3D replacement_list > > but for some reason the piece of if_python.c that handles this syntax > for the vim module wasn't ported to python 3. This is also causing > this syntax (from :h python) to fail: > > :py del b[n:m] # deletes a number of lines
Hmm, I should have been more careful when including the python3 patch. Apparently there is a lot of code duplicated between the two files, but the patch was based on a slightly older version of if_python.c -- Why don't cannibals eat clowns? Because they taste funny. /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ download, build and distribute -- http://www.A-A-P.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org /// -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php
