From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "moheb missaghi" Newsgroups: gmane.emacs.devel Subject: Re: Popup when buffer file is changed on disk Date: Tue, 15 Feb 2005 19:59:42 -0700 Message-ID: <002901c513d3$90cfc590$6601a8c0@y8h26> References: <200502040036.j140atb03430@raven.dms.auburn.edu><009d01c50bbb$9aa2fd50$0200a8c0@sedrcw11488><000c01c50bc5$248dc1e0$6501a8c0@y8h26><01c50bd6$Blat.v2.4$48866000@zahav.net.il><001701c50be6$0eb9fa20$0200a8c0@sedrcw11488><01c50c1c$Blat.v2.4$88670e40@zahav.net.il><002801c50c2a$cbce93c0$0200a8c0@sedrcw11488><01c50c31$Blat.v2.4$d9a7a2a0@zahav.net.il><000301c50c38$6a152640$0200a8c0@sedrcw11488><200502061704.j16H4iG15131@raven.dms.auburn.edu><200502110033.j1B0XD907696@raven.dms.auburn.edu><200502130141.j1D1fr519696@raven.dms.auburn.edu><01c51185$Blat.v2.4$b97e1e60@zahav.net.il><200502150305.j1F351K06222@raven.dms.auburn.edu> <01c5131b$Blat.v2.4$36d1efe0@zahav.net.il> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1108523366 24038 80.91.229.2 (16 Feb 2005 03:09:26 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 16 Feb 2005 03:09:26 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Feb 16 04:09:25 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1D1FYt-00061R-Sv for ged-emacs-devel@m.gmane.org; Wed, 16 Feb 2005 04:09:12 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D1Fok-0003yg-UJ for ged-emacs-devel@m.gmane.org; Tue, 15 Feb 2005 22:25:35 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1D1FnI-0003RM-I7 for emacs-devel@gnu.org; Tue, 15 Feb 2005 22:24:05 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1D1FnG-0003QI-7m for emacs-devel@gnu.org; Tue, 15 Feb 2005 22:24:02 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D1FnF-0003Od-GS for emacs-devel@gnu.org; Tue, 15 Feb 2005 22:24:01 -0500 Original-Received: from [216.148.227.85] (helo=rwcrmhc12.comcast.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1D1FTp-0000pn-FN for emacs-devel@gnu.org; Tue, 15 Feb 2005 22:03:57 -0500 Original-Received: from y8h26 (pcp03531757pcs.sntafe01.nm.comcast.net[68.35.4.113]) by comcast.net (rwcrmhc12) with SMTP id <2005021602594501400g6edre>; Wed, 16 Feb 2005 02:59:45 +0000 Original-To: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org X-MailScanner-To: ged-emacs-devel@m.gmane.org Xref: main.gmane.org gmane.emacs.devel:33521 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:33521 Hi, I posted the following yesterday but I am not sure if it made it to the list. Sorry if it did post but noone chose to comment. Thanks for all the responses to my proposed patch. Autorevert doesn't quite do what Lennart and I want because it is not deterministic, i.e., depends on some frequency value to be set. Also it has to be turned on/off for each buffer unless you set it globally. Problem with global setting is that you might forget that buffers are automatically reverted unless some message or symbol appears on the modeline. Following Lennart's idea, I added a flag to the buffer struct (leaveBufferAlone) which persists the state of whether the user chose to ignore that the buffer file was changed on disk or not. When working with an IDE, the popup provides a symmetric editing experience in that emacs and the IDE notify the user whenever the file is changed on disk (by the other) and give him/her the chance to ignore or revert. In the case of emacs, this works fine with ask-user-about-supersession-threat, if user chooses not to revert. When he/she finally saves the buffer, the leaveBufferAlone flag is reset. It is also a bit more efficient than the current emacs functionality in that it involves one less key stroke. Currently, if the file is changed on disk you have to do an edit action in order to get to choose to revert or not via ask-user-about-supersession-threat (which is a bit annoying to my taste!) whereas with the popup, you'll get the message as soon as you switch to the buffer or as soon as the emacs frame gets the focus if the buffer is currently visited. The new code follows. Regards, Moheb cvs diff: Diffing nt Index: nt/nmake.defs =================================================================== RCS file: /cvsroot/emacs/emacs/nt/nmake.defs,v retrieving revision 1.20 diff -w -r1.20 nmake.defs 132a133,136 > > > USER_CFLAGS = -DUSING_WITH_IDE > cvs diff: Diffing src Index: src/buffer.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/buffer.c,v retrieving revision 1.473 diff -w -r1.473 buffer.c 55a56,59 > #if USING_WITH_IDE > #include "w32term.h" > #endif > 684a689,693 > > #if USING_WITH_IDE > b->leaveBufferAlone = 0; > #endif > 1662a1672,1676 > #if USING_WITH_IDE > Lisp_Object buf; > HWND hwnd = FRAME_W32_WINDOW (SELECTED_FRAME ()); > #endif > 1670a1685,1720 > #if USING_WITH_IDE > buf = switch_to_buffer_1 (buffer, norecord); > > // see if file is changed > if ((!NILP (current_buffer->filename) > && SAVE_MODIFF >= MODIFF > && NILP (Fverify_visited_file_modtime (Fcurrent_buffer ())) > && !NILP (Ffile_exists_p (current_buffer->filename))) && > current_buffer->leaveBufferAlone == 0) > { > int fileChangedDialogAnswer = MessageBox (NULL, "Buffer file changed > on disk, revert?", "Emacs", > MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL|MB_SETFOREGROUND); > char msg[80]; > > if (fileChangedDialogAnswer == IDYES) > { > /* reset the don't change flag */ > current_buffer->leaveBufferAlone = 0; > call3 (intern ("revert-buffer"), Qt, Qt, Qt); > strcpy(msg, "File reverted: "); > strcat(msg, XSTRING(current_buffer->filename)->data); > message (msg); > SetFocus(hwnd); > } > else > { > /* persist that the question was asked and the answer was no */ > current_buffer->leaveBufferAlone = 1; > strcpy(msg, "File changed on disk: "); > strcat(msg, XSTRING(current_buffer->filename)->data); > message (msg); > SetFocus(hwnd); > } > } > > return buf; > #else 1671a1722 > #endif Index: src/buffer.h =================================================================== RCS file: /cvsroot/emacs/emacs/src/buffer.h,v retrieving revision 1.100 diff -w -r1.100 buffer.h 510a511,515 > #if USING_WITH_IDE > /* for persistance when buffer file changes on disk */ > int leaveBufferAlone; > #endif > Index: src/fileio.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/fileio.c,v retrieving revision 1.526 diff -w -r1.526 fileio.c 5276a5277,5281 > #if USING_WITH_IDE > /* reset leaveBufferAlone flag */ > current_buffer->leaveBufferAlone = 0; > #endif > Index: src/w32fns.c =================================================================== RCS file: /cvsroot/emacs/emacs/src/w32fns.c,v retrieving revision 1.246 diff -w -r1.246 w32fns.c 3558a3559,3590 > #if USING_WITH_IDE > // see if file is changed > if ((!NILP (current_buffer->filename) > && SAVE_MODIFF >= MODIFF > && NILP (Fverify_visited_file_modtime (Fcurrent_buffer ())) > && !NILP (Ffile_exists_p (current_buffer->filename))) && > current_buffer->leaveBufferAlone == 0) > { > int fileChangedDialogAnswer = MessageBox (NULL, "Buffer file changed > on disk, revert?", "Emacs", > MB_YESNO|MB_ICONQUESTION|MB_APPLMODAL|MB_SETFOREGROUND); > char msg[80]; > > if (fileChangedDialogAnswer == IDYES) > { > /* reset the flag */ > current_buffer->leaveBufferAlone = 0; > call3 (intern ("revert-buffer"), Qt, Qt, Qt); > strcpy(msg, "File reverted: "); > strcat(msg, XSTRING(current_buffer->filename)->data); > message (msg); > SetFocus(hwnd); > } > else > { > /* don't let the dialog to be annoying */ > current_buffer->leaveBufferAlone = 1; > strcpy(msg, "File changed on disk: "); > strcat(msg, XSTRING(current_buffer->filename)->data); > message (msg); > SetFocus(hwnd); > } > } > #endif