speechd-discuss
[Top][All Lists]
Advanced

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

Possible conflict between speechd.el and following code


From: Pierre Lorenzon
Subject: Possible conflict between speechd.el and following code
Date: Tue, 08 May 2007 16:20:16 +0200 (CEST)

Hi, 

Following is not my goal itself ! But I'd like to have a buffer
where a timer can modify a certain widget periodically. When
using this code in conjunction with speechd.el things do not
display correctly. Precisely, the widget refresh mechanism uses
temporary insertion of sequences of characters like "%v" or
"%{" etc... Instead of beeing removed after widget has been
displayed, they remain in the buffer ! just as if the
`delete-backward-char' in the code just bellow were not
executed. 

The error does not occur azlways but only when up or down key
has been pressed. 

When speechd library is not loaded the error does not occur
that's why I suspect there could be a conflict between my code
and the speechd library. 

But when the libray is loaded and speechd-speak-mode is turn
off, the error still occurs ... 

Here is the code :

--- Code ---

(require 'wid-edit)

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

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


(defun widget-my-create (widget)
  "Create WIDGET at point in the current buffer."
  (widget-specify-insert
   (let ((from (point))
         button-begin button-end
         sample-begin sample-end
         doc-begin doc-end
         value-pos)
     (insert (widget-get widget :format))
     (goto-char from)
     ;; Parse escapes in format.
     (while (re-search-forward "%\\(.\\)" nil t)
       (let ((escape (char-after (match-beginning 1))))
         (delete-backward-char 2)
         (cond ((eq escape ?%)
                (insert ?%))
               ((eq escape ?\[)
                (setq button-begin (point))
                (insert (widget-get-indirect widget :button-prefix)))
               ((eq escape ?\])
                (insert (widget-get-indirect widget :button-suffix))
                (setq button-end (point)))
               ((eq escape ?\{)
                (setq sample-begin (point)))
               ((eq escape ?\})
                (setq sample-end (point)))
               ((eq escape ?n)
                (when (widget-get widget :indent)
                  (insert ?\n)
                  (insert-char ?  (widget-get widget :indent))))
               ((eq escape ?t)
                (let ((image (widget-get widget :tag-glyph))
                      (tag (widget-get widget :tag)))
                  (cond (image
                         (widget-image-insert widget (or tag "image") image))
                        (tag
                         (insert tag))
                        (t
                         (princ (widget-get widget :value)
                                (current-buffer))))))
               ((eq escape ?d)
                (let ((doc (widget-get widget :doc)))
                  (when doc
                    (setq doc-begin (point))
                    (insert doc)
                    (while (eq (preceding-char) ?\n)
                      (delete-backward-char 1))
                    (insert ?\n)
                    (setq doc-end (point)))))
               ((eq escape ?v)
                (if (and button-begin (not button-end))
                    (widget-apply widget :value-create)
                  (setq value-pos (point))))
               (t
                (widget-apply widget :format-handler escape)))))
     ;; Specify button, sample, and doc, and insert value.
     (and button-begin button-end
          (widget-specify-button widget button-begin button-end))
     (and sample-begin sample-end
          (widget-specify-sample widget sample-begin sample-end))
     (and doc-begin doc-end
          (widget-specify-doc widget doc-begin doc-end))
     (when value-pos
       (goto-char value-pos)
       (widget-apply widget :value-create)))
   (let ((from (point-min-marker))
         (to (point-max-marker)))
     (set-marker-insertion-type from t)
     (set-marker-insertion-type to nil)
     (widget-put widget :from from)
     (widget-put widget :to to)))
  (widget-clear-undo))

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

(let ((widget-field-use-before-change nil))
  (switch-to-buffer (get-buffer-create "*Clock*"))
  (widget-insert "\t| --------- |\n")
  (setq my-widget (widget-create 'timed))
  (widget-insert "\t| --------- |\n")
  (use-local-map widget-keymap)
  (widget-setup)
  (setq my-timer (run-at-time nil 5 'refresh)))

--- End code ---

Sorry if I did correctly identify the error and if does not
have anything to do with speechd.-el.

Bests

Pierre



reply via email to

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