To: vim-dev@vim.org Subject: Patch 6.1.125 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.125 Problem: Explorer plugin asks for saving a modified buffer even when it's open in another window as well. Solution: Count the number of windows using the buffer. Files: runtime/plugin/explorer.vim *** ../vim61.124/runtime/plugin/explorer.vim Sat Feb 16 11:50:58 2002 --- runtime/plugin/explorer.vim Wed Jun 12 22:05:16 2002 *************** *** 1,7 **** "============================================================================= " File: explorer.vim " Author: M A Aziz Ahmed (aziz@acorn-networks.com) ! " Last Change: 2002 Feb 16 " Version: 2.5 + changes " Additions by Mark Waggoner (waggoner@aracnet.com) et al. "----------------------------------------------------------------------------- --- 1,7 ---- "============================================================================= " File: explorer.vim " Author: M A Aziz Ahmed (aziz@acorn-networks.com) ! " Last Change: 2002 Jun 12 " Version: 2.5 + changes " Additions by Mark Waggoner (waggoner@aracnet.com) et al. "----------------------------------------------------------------------------- *************** *** 332,337 **** --- 332,356 ---- endfunction "--- + " Determine the number of windows open to this buffer number. + " Care of Yegappan Lakshman. Thanks! + fun! s:BufInWindows(bnum) + let cnt = 0 + let winnum = 1 + while 1 + let bufnum = winbufnr(winnum) + if bufnum < 0 + break + endif + if bufnum == a:bnum + let cnt = cnt + 1 + endif + let winnum = winnum + 1 + endwhile + + return cnt + endfunction + " If this is the only window, open file in a new window " Otherwise, open file in the most recently visited window " *************** *** 344,371 **** call s:OpenEntry() " Other windows exist else ! " Check if the previous buffer is modified - ask if they want to ! " save! ! let bufname = bufname(winbufnr(winnr())) ! if &modified let action=confirm("Save Changes in " . bufname . "?","&Yes\n&No\n&Cancel") " Yes - try to save - if there is an error, cancel if action == 1 ! let v:errmsg = "" ! silent w ! if v:errmsg != "" ! echoerr "Unable to write buffer!" ! wincmd p ! return ! endif " No, abandon changes elseif action == 2 ! set nomodified ! echomsg "Warning, abandoning changes in " . bufname " Cancel (or any other result), don't do the open else ! wincmd p ! return endif endif wincmd p --- 363,391 ---- call s:OpenEntry() " Other windows exist else ! " Check if the previous buffer is modified - ask if they want to save! ! " Was it modified, and is it the only window open to this file ! if &modified && s:BufInWindows(winbufnr(winnr())) < 2 ! let bufname = bufname(winbufnr(winnr())) ! let action=confirm("Save Changes in " . bufname . "?","&Yes\n&No\n&Cancel") " Yes - try to save - if there is an error, cancel if action == 1 ! let v:errmsg = "" ! silent w ! if v:errmsg != "" ! echoerr "Unable to write buffer!" ! wincmd p ! return ! endif " No, abandon changes elseif action == 2 ! set nomodified ! echomsg "Warning, abandoning changes in " . bufname " Cancel (or any other result), don't do the open else ! wincmd p ! return endif endif wincmd p *** ../vim61.124/src/version.c Thu Jul 4 21:59:55 2002 --- src/version.c Sat Jul 6 19:30:38 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 125, /**/ -- BEDEVERE: How do you know so much about swallows? ARTHUR: Well you have to know these things when you're a king, you know. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\ \\\ Project leader for A-A-P -- http://www.a-a-p.org /// \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///