all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Using widgets and timers simultaneously
@ 2007-04-30 20:21 Pierre Lorenzon
  0 siblings, 0 replies; 6+ messages in thread
From: Pierre Lorenzon @ 2007-04-30 20:21 UTC (permalink / raw)
  To: help-gnu-emacs

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

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

* Re: Using widgets and timers simultaneously
@ 2007-05-01 12:14 martin rudalics
  2007-05-01 13:30 ` Pierre Lorenzon
  0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2007-05-01 12:14 UTC (permalink / raw)
  To: pollock.nageoire; +Cc: help-gnu-emacs

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

It occurs to me that in `refresh' you set up `my-widget' in the buffer
that's current at that time, hence your widget might eventually appear
in all your buffers.

 > 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.

I recall that widgets may get screwed up when text is replaced at text
boundaries.  In principle you should make sure yourself that mutable
text is surrounded by immutable one.

 > 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.

Zero-length overlays are a mess but you could try something like the
following:

(defvar my-clock-overlay)
(defvar my-clock-timer)

(defun my-refresh ()
   (when (overlayp my-clock-overlay)
     (overlay-put my-clock-overlay 'after-string (current-time-string))))

(with-current-buffer (get-buffer-create "*Clock*")
   (setq my-clock-overlay (make-overlay (point) (point) nil t))
   (setq my-clock-timer (run-at-time nil 5 'my-refresh)))

Experiencing with code like this you soon will encounter similar
problems as the widget library - but at least you don't have to
examine the code of wid-edit.el to resolve them ;-).

 > 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.

I suppose point-marker is relocated when you re-create 'timed.  It
inherently deletes the entire line and creates it anew.  Any markers
within the deleted region move to the front of it.

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

* Re: Using widgets and timers simultaneously
  2007-05-01 12:14 Using widgets and timers simultaneously martin rudalics
@ 2007-05-01 13:30 ` Pierre Lorenzon
  2007-05-02  8:36   ` martin rudalics
  0 siblings, 1 reply; 6+ messages in thread
From: Pierre Lorenzon @ 2007-05-01 13:30 UTC (permalink / raw)
  To: rudalics; +Cc: help-gnu-emacs


Hi

From: martin rudalics <rudalics@gmx.at>
Subject: Re: Using widgets and timers simultaneously
Date: Tue, 01 May 2007 14:14:59 +0200

>  > (defun refresh ()
>  >   (let ((pos (point)))
>  >     (widget-delete my-widget)
>  >     (setq my-widget (widget-create 'timed))
>  >     (goto-char pos))
>  >   (widget-setup))
> 
> It occurs to me that in `refresh' you set up `my-widget' in the buffer
> that's current at that time, hence your widget might eventually appear
> in all your buffers.

  Indeed it is a bad "collateral" effect that might easily be
  improved but this not the heart of the problem !


> 
>  > 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.
> 
> I recall that widgets may get screwed up when text is replaced at text
> boundaries.  In principle you should make sure yourself that mutable
> text is surrounded by immutable one.

  I suppose the point is here but I don't really understand !
  Can you give me more details ? 

  Indeed I implemented the refresh method slightly differently
  :

  (defun refresh ()
  (widget-value-set my-widget (current-time-string)))

  It avoids the setq my-widget mentioned above and which was
  not really good as you observed. But since the
  widget-defaul-value-set still require the
  widget-default-create method the problem with the
  delete-backward-char which is not executed is still there !

Bests

Pierre

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

* Re: Using widgets and timers simultaneously
       [not found] <mailman.12.1177964905.32220.help-gnu-emacs@gnu.org>
@ 2007-05-01 16:26 ` Johan Bockgård
  0 siblings, 0 replies; 6+ messages in thread
From: Johan Bockgård @ 2007-05-01 16:26 UTC (permalink / raw)
  To: help-gnu-emacs


Have you looked at ewoc (Emacs' Widget for Object Collections)?

http://ursine.ca/cgi-bin/info2www?(emacs-snapshot/elisp)Abstract+Display

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

* Re: Using widgets and timers simultaneously
  2007-05-01 13:30 ` Pierre Lorenzon
@ 2007-05-02  8:36   ` martin rudalics
  2007-05-08 13:11     ` Pierre Lorenzon
  0 siblings, 1 reply; 6+ messages in thread
From: martin rudalics @ 2007-05-02  8:36 UTC (permalink / raw)
  To: Pierre Lorenzon; +Cc: help-gnu-emacs

 >>I recall that widgets may get screwed up when text is replaced at text
 >>boundaries.  In principle you should make sure yourself that mutable
 >>text is surrounded by immutable one.
 >
 >
 >   I suppose the point is here but I don't really understand !
 >   Can you give me more details ?
 >
 >   Indeed I implemented the refresh method slightly differently
 >   :
 >
 >   (defun refresh ()
 >   (widget-value-set my-widget (current-time-string)))
 >
 >   It avoids the setq my-widget mentioned above and which was
 >   not really good as you observed. But since the
 >   widget-defaul-value-set still require the
 >   widget-default-create method the problem with the
 >   delete-backward-char which is not executed is still there !

You would have to give me a precise recipe to reproduce the failure.
Note that debugging widgets is a real pain, that's why I usually try to
avoid it.  You could try to edebug `widget-default-value-set' (according
to Richard there's a bug) and see for yourself.  Be sure to cancel the
timer before and invoke `refresh' manually.  It might be worth to edebug
the `widget-field-...' functions as well.

Does the character of the problem change when you set
`widget-field-add-space' to a non-nil value?  Does setting
`widget-field-use-before-change' to nil affect the problem?

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

* Re: Using widgets and timers simultaneously
  2007-05-02  8:36   ` martin rudalics
@ 2007-05-08 13:11     ` Pierre Lorenzon
  0 siblings, 0 replies; 6+ messages in thread
From: Pierre Lorenzon @ 2007-05-08 13:11 UTC (permalink / raw)
  To: rudalics; +Cc: help-gnu-emacs

Hi Martin,

Anyone is always happy when he discover where the problem comes
from even if he do not know how to solve it ! Indeed my problem
was not a conflict between widgets and timers but I think a
conflict between the two things and the speech system I am
using on my emacs. Indeed I a blind and usinbg speechd-el and
certain functions are advised (anyway the system tries to
produce speech echo when displaying). When executing my code
without activating the speech support it seems that there is no
problem and that everything displays correctly.
(I can check it with a braille display).

So I have to investigate why there is a conflict between the
speech system and "the rest of the world" but anyway it
concerns pieces of code that I did not communicate to you ! 

So I thank you for your help even if I did not give you all
elements of the problem : I am very sorry for that ! but I did
not figure myself that the problem could come from ther ... 

Bests

Pierre

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

end of thread, other threads:[~2007-05-08 13:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-01 12:14 Using widgets and timers simultaneously martin rudalics
2007-05-01 13:30 ` Pierre Lorenzon
2007-05-02  8:36   ` martin rudalics
2007-05-08 13:11     ` Pierre Lorenzon
     [not found] <mailman.12.1177964905.32220.help-gnu-emacs@gnu.org>
2007-05-01 16:26 ` Johan Bockgård
  -- strict thread matches above, loose matches on Subject: below --
2007-04-30 20:21 Pierre Lorenzon

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.