![]() |
Creating your own dynamic menus | ![]() |
You may define a menu with name name either using
(menu-bind name . def) |
or
(tm-menu (name) . def) |
Here def is a program which represents the entries of the menu. In particular, you may take a look at the files in the directory
$TEXMACS_PATH/progs/menu
in order to see how the standard TeXmacs menus are defined. In the case of tm-menu, it is possible to specify additional arguments, which makes it possible to dynamically construct more complex menus which depend on parameters.
More precisely, the program def in menu-bind or tm-menu is a list of entries of one of the following forms:
(=> "pulldown menu name" menu-definition)
(-> "pullright menu name" menu-definition)
("entry" action)
---
(if condition menu-definition)
(when condition menu-definition)
(link variable)
(former) |
The constructors => and -> are used to create pulldown or pullright menus and menu-definition should contain a program which creates the submenu. In the main (or system) menu bar all root items are pulldown menus and all submenus of these are pullright. Both pulldown and pullright may be used in toolbars or other widgets.
The constructor ("entry" action) creates an ordinary entry, where action will be compiled and executed when you click on entry. Items of a menu may be separated using ---. The constructor if is used for inserting menu items only if a certain condition is satisfied (for instance, if we are in math mode), whereas while always inserts the item but deactivates (e.g. greying it out) it condition is not met.
If you declared a menu name, then you may use this menu indirectly using the link constructor, thus one may link any such “indirect” submenu to as many menus as desired.
Finally, new items may be added to any given menu a posteriori using former, as in the following example:
(tm-menu (tools-menu)
(former)
---
("New item" (noop))) |
The main TeXmacs menus are:
texmacs-menu: contains the root entries of the main menu bar at the top of the window (or desktop under MacOS). It uses link to display file-menu, edit-menu, insert-menu, text-menu, paragraph-menu, document-menu and help-menu among others.
texmacs-main-icons: contains the main toolbar, which typically features buttons to open and save files, copy and paste text, etc.
texmacs-mode-icons: contains the icons which depend on the current editing mode, that is: mathematics, text, code, etc.
texmacs-focus-icons: these icons change with the cursor. One should install here any icons that are specific to a particular tag or context.
texmacs-extra-icons: custom icons for user extensions.
texmacs-popup-menu: the menu which pops up when the user right-clicks on a TeXmacs document. Extending or replacing this menu is useful for instance for plugin writers: you may want to display some extra actions while removing others when the user in inside a session for your plugin.