unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Richard Stallman <rms@gnu.org>
Cc: cyd@stupidchicken.com, emacs-devel@gnu.org
Subject: Re: sit-for and idle timers
Date: Mon, 14 Aug 2006 15:20:49 -0400	[thread overview]
Message-ID: <E1GChzV-0002nz-6d@fencepost.gnu.org> (raw)
In-Reply-To: <20060811124841.840381.FMU5696@piglet.prv.splode.com> (message from Noah Friedman on Fri, 11 Aug 2006 12:48:41 -0700 (PDT))

    The change to sit-for of 2006-07-26 ("Use new SECONDS arg of read-event
    instead of a timer") seems to cause problems with idle-timers
    which call sit-for.


Why do these timer functions call sit-for?  It is a strange thing for
a timer to wait.  It should reschedule itself instead.  What are they
really trying to do?

    > The problem is that read-event's call tree ultimately results in
    > calling keyboard.c:read_char, which calls timer_start_idle.  This
    > resets the activation time for all the current idle timer events,
    > which means that any function on an idle timer which calls sit-for
    > is now getting scheduled to be run recursively if another interval
    > of the appropriate length ensues.

    I think the solution is to avoid calling timer_start_idle when
    read-event is given a non-nil SECONDS argument.  What do people think?

That is definitely not right.  Emacs really is idle when it reads an event,
even if there is a timeout.

The way to find the right fix is to ask WHY the current behavior is
wrong.  Calling timer_start_idle is appropriate when Emacs changes
from non-idle to idle.  It is wrong to call that function when Emacs
is already idle.

So my conclusion is that when read-event is called from an idle timer,
it should not change the state to idle at the beginning, and it should
not change the state away from idle at the end.


Does this change fix it?


*** keyboard.c	12 Aug 2006 17:31:29 -0400	1.866
--- keyboard.c	14 Aug 2006 03:48:20 -0400	
***************
*** 2416,2421 ****
--- 2416,2424 ----
    volatile int reread;
    struct gcpro gcpro1, gcpro2;
    int polling_stopped_here = 0;
+   /* If we are already in the idle state, for instance if we
+      are calling from an idle timer, stay idle when we exit.  */
+   int already_idle = ! EMACS_TIME_NEG_P (timer_idleness_start_time);
  
    also_record = Qnil;
  
***************
*** 2679,2685 ****
        goto non_reread;
      }
  
!   timer_start_idle ();
  
    /* If in middle of key sequence and minibuffer not active,
       start echoing if enough time elapses.  */
--- 2682,2689 ----
        goto non_reread;
      }
  
!   if (! already_idle)
!     timer_start_idle ();
  
    /* If in middle of key sequence and minibuffer not active,
       start echoing if enough time elapses.  */
***************
*** 2749,2755 ****
        c = read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu);
  
        /* Now that we have read an event, Emacs is not idle.  */
!       timer_stop_idle ();
  
        goto exit;
      }
--- 2753,2760 ----
        c = read_char_x_menu_prompt (nmaps, maps, prev_event, used_mouse_menu);
  
        /* Now that we have read an event, Emacs is not idle.  */
!       if (!already_idle)
! 	timer_stop_idle ();
  
        goto exit;
      }
***************
*** 2931,2937 ****
  
   non_reread:
  
!   timer_stop_idle ();
    RESUME_POLLING;
  
    if (NILP (c))
--- 2936,2943 ----
  
   non_reread:
  
!   if (!already_idle)
!     timer_stop_idle ();
    RESUME_POLLING;
  
    if (NILP (c))
***************
*** 2970,2976 ****
  	   prevents automatic window selection (under
  	   mouse_autoselect_window from acting as a real input event, for
  	   example banishing the mouse under mouse-avoidance-mode.  */
! 	timer_resume_idle ();
  
        /* Resume allowing input from any kboard, if that was true before.  */
        if (!was_locked)
--- 2976,2983 ----
  	   prevents automatic window selection (under
  	   mouse_autoselect_window from acting as a real input event, for
  	   example banishing the mouse under mouse-avoidance-mode.  */
! 	if (!already_idle)
! 	  timer_resume_idle ();
  
        /* Resume allowing input from any kboard, if that was true before.  */
        if (!was_locked)
***************
*** 3170,3177 ****
  
        show_help_echo (help, window, object, position, 0);
  
!       /* We stopped being idle for this event; undo that.  */
!       timer_resume_idle ();
        goto retry;
      }
  
--- 3177,3185 ----
  
        show_help_echo (help, window, object, position, 0);
  
!       /* If we stopped being idle for this event, undo that.  */
!       if (!already_idle)
! 	timer_resume_idle ();
        goto retry;
      }

  parent reply	other threads:[~2006-08-14 19:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-11 19:48 sit-for and idle timers Noah Friedman
2006-08-11 21:00 ` Chong Yidong
2006-08-14 18:34 ` Chong Yidong
2006-08-14 19:20 ` Richard Stallman [this message]
2006-08-14 19:47   ` Chong Yidong
2006-08-14 20:05     ` Chong Yidong
2006-08-15 12:41       ` Richard Stallman
2006-08-15 20:12         ` Chong Yidong
2006-08-16 19:27           ` Richard Stallman
2006-08-16 19:38             ` Chong Yidong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1GChzV-0002nz-6d@fencepost.gnu.org \
    --to=rms@gnu.org \
    --cc=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).