Loading ...
Sorry, an error occurred while loading the content.
 

[patch] Python 3: Add support for assigning to slices on RangeObject

Expand Messages
  • Brett Overesch
    Hello, I ve been working with Python 3 scripts a lot lately and noticed that the range objects in the vim modules (e.g. vim.current.range) do not support
    Message 1 of 4 , Sep 2, 2011
      Hello,

      I've been working with Python 3 scripts a lot lately and noticed that the range objects in the vim modules (e.g. vim.current.range) do not support assignment via slices. The Python 2.x interface does support this, and it works on the buffer object in the Python 3 interface. For example:

      vim.current.range[2:10] = ["some new text"]
      or
      vim.current.range[5:5] = ["adding a new line at position 5"]

      This should work, but instead you get an error stating: "Index must be int or slice", which of course it is. I created a patch to add this, trying my best to conform to the existing code structure. Not sure if this has been covered already; I looked back a few days and searched, and didn't see anything related. Well, I found a post from someone stating the problem, but no patches. Anyway, just thought some fellow vim users might find it useful when working with the Python 3 interface. Have a nice day!

      -Brett Overesch

      --
      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
    • Roland Puntaier
      ... Before your patch this did work for :py but not for :py3. I ve found that ... had one entry too much compared to ... I made a little correction for that.
      Message 2 of 4 , Sep 6, 2011

        On 09/03/2011 07:26 AM, Brett Overesch wrote: Hello,

        I've been working with Python 3 scripts a lot lately and noticed that the range objects in the vim modules (e.g. vim.current.range) do not support assignment via slices. The Python 2.x interface does support this, and it works on the buffer object in the Python 3 interface. For example:

        vim.current.range[2:10] = ["some new text"]
        or
        vim.current.range[5:5] = ["adding a new line at position 5"]

        This should work, but instead you get an error stating: "Index must be int or slice", which of course it is. I created a patch to add this, trying my best to conform to the existing code structure. Not sure if this has been covered already; I looked back a few days and searched, and didn't see anything related. Well, I found a post from someone stating the problem, but no patches. Anyway, just thought some fellow vim users might find it useful when working with the Python 3 interface. Have a nice day!

        -Brett Overesch
        --
        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

        I've applied your patch and tested it on a line like:

        :py3 vim.current.buffer.range(1,3)[0:2]=['line1','line2']

        Before your patch this did work for :py but not for :py3.

        I've found that

        :py3 print(vim.current.buffer.range(1,3)[0:2])

        had one entry too much compared to

        :py print(vim.current.buffer.range(1,3)[0:2])

        I made a little correction for that. The following patch is your patch plus this one line correction.

        -Roland


        --
        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
      • Roland Puntaier
        Hello Bram, will you include this patch? Regards, Roland ... Subject: Re: [patch] Python 3: Add support for assigning to slices on RangeObject Date: Wed, 07
        Message 3 of 4 , Sep 9, 2011
          Hello Bram,

          will you include this patch?

          Regards, Roland

          -------- Original Message --------
          Subject:Re: [patch] Python 3: Add support for assigning to slices on RangeObject
          Date:Wed, 07 Sep 2011 01:08:22 +0200
          From:Roland Puntaier <roland.puntaier@...>
          Reply-To:vim_dev@...
          To:vim_dev@...
          CC:Brett Overesch <oversearch@...>



          On 09/03/2011 07:26 AM, Brett Overesch wrote: Hello,

          I've been working with Python 3 scripts a lot lately and noticed that the range objects in the vim modules (e.g. vim.current.range) do not support assignment via slices. The Python 2.x interface does support this, and it works on the buffer object in the Python 3 interface. For example:

          vim.current.range[2:10] = ["some new text"]
          or
          vim.current.range[5:5] = ["adding a new line at position 5"]

          This should work, but instead you get an error stating: "Index must be int or slice", which of course it is. I created a patch to add this, trying my best to conform to the existing code structure. Not sure if this has been covered already; I looked back a few days and searched, and didn't see anything related. Well, I found a post from someone stating the problem, but no patches. Anyway, just thought some fellow vim users might find it useful when working with the Python 3 interface. Have a nice day!

          -Brett Overesch
          --
          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

          I've applied your patch and tested it on a line like:

          :py3 vim.current.buffer.range(1,3)[0:2]=['line1','line2']

          Before your patch this did work for :py but not for :py3.

          I've found that

          :py3 print(vim.current.buffer.range(1,3)[0:2])

          had one entry too much compared to

          :py print(vim.current.buffer.range(1,3)[0:2])

          I made a little correction for that. The following patch is your patch plus this one line correction.

          -Roland


          --
          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

          --
          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
        • Bram Moolenaar
          ... It s in the todo list. -- I used to be indecisive, now I m not sure. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net ///
          Message 4 of 4 , Sep 12, 2011
            Roland Puntaier wrote:

            > Hello Bram,
            >
            > will you include this patch?

            It's in the todo list.

            --
            I used to be indecisive, now I'm not sure.

            /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
            /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
            \\\ an exciting new programming language -- http://www.Zimbu.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
          Your message has been successfully submitted and would be delivered to recipients shortly.