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

Re: Re: Re: Re: Re: vim60 bug: deleting buffer lines using python can cause an error

Expand Messages
  • Gold is Heavy
    Bram, The patch below seems to fix everything. Many thanks! --Leo
    Message 1 of 9 , Sep 29, 2001
    • 0 Attachment
      Bram,

      The patch below seems to fix everything. Many thanks!

      --Leo

      > Note: this patch is against the original 6.0 if_python.c.
      >
      > *** ../vim60.8/src/if_python.c Fri Aug 24 21:30:54 2001
      > --- src/if_python.c Sat Sep 29 20:40:30 2001
      > ***************
      > *** 2116,2121 ****
      > --- 2116,2148 ----
      > return list;
      > }
      >
      > + /*
      > + * Check if deleting lines made the cursor position invalid.
      > + * Changed the lines from "lo" to "hi" and added "extra" lines (negative if > + * deleted).
      > + */
      > + static void
      > + py_fix_cursor(int lo, int hi, int extra)
      > + {
      > + if (curwin->w_cursor.lnum >= lo)
      > + {
      > + /* Adjust the cursor position if it's in/after the changed
      > + * lines. */
      > + if (curwin->w_cursor.lnum >= hi)
      > + {
      > + curwin->w_cursor.lnum += extra;
      > + check_cursor_col();
      > + }
      > + else if (extra < 0)
      > + {
      > + curwin->w_cursor.lnum = lo;
      > + check_cursor();
      > + }
      > + changed_cline_bef_curs();
      > + }
      > + invalidate_botline();
      > + }
      > +
      > /* Replace a line in the specified buffer. The line number is
      > * in Vim format (1-based). The replacement line is given as
      > * a Python string object. The object is checked for validity
      > ***************
      > *** 2145,2151 ****
      > --- 2172,2182 ----
      > else if (ml_delete((linenr_T)n, FALSE) == FAIL)
      > PyErr_SetVim(_("cannot delete line"));
      > else
      > + {
      > deleted_lines_mark((linenr_T)n, 1L);
      > + if (buf == curwin->w_buffer)
      > + py_fix_cursor(n, n + 1, -1);
      > + }
      >
      > curbuf = savebuf;
      >
      > ***************
      > *** 2234,2239 ****
      > --- 2265,2273 ----
      > }
      > }
      > deleted_lines_mark((linenr_T)lo, (long)i);
      > +
      > + if (buf == curwin->w_buffer)
      > + py_fix_cursor(lo, hi, -n);
      > }
      >
      > curbuf = savebuf;
      > ***************
      > *** 2353,2358 ****
      > --- 2387,2395 ----
      > mark_adjust((linenr_T)lo, (linenr_T)(hi - 1),
      > (long)MAXLNUM, (long)extra);
      > changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
      > +
      > + if (buf == curwin->w_buffer)
      > + py_fix_cursor(lo, hi, extra);
      >
      > curbuf = savebuf;
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.