0

Looking up information from an Active Directory, I want to populate a form. Generally that works fine with editable-fields, since all one has to do is to add the value, which Emacs has a function for ((widget-value-set)). However, for one element I will need to use a drop-down field to only choose one of potentially more options, but I appear to fail to understand how to add items to a menu-choice widget.

My constant helper for building forms is the Emacs widget library. However, even the programming example under 3 is not revealing this as the example simply hard-coded them.

My current mock-up for testing this outside the actual environment looks like the following:

(let ((sBuffer "*Test*") (lItems (list '(item :tag "Test 1" :value 1) '(item :tag "Test 2" :value 2)))) (switch-to-buffer sBuffer) (make-local-variable 'wADgroup) (let ((inhibit-read-only t)) (erase-buffer)) (remove-overlays) (setq wButton (widget-create 'push-button :notify (lambda (widget &rest ignore) (widget-put wADgroup :children lItems) ;;(widget-value-set wADgroup 1) (widget-setup)) "Click me!")) (widget-insert "\n\n") (setq wADgroup (widget-create 'menu-choice :tag "- AD group " :value 1 :notify (lambda (widget &rest ignore)))) (use-local-map widget-keymap) (widget-setup)) 

Pressing the button in the above shall add the items.

Is there a way to dynamically add items to an existing menu-choice widget in hindsight or does it need to be deleted and re-created? I tried to add a list for :children, but that did not seem to have an effect and I am not sure how to add "loose" arguments when using widget-create (for any ordinary list I would use (append), of course). Even if the widget would need to be re-created, I still fail to understand how to programmatically add the items.

I'm using Emacs 28.

1 Answer 1

2

I’m pretty sure that the :children of a widget are the visible children of the widget. The choice widget only displays currently selected widget, so modifying :children is not what you want. Modify the :args list instead.

Don’t forget that you can use widget-browse-at to open a debug window that shows you all the properties of the widget under the point.

1
  • 1
    Awesome! That did it. And thanks for the additional command. That makes troubleshooting widgets tremendously easier in the future. Thank you very much! Commented May 1, 2023 at 1:05

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.