From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.help Subject: Re: Using widgets and timers simultaneously Date: Tue, 01 May 2007 14:14:59 +0200 Message-ID: <46372F43.4000006@gmx.at> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1178021642 7846 80.91.229.12 (1 May 2007 12:14:02 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 1 May 2007 12:14:02 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: pollock.nageoire@wanadoo.fr Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue May 01 14:14:00 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HirF1-0003KK-7R for geh-help-gnu-emacs@m.gmane.org; Tue, 01 May 2007 14:13:59 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HirLJ-0001Rd-0J for geh-help-gnu-emacs@m.gmane.org; Tue, 01 May 2007 08:20:29 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HirL6-0001RO-LU for help-gnu-emacs@gnu.org; Tue, 01 May 2007 08:20:16 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HirL5-0001RC-2n for help-gnu-emacs@gnu.org; Tue, 01 May 2007 08:20:16 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HirL5-0001R9-03 for help-gnu-emacs@gnu.org; Tue, 01 May 2007 08:20:15 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1HirEm-00034b-3V for help-gnu-emacs@gnu.org; Tue, 01 May 2007 08:13:44 -0400 Original-Received: (qmail invoked by alias); 01 May 2007 12:13:42 -0000 Original-Received: from M3075P026.adsl.highway.telekom.at (EHLO [88.117.32.90]) [88.117.32.90] by mail.gmx.net (mp034) with SMTP; 01 May 2007 14:13:42 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX1+jqClhzQOjwJ6eN7DjGdVmXEJJZGAlfd4L+YsBA9 SCofbmZZt3gjAm User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en X-Y-GMX-Trusted: 0 X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:43430 Archived-At: > (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.