From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: moheb1333@comcast.net Newsgroups: gmane.emacs.devel Subject: Re: Popup when buffer file is changed on disk Date: Mon, 14 Feb 2005 20:18:43 +0000 Message-ID: <021420052018.19405.421107A30005F04700004BCD2200762302CCCCCCCE0D0A080103@comcast.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1365025973==" X-Trace: sea.gmane.org 1108412316 14721 80.91.229.2 (14 Feb 2005 20:18:36 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 14 Feb 2005 20:18:36 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 14 21:18:35 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1D0mfc-0007c6-Dd for ged-emacs-devel@m.gmane.org; Mon, 14 Feb 2005 21:18:13 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D0mvC-0003Z6-Fx for ged-emacs-devel@m.gmane.org; Mon, 14 Feb 2005 15:34:18 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1D0muh-0003Xi-Ev for emacs-devel@gnu.org; Mon, 14 Feb 2005 15:33:47 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1D0mue-0003VP-Pt for emacs-devel@gnu.org; Mon, 14 Feb 2005 15:33:45 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D0mud-0003UX-Vk for emacs-devel@gnu.org; Mon, 14 Feb 2005 15:33:44 -0500 Original-Received: from [204.127.202.59] (helo=sccrmhc11.comcast.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1D0mgE-0008As-SX for emacs-devel@gnu.org; Mon, 14 Feb 2005 15:18:52 -0500 Original-Received: from 204.127.205.145 ([204.127.205.145]) by comcast.net (sccrmhc14) with SMTP id <2005021420184301400o874re>; Mon, 14 Feb 2005 20:18:43 +0000 Original-Received: from [164.64.187.191] by 204.127.205.145; Mon, 14 Feb 2005 20:18:43 +0000 Original-To: emacs-devel@gnu.org X-Mailer: AT&T Message Center Version 1 (Dec 17 2004) X-Authenticated-Sender: bW9oZWIxMzMzQGNvbWNhc3QubmV0 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:33420 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:33420 --===============1365025973== Content-Type: multipart/alternative; boundary="NextPart_Webmail_9m3u9jl4l_19405_1108412323_0" --NextPart_Webmail_9m3u9jl4l_19405_1108412323_0 Content-Type: text/plain Content-Transfer-Encoding: 8bit Hi, 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 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 whereas with the popup, you'll get the message by switching to the buffer or when the emacs frame gets the focus if the buffer is currently visited. 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 --NextPart_Webmail_9m3u9jl4l_19405_1108412323_0 Content-Type: text/html Content-Transfer-Encoding: 8bit
Hi,
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 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 whereas with the pop up, you'll get the
message by switching to the buffer or when the emacs frame gets the focus if
the buffer is currently visited.
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)
>  &nbs p;    && 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 cha nge 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-& gt;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
& gt;           && 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 (fileChang edDialogAnswer == 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);
>  &nb sp;      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   
--NextPart_Webmail_9m3u9jl4l_19405_1108412323_0-- --===============1365025973== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --===============1365025973==--