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

Re: missing setbufline()?

Expand Messages
  • Yegappan Lakshmanan
    Hi Bram, ... The setbufline() implementation is similar to the one used in if_perl.xs (Set) , if_python.c (SetBufferLine), if_ruby.c (set_buffer_line)
    Message 1 of 4 , Oct 23, 2006
      Hi Bram,

      On 10/23/06, Bram Moolenaar <Bram@...> wrote:
      >
      > Yegappan Lakshmanan wrote:
      >
      > > On 10/22/06, Hari Krishna Dara <hari_vim@...> wrote:
      > > > > On 10/22/06, Hari Krishna Dara <hari_vim@...> wrote:
      > > > > >
      > > > > > I see functions for creating new unlisted buffers (bufnr() with {create}
      > > > > > option), and for reading the lines from the buffer using getbufline(),
      > > > > > all without having to change the current buffer, but I don't see a
      > > > > > setbufline() so there is no way to set the lines without having to
      > > > > > switch to it. Is there a reason to leave this circle incomplete?
      > > > > >
      > > > >
      > > > > Yes. I had a patch for the setbufline() function last year. There were
      > > > > several problems with it. So it was not included in Vim7 and only
      > > > > the getbufline() function was included.
      > > > >
      > > > > The setbufline() function worked only for loaded buffers. The undo
      > > > > history was not updated correctly.
      > > > >
      > > > > But I agree that it will be good to have the setbufline() function.
      > > > >
      > > > > - Yegappan
      > > >
      > > > Nice, so it will be included at some point after resolving these issues.
      > > >
      > >
      > > You can try the attached patch against the latest Vim7 sources.
      > > The syntax of the new function is:
      > >
      > > setbufline({expr}, {lnum}, {line})
      > >
      > > where, {expr} specifies the loaded buffer name/number, {lnum} specifies
      > > a valid line number in that buffer and {line} is either a single line
      > > or a List of lines.
      > >
      > > Note. The patch also includes the new gettabvar() and settabvar()
      > > functions.
      >
      > It looks like after this patch, if you change lines in another buffer
      > some marks in the current window will be moved. Especially the
      > jumplist, perhaps setting cmdmod.lockmarks would help. The '< and '>
      > marks are probably moved. Manual folds might be moved. There may also
      > be redrawing problems.
      >

      The setbufline() implementation is similar to the one used in
      if_perl.xs (Set) , if_python.c (SetBufferLine), if_ruby.c (set_buffer_line)
      if_mzsch.c (set_buffer_line_list) and if_tcl.c (BUF_SET) interface
      files. These problems should also be seen with those
      interfaces also.

      >
      > This needs a test in src/testdir. And documentation, of course.
      >

      Will add the doc updates.

      >
      > I'm very careful with including something like this. Currently there is
      > no code that changes another buffer. It could break more than you
      > expect.
      >

      You can't change the buffer contents with the Perl/Python/Tcl/Ruby
      interfaces?

      - Yegappan
    • Yegappan Lakshmanan
      Hi Bram, ... I tried to reproduce this problem using the new setbufline() function. The jumplist for the current buffer is not affected while changing the
      Message 2 of 4 , Oct 23, 2006
        Hi Bram,

        On 10/23/06, Bram Moolenaar <Bram@...> wrote:
        >
        > >
        > > You can try the attached patch against the latest Vim7 sources.
        > > The syntax of the new function is:
        > >
        > > setbufline({expr}, {lnum}, {line})
        > >
        > > where, {expr} specifies the loaded buffer name/number, {lnum} specifies
        > > a valid line number in that buffer and {line} is either a single line
        > > or a List of lines.
        > >
        > > Note. The patch also includes the new gettabvar() and settabvar()
        > > functions.
        >
        > It looks like after this patch, if you change lines in another buffer
        > some marks in the current window will be moved. Especially the
        > jumplist, perhaps setting cmdmod.lockmarks would help.
        >

        I tried to reproduce this problem using the new setbufline()
        function. The jumplist for the current buffer is not affected
        while changing the contents of another loaded buffer using
        the setbufline() function. Is there any specific sequence that
        needs to be followed to see this problem?

        >
        > The '< and '> marks are probably moved. Manual folds might be moved.
        >

        I couldn't reproduce the above problems also. The manual folds
        and the visual area marks for the current buffer are not changed
        by setbufline().

        >
        > There may also be redrawing problems.
        >

        I didn't see any redraw problems. Are you referring to redraw
        problems in the current buffer or in the buffer that is being
        changed using setbufline()?

        - Yegappan

        >
        > This needs a test in src/testdir. And documentation, of course.
        >
        > I'm very careful with including something like this. Currently there is
        > no code that changes another buffer. It could break more than you
        > expect.
        >
      • Bram Moolenaar
        ... There also have been bugs in this implementation. I don t know if there are any others, it does not appear to be used much. ... OK, so you can. But this
        Message 3 of 4 , Oct 23, 2006
          Yegappan Lakshmanan wrote:

          > > > On 10/22/06, Hari Krishna Dara <hari_vim@...> wrote:
          > > > > > On 10/22/06, Hari Krishna Dara <hari_vim@...> wrote:
          > > > > > >
          > > > > > > I see functions for creating new unlisted buffers (bufnr() with {create}
          > > > > > > option), and for reading the lines from the buffer using getbufline(),
          > > > > > > all without having to change the current buffer, but I don't see a
          > > > > > > setbufline() so there is no way to set the lines without having to
          > > > > > > switch to it. Is there a reason to leave this circle incomplete?
          > > > > > >
          > > > > >
          > > > > > Yes. I had a patch for the setbufline() function last year. There were
          > > > > > several problems with it. So it was not included in Vim7 and only
          > > > > > the getbufline() function was included.
          > > > > >
          > > > > > The setbufline() function worked only for loaded buffers. The undo
          > > > > > history was not updated correctly.
          > > > > >
          > > > > > But I agree that it will be good to have the setbufline() function.
          > > > > >
          > > > > > - Yegappan
          > > > >
          > > > > Nice, so it will be included at some point after resolving these issues.
          > > > >
          > > >
          > > > You can try the attached patch against the latest Vim7 sources.
          > > > The syntax of the new function is:
          > > >
          > > > setbufline({expr}, {lnum}, {line})
          > > >
          > > > where, {expr} specifies the loaded buffer name/number, {lnum} specifies
          > > > a valid line number in that buffer and {line} is either a single line
          > > > or a List of lines.
          > > >
          > > > Note. The patch also includes the new gettabvar() and settabvar()
          > > > functions.
          > >
          > > It looks like after this patch, if you change lines in another buffer
          > > some marks in the current window will be moved. Especially the
          > > jumplist, perhaps setting cmdmod.lockmarks would help. The '< and '>
          > > marks are probably moved. Manual folds might be moved. There may also
          > > be redrawing problems.
          > >
          >
          > The setbufline() implementation is similar to the one used in
          > if_perl.xs (Set) , if_python.c (SetBufferLine), if_ruby.c (set_buffer_line)
          > if_mzsch.c (set_buffer_line_list) and if_tcl.c (BUF_SET) interface
          > files. These problems should also be seen with those
          > interfaces also.

          There also have been bugs in this implementation. I don't know if there
          are any others, it does not appear to be used much.

          > > This needs a test in src/testdir. And documentation, of course.
          >
          > Will add the doc updates.
          >
          > > I'm very careful with including something like this. Currently there is
          > > no code that changes another buffer. It could break more than you
          > > expect.
          >
          > You can't change the buffer contents with the Perl/Python/Tcl/Ruby
          > interfaces?

          OK, so you can. But this doesn't mean it actually works properly,
          without any undesired side effects. This code is only included
          optionally. For the main Vim code I'm more careful.

          --
          From "know your smileys":
          C=}>;*{)) Drunk, devilish chef with a toupee in an updraft,
          a mustache, and a double chin

          /// Bram Moolenaar -- Bram@... -- 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 ///
        • Bram Moolenaar
          ... The thing is that changes are made to another buffer while using the current window. This may change information in the current window that is wrong for
          Message 4 of 4 , Oct 24, 2006
            Yegappan Lakshmanan wrote:

            > On 10/23/06, Bram Moolenaar <Bram@...> wrote:
            > >
            > > >
            > > > You can try the attached patch against the latest Vim7 sources.
            > > > The syntax of the new function is:
            > > >
            > > > setbufline({expr}, {lnum}, {line})
            > > >
            > > > where, {expr} specifies the loaded buffer name/number, {lnum} specifies
            > > > a valid line number in that buffer and {line} is either a single line
            > > > or a List of lines.
            > > >
            > > > Note. The patch also includes the new gettabvar() and settabvar()
            > > > functions.
            > >
            > > It looks like after this patch, if you change lines in another buffer
            > > some marks in the current window will be moved. Especially the
            > > jumplist, perhaps setting cmdmod.lockmarks would help.
            > >
            >
            > I tried to reproduce this problem using the new setbufline()
            > function. The jumplist for the current buffer is not affected
            > while changing the contents of another loaded buffer using
            > the setbufline() function. Is there any specific sequence that
            > needs to be followed to see this problem?
            >
            > >
            > > The '< and '> marks are probably moved. Manual folds might be moved.
            > >
            >
            > I couldn't reproduce the above problems also. The manual folds
            > and the visual area marks for the current buffer are not changed
            > by setbufline().
            >
            > >
            > > There may also be redrawing problems.
            > >
            >
            > I didn't see any redraw problems. Are you referring to redraw
            > problems in the current buffer or in the buffer that is being
            > changed using setbufline()?

            The thing is that changes are made to another buffer while using the
            current window. This may change information in the current window that
            is wrong for when the buffer originally edited in it has been put
            back.

            I can't predict what exactly would go wrong or how to trigger that. The
            functions that are invoked are appended_lines_mark() and
            changed_bytes(). You probably need to try with the current buffer
            having more lines than the buffer being changed.

            --
            Common sense is what tells you that the world is flat.

            /// Bram Moolenaar -- Bram@... -- 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 ///
          Your message has been successfully submitted and would be delivered to recipients shortly.