Julien Danjou writes:
On Fri, Oct 22 2010, Stephen J. Turnbull wrote:
> What does current-idle-timer do?
It returns the time since when Emacs is idle, or nil if it's not idle.
Good thing I asked; I would have expected it to return the idle-timer
currently running (ie, the one that called the function). That's easy.
(defun current-idle-timer () ;; or is it `current-idle-time'?
"Return XEmacs's idle time in seconds as a float."
(itimer-time-difference (current-time) last-command-event-time))
This will never return nil, though. I guess if you really need to
know that XEmacs is idle
(defvar xemacs-is-idle-p nil)
(add-hook 'pre-idle-hook
(defun set-xemacs-is-idle-p () (setq xemacs-is-idle-p t)))
(add-hook 'pre-command-hook
(defun clear-xemacs-is-idle-p () (setq xemacs-is-idle-p nil)))
(defun emacs-like-current-idle-timer ()
(and xemacs-is-idle-p
(current-idle-timer)))
Of course there may be a race condition here depending on your
definition of "idle". However, it wouldn't matter for practical uses
(the race window is way less than a second, so if your interval is
more than a second, you won't execute anyway if you hit the window,
because last-command-event-time will be set and the current-idle-timer
function will return a sufficiently small number).
> > run-with-idle-timer is not usable because it only run once
by idle
> > session.
>
> ;; probably you want to wrap this up in a macro and use a gensym
> ;; instead of a global symbol
> (defvar timer-foo-timer nil)
> (defun timer-foo ()
> (do-foo)
> (when (itimerp timer-foo-timer) (delete-itimer itimer-foo-timer))
> (setq timer-foo-timer (run-with-idle-timer secs nil #'timer-foo)))
I don't think this will work.
Maybe not. I guess you'd probably need to use a regular timer anyway.
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-beta