all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* find-file-hook as illustration of Custom problems
@ 2005-02-04  0:36 Luc Teirlinck
  2005-02-04  7:16 ` Lennart Borgman
  2005-02-05 17:38 ` Richard Stallman
  0 siblings, 2 replies; 67+ messages in thread
From: Luc Teirlinck @ 2005-02-04  0:36 UTC (permalink / raw)


Programs adding entries to hooks or other lists or alists that are
defined by defcustoms can yield _all kinds_ of problems.

If you do `emacs -q' and then `M-x customize-rogue' you will see well
over twenty variables that are defined with defcustoms and are then
changed by code.  Just experimenting a little bit with these variables
in Custom buffers (_not_ in `emacs -q', because you want a regular
customized Emacs for this) will reveal a wide variety of buggish behavior.

I _only_ took a look at find-file-hook, because I wanted a really easy
example.  (Plenty of other variables, look like they might be a much
bigger mess.)

If you customize find-file-hook, then regret your customizations and
select "Erase Customization" VC will not work any more, for newly
visited files.  If you use auto-revert-tail-mode, it will malfunction
from that moment on, for newly visited files.  Both will work again if
you start a new session, but the fact that they cease to work without
warning in the current session is bad enough.

The problem is that vc-hooks.el contains:

(add-hook 'find-file-hook 'vc-find-file-hook)

and autorevert.el contains:

(add-hook 'find-file-hook
	    (lambda ()
	        (set (make-local-variable 'auto-revert-tail-pos)
		      (save-restriction (widen) (1- (point-max))))))

Since vc-hooks.el is apparently preloaded, one could either call
vc-find-file-hook directly from after-find-file or one could add it to
the defcustom of find-file-hook.  Since it seems to be a function that
needs to run _unconditionally_, I personally would lean toward calling
it from after-find-file directly.

What should be done with the auto-revert-tail-mode problem is not that
straightforward.  I would say just ignore it for the moment.  I just
noticed auto-revert-tail, because I use auto-revert-mode, but looking
through the code, I noticed that several other packages add stuff to
find-file-hook in the same way and hence will also be disabled by
"Erase Customization ".

I guess that after "21.4" is released, we could split some of the most
often used and most problematic hooks (like find-file-hook) into a
user and a program hook, thereby solving this kind of problem.  (Doing
this for all defcustomed hooks would probably be unrealistic, because
there are too many of them.)

After that more than twenty complete different and much more complex
problems with changing stuff outside Custom remain, if we just look at
problems present at startup.

But problems occurring _after_ startup are much more dangerous, as I
pointed out and they are also apparently even way more numerous.

I would say, let us tackle this seriously after 21.4 is released and
let us leave Custom alone until 21.4 is released.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 67+ messages in thread
* Re: Popup when buffer file is changed on disk
@ 2005-02-14 20:18 moheb1333
  2006-01-01 16:10 ` Richard M. Stallman
  0 siblings, 1 reply; 67+ messages in thread
From: moheb1333 @ 2005-02-14 20:18 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 5597 bytes --]

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   

[-- Attachment #1.2: Type: text/html, Size: 9216 bytes --]

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

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

^ permalink raw reply	[flat|nested] 67+ messages in thread

end of thread, other threads:[~2006-01-01 16:10 UTC | newest]

Thread overview: 67+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-04  0:36 find-file-hook as illustration of Custom problems Luc Teirlinck
2005-02-04  7:16 ` Lennart Borgman
2005-02-05 17:38 ` Richard Stallman
2005-02-05 18:54   ` Luc Teirlinck
2005-02-06 21:01     ` Richard Stallman
2005-02-06 22:19       ` Lennart Borgman
2005-02-05 19:43   ` Lennart Borgman
2005-02-05 20:56     ` Popup when buffer file is changed on disk moheb missaghi
2005-02-05 22:57       ` Eli Zaretskii
2005-02-06  0:51         ` Lennart Borgman
2005-02-06  7:20           ` Eli Zaretskii
2005-02-06  9:02             ` Lennart Borgman
2005-02-06  9:53               ` Eli Zaretskii
2005-02-06 10:41                 ` Lennart Borgman
2005-02-06 16:34                   ` Luc Teirlinck
2005-02-06 17:52                     ` Lennart Borgman
2005-02-06 17:04                   ` Luc Teirlinck
2005-02-11  0:33                     ` Luc Teirlinck
2005-02-11 15:40                       ` Eli Zaretskii
2005-02-11 16:51                         ` David Kastrup
2005-02-11 19:38                           ` Luc Teirlinck
2005-02-12 11:03                             ` Eli Zaretskii
2005-02-12  8:37                       ` Richard Stallman
2005-02-13  1:41                         ` Luc Teirlinck
2005-02-13  4:36                           ` Eli Zaretskii
2005-02-15  3:05                             ` Luc Teirlinck
2005-02-15  4:59                               ` Eli Zaretskii
2005-02-16  2:59                                 ` moheb missaghi
2005-02-16  9:31                               ` Richard Stallman
2005-02-16 10:37                                 ` David Kastrup
2005-02-16 15:06                                   ` Luc Teirlinck
2005-02-16 15:21                                     ` David Kastrup
2005-02-17  1:08                                       ` Luc Teirlinck
2005-02-06 12:42               ` Richard Stallman
2005-02-06 18:00                 ` Lennart Borgman
2005-02-06 18:17                   ` Jan D.
2005-02-06 19:59                     ` Lennart Borgman
2005-02-06 20:40                       ` Jan D.
2005-02-07  4:34                         ` Eli Zaretskii
2005-02-07  4:04                   ` Luc Teirlinck
2005-02-06 18:11                 ` Luc Teirlinck
2005-02-06 18:45                   ` Luc Teirlinck
2005-02-06 13:24               ` Jason Rumney
2005-02-06 13:54                 ` Lennart Borgman
2005-02-06  7:23         ` Eli Zaretskii
2005-02-06 21:01     ` find-file-hook as illustration of Custom problems Richard Stallman
2005-02-06  1:50   ` Luc Teirlinck
2005-02-06  3:26     ` Luc Teirlinck
2005-02-06  4:02       ` Luc Teirlinck
2005-02-06 21:02     ` Richard Stallman
2005-02-08  1:50       ` Luc Teirlinck
2005-02-09  8:10         ` Richard Stallman
2005-02-09 10:42           ` Kim F. Storm
2005-02-10 18:39             ` Richard Stallman
2005-02-10 21:42               ` Kim F. Storm
2005-02-12  8:37                 ` Richard Stallman
2005-02-10  5:12           ` Luc Teirlinck
2005-02-10 18:40             ` Richard Stallman
2005-02-11  0:09               ` Luc Teirlinck
2005-02-12  8:37                 ` Richard Stallman
2005-02-11  0:21               ` Luc Teirlinck
2005-02-11 14:59               ` Luc Teirlinck
2005-02-10  5:26           ` Luc Teirlinck
2005-02-06  2:07   ` Luc Teirlinck
2005-02-06  3:16     ` Luc Teirlinck
  -- strict thread matches above, loose matches on Subject: below --
2005-02-14 20:18 Popup when buffer file is changed on disk moheb1333
2006-01-01 16:10 ` Richard M. Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.