To: vim-dev@vim.org Subject: Patch 7.0.044 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 7.0.044 Problem: Perl: setting a buffer line in another buffer may result in changing the current buffer. Solution: Properly change to the buffer to be changed. Files: src/if_perl.xs *** ../vim-7.0.043/src/if_perl.xs Tue Mar 7 00:18:16 2006 --- src/if_perl.xs Thu Jun 22 21:22:18 2006 *************** *** 1056,1062 **** int i; long lnum; char *line; - buf_T *savebuf; PPCODE: if (buf_valid(vimbuf)) { --- 1056,1061 ---- *************** *** 1069,1082 **** line = SvPV(ST(i),PL_na); if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL) { ! savebuf = curbuf; curbuf = vimbuf; if (u_savesub(lnum) == OK) { ml_replace(lnum, (char_u *)line, TRUE); changed_bytes(lnum, 0); } ! curbuf = savebuf; } } } --- 1068,1098 ---- line = SvPV(ST(i),PL_na); if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL) { ! #ifdef FEAT_AUTOCMD ! aco_save_T aco; ! ! /* set curwin/curbuf for "vimbuf" and save some things */ ! aucmd_prepbuf(&aco, vimbuf); ! #else ! buf_T *save_curbuf = curbuf; ! curbuf = vimbuf; + curwin->w_buffer = vimbuf; + #endif if (u_savesub(lnum) == OK) { ml_replace(lnum, (char_u *)line, TRUE); changed_bytes(lnum, 0); } ! ! #ifdef FEAT_AUTOCMD ! /* restore curwin/curbuf and a few other things */ ! aucmd_restbuf(&aco); ! /* Careful: autocommands may have made "vimbuf" invalid! */ ! #else ! curwin->w_buffer = save_curbuf; ! curbuf = save_curbuf; ! #endif } } } *************** *** 1087,1093 **** PREINIT: long i, lnum = 0, count = 0; - buf_T *savebuf; PPCODE: if (buf_valid(vimbuf)) { --- 1103,1108 ---- *************** *** 1114,1129 **** { if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count) { ! savebuf = curbuf; curbuf = vimbuf; if (u_savedel(lnum, 1) == OK) { ml_delete(lnum, 0); deleted_lines_mark(lnum, 1L); ! if (savebuf == curbuf) check_cursor(); } ! curbuf = savebuf; update_curbuf(VALID); } } --- 1129,1159 ---- { if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count) { ! buf_T *save_curbuf = curbuf; ! #ifdef FEAT_AUTOCMD ! aco_save_T aco; ! ! /* set curwin/curbuf for "vimbuf" and save some things */ ! aucmd_prepbuf(&aco, vimbuf); ! #else curbuf = vimbuf; + curwin->w_buffer = vimbuf; + #endif if (u_savedel(lnum, 1) == OK) { ml_delete(lnum, 0); deleted_lines_mark(lnum, 1L); ! if (save_curbuf == curbuf) check_cursor(); } ! #ifdef FEAT_AUTOCMD ! /* restore curwin/curbuf and a few other things */ ! aucmd_restbuf(&aco); ! /* Careful: autocommands may have made "vimbuf" invalid! */ ! #else ! curwin->w_buffer = save_curbuf; ! curbuf = save_curbuf; ! #endif update_curbuf(VALID); } } *************** *** 1138,1144 **** int i; long lnum; char *line; - buf_T *savebuf; PPCODE: if (buf_valid(vimbuf)) { --- 1168,1173 ---- *************** *** 1151,1164 **** line = SvPV(ST(i),PL_na); if (lnum >= 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL) { ! savebuf = curbuf; curbuf = vimbuf; if (u_inssub(lnum + 1) == OK) { ml_append(lnum, (char_u *)line, (colnr_T)0, FALSE); appended_lines_mark(lnum, 1L); } ! curbuf = savebuf; update_curbuf(VALID); } } --- 1180,1210 ---- line = SvPV(ST(i),PL_na); if (lnum >= 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL) { ! #ifdef FEAT_AUTOCMD ! aco_save_T aco; ! ! /* set curwin/curbuf for "vimbuf" and save some things */ ! aucmd_prepbuf(&aco, vimbuf); ! #else ! buf_T *save_curbuf = curbuf; ! curbuf = vimbuf; + curwin->w_buffer = vimbuf; + #endif if (u_inssub(lnum + 1) == OK) { ml_append(lnum, (char_u *)line, (colnr_T)0, FALSE); appended_lines_mark(lnum, 1L); } ! ! #ifdef FEAT_AUTOCMD ! /* restore curwin/curbuf and a few other things */ ! aucmd_restbuf(&aco); ! /* Careful: autocommands may have made "vimbuf" invalid! */ ! #else ! curwin->w_buffer = save_curbuf; ! curbuf = save_curbuf; ! #endif update_curbuf(VALID); } } *** ../vim-7.0.043/src/version.c Tue Aug 8 16:30:51 2006 --- src/version.c Tue Aug 8 16:45:40 2006 *************** *** 668,669 **** --- 668,671 ---- { /* Add new patch number below this line */ + /**/ + 44, /**/ -- Momento mori, ergo carpe diem /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///