all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: pollock.nageoire@wanadoo.fr
Cc: help-gnu-emacs@gnu.org
Subject: Re: Using widgets and timers simultaneously
Date: Tue, 01 May 2007 14:14:59 +0200	[thread overview]
Message-ID: <46372F43.4000006@gmx.at> (raw)

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

             reply	other threads:[~2007-05-01 12:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-01 12:14 martin rudalics [this message]
2007-05-01 13:30 ` Using widgets and timers simultaneously 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

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

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

  git send-email \
    --in-reply-to=46372F43.4000006@gmx.at \
    --to=rudalics@gmx.at \
    --cc=help-gnu-emacs@gnu.org \
    --cc=pollock.nageoire@wanadoo.fr \
    /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 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.