[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: idledo.el v. 0.3

From: Kim F. Storm
Subject: Re: idledo.el v. 0.3
Date: 25 Oct 2002 11:11:59 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Richard Stallman <address@hidden> writes:

>     IMO, the clean enhancement to timer.el would be to allow REPEAT to be
>     a number for run-with-idle-timer as well.
>     This requires C-level changes, e.g. using the first element of the
> I think this feature can be implemented at the Lisp level, in
> timer.el.

If we want this to be supported directly in the idle-timers (not
having to setup an idle-timer or a pre-command-hook), it requires C
level changes!

But I agree that it can [and should] be done in lisp [in a way similar
to what blink-cursor-mode currently does].

So I suggest the following to changes to timer.el:

Change run-with-idle-timer so that:

  If REPEAT is non-nil, do the action each time Emacs has been idle
  for exactly SECS seconds.
  If REPEAT is a number, keep repeating the action every REPEAT
  seconds as long as emacs remains idle; otherwise, only do the action
  once for each time Emacs becomes idle.

[Implementation: use a list of normal timers (one for each repeating
 idle hook) similar to blink-cursor-mode, and a pre-command hook which
 clears that list when emacs is no longer idle].

Add a new function:

  (timer-idle-timer-first-invocation-p TIMER)

which allows an idle-timer action to check whether this is the first
invocation of the timer after emacs becoming idle, or a repeated

[Implementation: just look at the first element of the timer vector]

Add a new hooks:


where users of idle-timers may setup functions to be called when emacs
is no longer idle.  Functions may be added/removed to this hook once
(e.g. when blink-cursor-mode is turned on or off), or it could be
added by the idle-timer action (in which case the hook function would be
responsible for removing the function from the hook when called).

Note: Globally added functions on that hook are called independently
of whether the "corresponding" idle-timer was activated or not (there
is really no way to associate the function with a specific timer;
however, they can use the timer-idle-timer-first-invocation-p function
to check whether a specific timer has been activated)

[Implementation: Run from the above mentioned pre-command hook.]

Note: The pre-command hook is only setup when the first idle-timer is
activated, so if no idle-timers have been activated, the
timer-no-longer-idle-hook isn't run either!  

[This may seem a little strange, but from a practical point of view, I
think it actually makes good sense, as the intended purpose of the
no-longer-idle hook is to be able to clean-up things which were
initiated by an idle-timer action.  So if no idle-timers were run,
there's no reason to run the hook either].

As an example, blink-cursor-mode could then be implemented by just three

(defun blink-cursor-mode (arg)
   ... e.g. to turn it on ...:
    (setq blink-cursor-idle-timer
            blink-cursor-interval  ;; OBS: New functionality!!!
    (add-hook 'timer-no-longer-idle-hook 'blink-cursor-stop))

(defun blink-cursor-blink ()
  "Toggle blinking cursor."
  (internal-show-cursor nil (not (internal-show-cursor-p))))

(defun blink-cursor-stop ()
  "Stop cursor blinking."
  (internal-show-cursor nil t))

Kim F. Storm <address@hidden> http://www.cua.dk

reply via email to

[Prev in Thread] Current Thread [Next in Thread]