GNU TeXmacsUser manualReferenceAboutEnglish·Deutsch·Italiano
Summary of the configuration options for plug-ins

1.The plugin-configure macro

As explained before, the Scheme configuration file myplugin/progs/init-myplugin.scm of a plug-in with name myplugin should contain an instruction of the type

(plugin-configure myplugin
  configuration-options)

The macro plugin-configure is defined in

kernel/texmacs/tm-plugins.scm

. Each option is a list whose first element is a keyword; the options are processed in order by plugin-configure-cmd. After each option, the processing stops as soon as the plug-in is known to be unsupported (that is, as soon as the entry of the plug-in in the internal plugin-data-table is false). In practice this means that options which follow a failing :require are ignored, whereas options which precede it (such as :winpath) are always executed.

The list of options is quasi-quoted. The five options :require, :versions, :preferences, :setup and :initialize are special: their argument is automatically wrapped into a lambda by plugin-configure-sub, so that it is evaluated at the moment the option is processed (or not at all). For all other options the arguments are taken literally, so computed values and Scheme functions have to be inserted with an explicit unquote, as in (:launch ,(python-launcher)) or (:serializer ,python-serialize). It is also possible to splice a computed list of options, as the maxima plug-in does with ,@(maxima-launchers).

2.The plug-in cache

Several options interact with the plug-in cache, which is stored in $TEXMACS_HOME_PATH/system/cache/plugin_cache.scm. When the cache is valid, the global flag reconfigure-flag? is false and the (potentially expensive) tests of :require, :versions and :setup are not evaluated: their cached results are used instead. The cache is rebuilt (and reconfigure-flag? set to true) when it does not exist yet, when the PATH changed, when one of the directories of the PATH has been modified since the last run, or when the user explicitly asks for it using Tools\(\rightarrow\)Update\(\rightarrow\)Plugins or Insert\(\rightarrow\)Session\(\rightarrow\)Redetect (both call reinit-plugin-cache). See the section on internals for more details.

3.Available options

Here follows the complete list of the options which are recognized by plugin-configure-cmd. Any other option triggers the message warning: unsupported tm-configure option on the standard output, and is otherwise ignored.

3.1.Detection and set-up

(:require condition)
(sanity check)

This option specifies a sanity condition which needs to be satisfied by the plug-in. Usually, it is checked that certain binaries or libraries are present on your system, for instance using (url-exists-in-path? "maxima"). If the condition evaluates to #f, then TeXmacs will continue as whether your plug-in did not exist: the remaining options are ignored and (supports-myplugin?) returns #f. The condition is only evaluated when the plug-in cache is rebuilt; otherwise the cached result is used. If an alternative launcher is installed for the plug-in (see :launch below), then the condition is not evaluated and the plug-in is considered to be supported.

(:versions version-cmd)
(detect available versions)

