GNU TeXmacsUser manualReferenceAboutEnglish
Interactive dialogues

The routines on this page allow Scheme programs to ask simple questions to the user and to display messages. They are defined in

kernel/texmacs/tm-dialogue.scm

and

kernel/gui/menu-widget.scm

. Since the graphical user interface is event driven, the answers are passed to continuations rather than returned. More complex dialogues can be built using widgets, as explained in dialogs and composite widgets.

(user-ask prompt cont)
(ask a question)

Prompt the user with the string prompt (in the footer or in a dialogue window, depending on the preferences) and call cont with the answer (a string). Instead of a string, prompt may also be a list (prompt type proposal …), where type is as in the :argument option of tm-define (see function definitions) and the proposals are the suggested answers.

(user-confirm prompt default cont)
(ask for confirmation)

Ask a yes/no question and call cont with a boolean. The boolean default determines whether "yes" or "no" is proposed first. For instance:

(user-confirm "Really close the document?" #f
  (lambda (answ) (when answ (buffer-close (current-buffer)))))
(user-url prompt type cont)
(ask for a file name)

Open a file chooser with title prompt and call cont with the chosen URL. The type can for instance be "texmacs", "image" or "directory"; see choose-file in

kernel/boot/abbrevs.scm

.

(interactive fun)

(interactive fun arg-1 … arg-n)
(call a function interactively)

Prompt the user for the arguments of the function fun and then call it. In the first form, the prompts, types and default values of the arguments are taken from the :argument, :default and :proposals options of the definition of fun. In the second form, each arg-i is a prompt string or a list (prompt type proposal …). Answers are learned, so that they can be proposed again next time (see also learn-interactive and forget-interactive). This is the usual way to bind commands which require arguments in menus, as in (interactive load-buffer).

(set-message left right)

(set-temporary-message left right ms)
(messages in the footer)

Display the message left in the footer, together with the information right (which usually describes the action that caused the message). The temporary variant restores the previous message after ms milliseconds of inactivity. The messages may be strings or TeXmacs content.

(show-message msg title)

(notify-now msg)
(message windows)

Show the message msg in a small window with an Ok button. The routine notify-now uses the title Notification and opens the window after the current event has been processed.

(dialogue-window widget cmd title)
(dialogue windows)

Open a new window with the widget widget (defined using tm-widget) and the given title. When the widget calls its continuation with some arguments, then cmd is applied to these arguments and the window is closed. See dialogs and composite widgets for details and examples.

Many dialogues need to be executed after the current event has been processed or after some delay. This can be done using the following macro.

(delayed option … body …)
(delayed execution)

Schedule the evaluation of body after the current event has been processed. The following options modify when and how often body is evaluated:

(:idle ms)

Wait until the user has been inactive during ms milliseconds.

(:pause ms)

Wait ms milliseconds.

(:every ms)

Evaluate body every ms milliseconds (usually combined with :while or :permanent).

(:on-cpu-idle ms)

Wait at least ms milliseconds, and then until the computer has been idle during 30 seconds; with :permanent, this is used for periodic maintenance, such as the backups of the server.

(:refresh ms)

Evaluate body once the user has been inactive during ms milliseconds. With :permanent after it, body is evaluated again after each later change of the document, once the user has been inactive again during ms milliseconds; without a change, nothing happens.

(:require cond)

Postpone the evaluation until cond holds.

(:while cond)

Repeat the evaluation as long as cond holds.

(:permanent cond)

Reschedule the evaluation after each execution as long as cond evaluates to #t.

(:clean expr)

Evaluate expr once the task has finished.

(:do expr)

Evaluate expr each time the task is checked.

For instance, (delayed (:idle 1000) (set-message "Hi" "")) displays a message after one second of inactivity. The macro is defined in

kernel/texmacs/tm-dialogue.scm

. Notice that :idle does not work in headless mode.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".