To: diffusor@ugcs.caltech.edu Cc: vim-dev list Subject: patch 5.4n.19 (was: vim 5.4n pl0: :edit in options window causes problems) In-Reply-To: From: Bram Moolenaar Date: Thu, 08 Jul 1999 15:23:55 +0200 Sender: mool@masaka.moolenaar.net Steve Mueller wrote: > Try this: > > start vim > :options > :e > i > > "Unknown function: OW_Space" is the error I receive. Related file: > $VIMRUNTIME/optwin.vim. The mappings for space and seem to be > maintained in both normal and insert from the setup of the option window: Something goes very wrong here. The BufLeave autocommands are not executed, since ":e" isn't supposed to leave the buffer. But then the BufUnload autocommand deletes the buffer. That can be fixed by removing the mappings on a BufUnload too, if the mappings still exist. > Also, if you happen to have another buffer in the buffer list that's > hidden and has a swapfile, vim does this: (from vim-5.4m) > > 1 buffer deleted > ATTENTION > Found a swap file by the name "~/.vimrc.swp" Oh, oh, another buffer-unexpectedly-deleted-by-autocommand problem. These autocommands really have a lot of side effects. But it can be fixed: Patch 5.4n.19 Problem: Doing ":e" (without argument) in an option-window causes trouble. The mappings for and are not removed. When there is another buffer loaded, the swap file for it gets mixed up. (Steve Mueller) Solution: Also remove the mappings at the BufUnload event, if they are still present. When re-editing the same file causes the current buffer to be deleted, don't try editing it. Also added a test for this situation. Files: runtime/optwin.vim, src/ex_cmds.c, src/testdir/test13.in, src/testdir/test13.ok *** ../vim-5.4n/runtime/optwin.vim Sun Jul 4 20:36:36 1999 --- runtime/optwin.vim Thu Jul 8 12:59:01 1999 *************** *** 1,7 **** " These commands create the option window. " " Maintainer: Bram Moolenaar ! " Last change: 1999 Jun 24 " Make sure the '<' flag is not included in 'cpoptions', otherwise would " not be recognized. See ":help 'cpoptions'". --- 1,7 ---- " These commands create the option window. " " Maintainer: Bram Moolenaar ! " Last change: 1999 Jul 08 " Make sure the '<' flag is not included in 'cpoptions', otherwise would " not be recognized. See ":help 'cpoptions'". *************** *** 828,835 **** au! au BufEnter option-window call OW_enter() au BufLeave option-window call OW_leave() ! au BufUnload,BufHidden option-window nested call OW_unload() ! \ | delfun OW_unload augroup END fun! OW_enter() --- 828,835 ---- au! au BufEnter option-window call OW_enter() au BufLeave option-window call OW_leave() ! au BufUnload,BufHidden option-window nested call OW_unload() | ! \ delfun OW_unload augroup END fun! OW_enter() *************** *** 845,854 **** fun! OW_leave() let cpo_save = &cpo let &cpo = "" ! unmap ! iunmap ! unmap ! iunmap let &cpo = cpo_save endfun --- 845,856 ---- fun! OW_leave() let cpo_save = &cpo let &cpo = "" ! if mapcheck("") != "" ! unmap ! iunmap ! unmap ! iunmap ! endif let &cpo = cpo_save endfun *************** *** 864,869 **** --- 866,872 ---- delfun OW_Header au! optwin bdel option-window + call OW_leave() delfun OW_enter delfun OW_leave endfun *** ../vim-5.4n/src/ex_cmds.c Sun Jul 4 20:35:50 1999 --- src/ex_cmds.c Thu Jul 8 13:21:11 1999 *************** *** 2224,2229 **** --- 2224,2230 ---- BUF *buf; #if defined(AUTOCMD) || defined(GUI_DIALOG) || defined(CON_DIALOG) BUF *old_curbuf = curbuf; + char_u *new_name = NULL; #endif char_u *free_fname = NULL; #ifdef USE_BROWSE *************** *** 2367,2374 **** if (buf != curbuf) { #ifdef AUTOCMD - char_u *new_name = NULL; - /* * Be careful: The autocommands may delete any buffer and change * the current buffer. --- 2368,2373 ---- *************** *** 2438,2451 **** oldbuf = (flags & ECMD_OLDBUF); } - /* Assume success now */ - retval = OK; - - /* - * If we get here we are sure to start editing - */ - /* don't redraw until the cursor is in the right line */ - ++RedrawingDisabled; if (flags & ECMD_SET_HELP) { curbuf->b_help = TRUE; --- 2437,2442 ---- *************** *** 2464,2474 **** --- 2455,2497 ---- set_last_cursor(curwin); /* may set b_last_cursor */ if (newlnum == ECMD_LAST || newlnum == ECMD_LASTL) newlnum = curwin->w_cursor.lnum; + #ifdef AUTOCMD + buf = curbuf; + if (buf->b_fname != NULL) + new_name = vim_strsave(buf->b_fname); + else + new_name = NULL; + #endif buf_freeall(curbuf, FALSE); /* free all things for buffer */ + #ifdef AUTOCMD + /* If autocommands deleted the buffer we were going to re-edit, give + * up and jump to the end. */ + if (!buf_valid(buf)) + { + delbuf_msg(new_name); /* frees new_name */ + goto theend; + } + vim_free(new_name); + + /* If autocommands change buffers under our fingers, forget about + * re-editing the file. Should do the buf_clear(), but perhaps the + * autocommands changed the buffer... */ + if (buf != curbuf) + goto theend; + #endif buf_clear(curbuf); curbuf->b_op_start.lnum = 0; /* clear '[ and '] marks */ curbuf->b_op_end.lnum = 0; } + + /* + * If we get here we are sure to start editing + */ + /* don't redraw until the cursor is in the right line */ + ++RedrawingDisabled; + + /* Assume success now */ + retval = OK; /* * Reset cursor position, could be used by autocommands. *** ../vim-5.4n/src/testdir/test13.in Sun Jul 4 20:35:24 1999 --- src/testdir/test13.in Thu Jul 8 13:32:29 1999 *************** *** 31,37 **** --- 31,41 ---- :bdel Xtestje2 Xtestje3 test.out :au! :au! BufUnload Xtestje1 bdel + :e Xtestje3 + :w >>test.out :e Xtestje2 + :sp Xtestje1 + :e :w >>test.out :!rm -rf Xtestje* :qa! *** ../vim-5.4n/src/testdir/test13.ok Sun Jul 4 20:35:25 1999 --- src/testdir/test13.ok Thu Jul 8 13:32:45 1999 *************** *** 11,16 **** --- 11,22 ---- contents end of testfile start of testfile + testje3 + contents + contents + contents + end of testfile + start of testfile testje2 contents contents -- CART DRIVER: Bring out your dead! There are legs stick out of windows and doors. Two MEN are fighting in the mud - covered from head to foot in it. Another MAN is on his hands in knees shovelling mud into his mouth. We just catch sight of a MAN falling into a well. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD --/-/---- Bram Moolenaar ---- Bram@moolenaar.net ---- Bram@vim.org ---\-\-- \ \ www.vim.org/iccf www.moolenaar.net www.vim.org / / .