help-gnu-emacs
[Top][All Lists]
Advanced

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

Using widgets and timers simultaneously


From: Pierre Lorenzon
Subject: Using widgets and timers simultaneously
Date: Mon, 30 Apr 2007 22:21:13 +0200 (CEST)

Hi all,

I.d like to use widgets and timers in conjunction. What I'd
like to be able to do is to set up a timer which will refresh a
certain widget periodically. Here is the code I wrote but
certainly I'd like to do more sophisticated tasks than simply
displaying the time !

--- Code ---

(defvar my-widget nil)
(defvar my-timer)

(define-widget
  'timed
  'string
  ""
  :value-to-internal
  (lambda (widget value) (current-time-string)))


(defun refresh ()
  (let ((pos (point)))
    (widget-delete my-widget)
    (setq my-widget (widget-create 'timed))
    (goto-char pos))
  (widget-setup))

(switch-to-buffer (get-buffer-create "*Clock*"))
(setq my-widget (widget-create 'timed))
(use-local-map widget-keymap)
(widget-setup)
(setq my-timer (run-at-time nil 5 'refresh))

--- End Code ---

Indeed it works i.e. time is redisplayed every 5 seconds. But
when I try to move the cursor in the buffer the behavior might
become some how erratic ! In fact especially after using up and
down arrow keys, the widget is no longer well displayed. The
formating characters appear "%{" "%[" or things like that just
as if the delete-backward-char method in the creating method
would not have any effect. 

Can somebody explain me why ; and give me an indication to solve
this question ? You certainly might say that widgets are not
adapted to display parts of a buffer that must be periodically
refreshed and that I should use something like overlays. Sure
but it would be much more convenient for me if I could use
widgets and moreover widgets displaying is  more or less based
on overlays.

Notice that if I replace the (let ((pos ...)) form in the
refresh method by a save-excursion the cursor always goes at
the beginning of the buffer as if all marks were killed by the
widget displayin mechanism. 

Bests

Pierre





reply via email to

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