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



_______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel

Reply via email to