To: vim-dev@vim.org Subject: Patch 6.0.096 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.0.096 Problem: When ":saveas fname" fails because the file already exists, the file name is changed anyway and a following ":w" will overwrite the file. (Eric Carlier) Solution: Don't change the file name if the file already exists. Files: src/ex_cmds.c *** ../vim60.95/src/ex_cmds.c Mon Nov 5 21:24:46 2001 --- src/ex_cmds.c Wed Dec 12 21:32:55 2001 *************** *** 2140,2191 **** } } ! if (eap->cmdidx == CMD_saveas && alt_buf != NULL) { #ifdef FEAT_AUTOCMD ! buf_T *was_curbuf = curbuf; ! apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); ! if (curbuf != was_curbuf) ! { ! /* buffer changed, don't change name now */ ! retval = FAIL; ! goto theend; ! } #endif ! /* Exchange the file names for the current and the alternate buffer. ! * This makes it look like we are now editing the buffer under the new ! * name. Must be done before buf_write(), because if there is no file ! * name and 'cpo' contains 'F', it will set the file name. */ ! fname = alt_buf->b_fname; ! alt_buf->b_fname = curbuf->b_fname; ! curbuf->b_fname = fname; ! fname = alt_buf->b_ffname; ! alt_buf->b_ffname = curbuf->b_ffname; ! curbuf->b_ffname = fname; ! fname = alt_buf->b_sfname; ! alt_buf->b_sfname = curbuf->b_sfname; ! curbuf->b_sfname = fname; ! buf_name_changed(); #ifdef FEAT_AUTOCMD ! apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); ! if (!alt_buf->b_p_bl) ! { ! alt_buf->b_p_bl = TRUE; ! apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, alt_buf); ! } ! if (curbuf != was_curbuf) ! { ! /* buffer changed, don't write the file */ ! retval = FAIL; ! goto theend; ! } #endif ! } - if (check_overwrite(eap, curbuf, fname, ffname, other) == OK) retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, eap, eap->append, eap->forceit, TRUE, FALSE); theend: #ifdef FEAT_BROWSE --- 2140,2194 ---- } } ! if (check_overwrite(eap, curbuf, fname, ffname, other) == OK) { + if (eap->cmdidx == CMD_saveas && alt_buf != NULL) + { #ifdef FEAT_AUTOCMD ! buf_T *was_curbuf = curbuf; ! apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); ! if (curbuf != was_curbuf) ! { ! /* buffer changed, don't change name now */ ! retval = FAIL; ! goto theend; ! } #endif ! /* Exchange the file names for the current and the alternate ! * buffer. This makes it look like we are now editing the buffer ! * under the new name. Must be done before buf_write(), because ! * if there is no file name and 'cpo' contains 'F', it will set ! * the file name. */ ! fname = alt_buf->b_fname; ! alt_buf->b_fname = curbuf->b_fname; ! curbuf->b_fname = fname; ! fname = alt_buf->b_ffname; ! alt_buf->b_ffname = curbuf->b_ffname; ! curbuf->b_ffname = fname; ! fname = alt_buf->b_sfname; ! alt_buf->b_sfname = curbuf->b_sfname; ! curbuf->b_sfname = fname; ! buf_name_changed(); #ifdef FEAT_AUTOCMD ! apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); ! if (!alt_buf->b_p_bl) ! { ! alt_buf->b_p_bl = TRUE; ! apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, alt_buf); ! } ! if (curbuf != was_curbuf) ! { ! /* buffer changed, don't write the file */ ! retval = FAIL; ! goto theend; ! } #endif ! } retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, eap, eap->append, eap->forceit, TRUE, FALSE); + } theend: #ifdef FEAT_BROWSE *** ../vim60.95/src/version.c Wed Dec 12 21:05:43 2001 --- src/version.c Wed Dec 12 21:37:50 2001 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 96, /**/ -- hundred-and-one symptoms of being an internet addict: 51. You put a pillow case over your laptop so your lover doesn't see it while you are pretending to catch your breath. /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim ))) \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///