6

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)

GergelyPolonkai
  • 748
  • 5
  • 12

1 Answers1

3

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.

GergelyPolonkai
  • 748
  • 5
  • 12