5

This is cross-post from Stack Overflow

I have a simple widget setup:

(setq gobgen-widget-name
      (widget-create 'editable-field
                     :size 25
                     :format "Name:   %v"
                     :notify (lambda (widget &rest ignore)
                               (widget-value-set gobgen-widget-prefix (get-gobject-prefix (widget-value widget))))
                     "g_example_object"))

(widget-insert " ")

(setq gobgen-widget-prefix
      (widget-create 'editable-field
                     :size 10
                     :format "Prefix: %v\n"
                     "g"))

I’d like to update the second widget real time with the return value of get-gobject-prefix.

However, whenever I enter a character in the Name widget, point automatically jumps to the last character of the Prefix field, and inserts my character there.

Is there a way to do what I’m trying to achieve?

(I’m using Emacs 24.3.1)

2

It turns out that this was easier than I expected: using save-excursion saved the day (and my point position).

(lambda (widget &rest ignore)
  (save-excursion
    (widget-value-set gobgen-widget-prefix (get-gobject-prefix (widget-value widget)))))

Not totally perfect, though, as it changes the width of the Prefix widget.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.