Asking for help with a simple form

Hello all,
I have a simple form with one input field. Upon pressing Enter, I would like the form to execute a TeXmacs command with the current entry and close the form. This can be done using mouse, but I just want to use the keyboard.
So, for example, upon pressing Enter/Return, I would like to execute (insert (tree 'cite (car (form-values)) and close the form.
Thanks in advance for any suggestions.
Kind regards,
Murali

Hi @murali, I have the vague memory that it is not possible to close a form automatically once you have used it.
I found a 2021 thread where I wasn’t able to close a widget, here is a post where I write it:

Perhaps either @jeroen or @mgubi could be able to tell you more. On the other hand, you might post your complete code and I or someone else might try to get the form to close.

It seems strange to me that one cannot close a form programmatically. Maybe give a look at some of the existing forms or widgets and try to replicate it. Every form has a button like “Apply” or “Ok” which should close it right away. For example this:

(tm-widget (form1 cmd)
  (form "Test"
    (centered
      (aligned
        (item (text "First:")
          (form-input "First" "string" '("gnu") "1w"))
        (item (text "Second:")
          (form-input "Second" "string" '("gnat") "1w"))))
    (bottom-buttons
      ("Cancel" (cmd "Cancel")) >>
      ("Ok"
       (display* (form-fields) " -> " (form-values) "\n")
       (cmd "Ok")))))

taken from $TEXMACS_PATH/progs/kernel/menu-test.scm. You see that the form take a parameter cmd which is a closure which has to be called at the end with some result, like (cmd "Ok"). I guess that this closure also closes the form, but I cannot test now. I would start from this and check also the showand show-form functions at the end of the file for some more inspiration.

I’ve looked up the definition of dialogue-window, it looks as follows:


(tm-define (dialogue-window menu-promise cmd name . opts)
  (:interactive #t)
  (with (bufs qqq) (decode-options opts)
    (let* ((win (alt-window-handle))
           (del (make-window-deleter win bufs))
           (qui (object->command (lambda () (qqq) (del))))
           (lbd (lambda x (apply cmd x) (del)))
           (men (menu-promise lbd))
           (scm (list 'vertical men))
           (wid (make-menu-widget* scm 0)))
      (alt-window-create-quit win wid (translate name) qui)
      (alt-window-show win))))

so you see that as soon as you call the callback it will close the window via a call to (del).