This option is similar to :require, but version-cmd should evaluate to a list of available versions of the helper application (or #f if there is none). The result is stored in the cache and can be retrieved later using (plugin-versions "myplugin"), which always returns a list. Like :require, the expression is only evaluated when the cache is rebuilt. The maxima plug-in uses this in order to define one launcher for each installed version of Maxima.

(:setup cmd)
(one-time set-up)

The command cmd is only executed when the plug-in cache is being rebuilt, that is, at the first run, after a change of the PATH or of one of its directories, or after Tools\(\rightarrow\)Update\(\rightarrow\)Plugins. It can be used for set-up work whose result remains valid as long as the environment does not change.

(:initialize cmd)
(initialization code)

The command cmd is executed each time the configuration is processed (provided that the plug-in is supported). In most plug-ins, the same effect is obtained by putting code inside a (when (supports-myplugin?) …) block after the plugin-configure instruction.

(:prioritary expr)
(initialize early)

The unevaluated expression expr is stored in the plug-in cache. It is evaluated by lazy-plugin-initialize: when it is true, the initialization file of the plug-in is loaded immediately at startup instead of after one second of idle time. No plug-in of the distribution currently uses this option. Notice that lazy-plugin-initialize is called before the plug-in cache is loaded from disk, so that the option does not seem to have an effect in the current implementation.

(:preferences condition)
(the plug-in has preferences)

If condition evaluates to a true value, then the plug-in is listed by (plugins-with-preferences), and hence in the dialogue opened by Insert\(\rightarrow\)Session\(\rightarrow\)Preferences. The actual contents of the preferences widget are provided by overloading the widget plugin-preferences-widget for the plug-in, as in the python plug-in:

(tm-widget (plugin-preferences-widget name)
  (:require (== name "python"))
  (aligned
    (meti (hlist // (text "Run via Jupyter"))
      (toggle (run-via-jupyter "python" answer)
              (run-via-jupyter? "python")))))

(:winpath package-path inner-bin-path)

(:macpath package-path inner-bin-path)
(search helper binaries)

Specify where to search for the helper application under Windows (:winpath) resp. macOS (:macpath); the option has no effect on other systems. The package-path is the usual installation directory of the application, relative to a list of standard roots, and may contain wildcards. The inner-bin-path is the place where to look for the binary, relative to the package-path. All existing directories which match are appended to the PATH. Under Windows, the roots are C:\., C:\Program File*, $HOME\AppData\Local and $HOME\AppData\Local\Programs; under macOS they are /Applications and $HOME/Applications. For instance, the pari plug-in uses (:macpath "Pari*" "Contents/Resources/bin").

The same functionality is also available as the ordinary functions (plugin-add-windows-path rad rel after?) and (plugin-add-macos-path rad rel after?), which may be called before plugin-configure and which allow to prepend (after? false) instead of append the directories.

3.2.Connection types

The following options declare how TeXmacs communicates with the helper application. Each of them may take an optional first argument variant, a string which names a variant of the plug-in (for instance a version number); the default variant is called "default". When a plug-in has several variants, the Insert\(\rightarrow\)Session menu displays a submenu with all variants.

(:launch shell-cmd)

(:launch variant shell-cmd)
(communication through pipes)

This option specifies that the plug-in is able to evaluate expressions over a pipe, using a helper application which is launched using the shell command shell-cmd. The command is executed using /bin/sh -c on Unix systems. The protocol used on the pipe is described in the chapter about writing interfaces. If an alternative launcher is installed for the plug-in, that is, if the overloadable function (alt-launcher name) returns a command instead of #f, then this command replaces shell-cmd. The jupyter plug-in uses this mechanism in order to run other plug-ins through a Jupyter kernel.

(:link lib-name export-symbol options)

(:link variant lib-name export-symbol options)
(dynamic linking)

This option is similar to :launch, except that the extern application is now linked dynamically as a shared library. The library lib-name is searched in $LD_LIBRARY_PATH, the symbol export-symbol should be a structure of type package_exports_1 and the string options is passed to its installation routine. For more information, see the section about dynamic linking. Dynamic linking is only available when TeXmacs has been compiled with TM_DYNAMIC_LINKING and never under Windows.

(:cmdline ,cmd-fun ,result-fun)
(one process per evaluation)

With this connection type, a new shell command is launched for each evaluation. For each input string in, TeXmacs calls (cmd-fun name session in), which should return the shell command to be executed (newlines in the input are replaced by spaces and 2> /dev/null is appended to the command). When the process terminates, its complete standard output res is passed to (result-fun name session res), which should return the TeXmacs tree to be inserted as output. This connection type is used by the AI plug-ins (chatgpt, gemini, ollama, etc.), which are all declared in

plugins/ai/progs/init-ai.scm

.

(:request ,request-fun ,result-fun)
(evaluation through network requests)

This is similar to :cmdline, but request-fun returns a string with a Scheme expression describing a network request instead of a shell command. The only request which is currently understood by

System/Link/request_link.cpp

is of the form (http_post url (tuple header-1 …) data), which performs an asynchronous HTTP POST of JSON data. The answer is again passed to result-fun. This connection type is used by the albert plug-in.

(:socket host port)

(:socket variant host port)
(sockets (not operational))

This option is accepted by plugin-configure and registers a connection of type "socket". However, the function connection_start in

System/Link/connection.cpp

only knows how to start connections of the types "pipe", "dynlink", "cmdline" and "request", so this option cannot be used in practice.

3.3.Sessions and scripts

(:session menu-name)
(shell sessions)

This option indicates that the plug-in supports an evaluator for interactive shell sessions. An item menu-name will be inserted in the Insert\(\rightarrow\)Session menu in order to launch such sessions. The menu-name is also used as the “human” name of the plug-in by plugin->name and session-name.

(:scripts menu-name)
(scripting language)

This option indicates that the plug-in may be used as a scripting language inside documents. The plug-in then appears under the name menu-name in the Document\(\rightarrow\)Scripts menu, in the Insert\(\rightarrow\)Scripts submenu (in text mode) and in the list of scripting languages in the preferences.

(:serializer ,fun)
(input serialization)

If the plug-in can be used as an evaluator, then this option specifies the Scheme function fun which is used in order to transform TeXmacs trees to strings. The function is called as (fun lan t), where lan is the name of the plug-in and t the input in Scheme form, and it should return the string which is sent to the application (usually terminated by a newline). The default serializer is verbatim-serialize; see mathematical and customized input.

(:commander ,fun)
(formatting of special commands)

This option is similar to the :serializer option, except that it is used to transform special commands (such as tab-completion requests and (input-done? …) queries) to strings. The function is called with a single argument, the command string. By default, the command is prefixed by the DATA_COMMAND character (ASCII 16) and terminated by a newline.

(:tab-completion #t)
(tab-completion)

This option indicates that the plug-in supports tab-completion.

(:test-input-done #t)
(multi-line input)

This option indicates that the plug-in provides a routine for testing whether the input is complete; see miscellaneous features.

(:handler channel fun-name)
(custom output channels)

Declare that output of the application to the channel channel (a string) should be passed to the Scheme function with name fun-name. Notice that fun-name is a symbol (no unquote): the function is looked up by name and called with the output document as its only argument. See the handler example plug-in, which uses (:handler "error" handler-error-handler).

(:filter-in x)
(obsolete)

This option is still accepted for compatibility, but it is ignored.

4.Automatically defined predicates

It should be noticed that the configuration of the plug-in myplugin automatically creates a few predicates:

(supports-myplugin?)

Test whether the plug-in is fully operational (all requirements are met), or whether a remote plug-in with the same name has been declared.

(in-myplugin?)

Test whether myplugin is the current programming language, that is, whether the environment variable prog-language equals "myplugin". This is typically the case inside a session of the plug-in. This predicate is defined as a TeXmacs mode (in-myplugin%), so that it can be used in (:mode …) clauses of keyboard and menu definitions.

(myplugin-scripts?)

Test whether myplugin is the current scripting language, that is, whether the environment variable prog-scripts equals "myplugin". This predicate is also defined as a mode.

5.Several connections in one plug-in

A single initialization file may contain several plugin-configure instructions for different names. For instance, the file

plugins/ai/progs/init-ai.scm

declares the connections chatgpt, gemini, ollama, open-mistral-7b and albert, and the jupyter plug-in generates one plugin-configure instruction for each Jupyter kernel found on the system. Moreover, plugin-configure may be called again later for an existing plug-in in order to complete its configuration; for instance, the complete example plug-in sends the command (plugin-configure complete (:tab-completion #t)) to TeXmacs in its startup banner.

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".