GNU TeXmacsUser manualReferenceAboutEnglish
Menus and toolbars

As we said before, menus are special collections of widgets: they are written in the same language as the widgets of dialogs, and the same keywords may be used in both cases (see the reference guide). The main differences are the way they are defined and the containers used to display them.

Defining menus

A menu is defined with

(menu-bind name
  options
  items)

which defines a function name without arguments, or with (tm-menu (name args) options items) for menus with arguments. Both are thin wrappers around tm-define, so that the options (:mode mode?) and (:require pred) may be used for contextual overloading, and (former) may be used inside a redefinition in order to include the previous definition. For instance, the following code adds an entry to the Insert menu in the mode in-database? only (similar code can be found in

progs/database/db-menu.scm

):

(menu-bind insert-menu
  (:mode in-database?)
  (former)
  ---
  ("Database entry" (interactive make-db-entry)))

The items of a menu are typically

Check-marks, dots for interactive commands, tooltips and keyboard shortcuts are usually not specified in the menu itself, but deduced from the properties of the command (see “Meta information and logical programming”):

(tm-define (toggle-session-math-input)
  (:synopsis "Toggle mathematical input in sessions")
  (:check-mark "v" session-math-input?)
  …)

(menu-bind session-input-menu
  …
  (when (in-plugin-with-converters?)
    ("Mathematical input" (toggle-session-math-input)))
  …)

Since menus are recomputed each time they are displayed, conditions like (if (in-math?) …) are evaluated with respect to the current cursor position.

The main menus and toolbars

The C++ part of TeXmacs asks the Scheme code for the menus of each window (see

src/Edit/Interface/edit_interface.cpp

). The menu bar is (horizontal (link texmacs-menu)) and the four toolbars are built from texmacs-main-icons, texmacs-mode-icons, texmacs-focus-icons and texmacs-extra-icons. The context menu which is opened by a right click is texmacs-popup-menu (or texmacs-alternative-popup-menu when the shift or control key is held down). The side and bottom panels are made of the widgets texmacs-side-tools, texmacs-left-tools and texmacs-bottom-tools, which display the tools defined with tm-tool. Most of these menus are defined in

progs/texmacs/menus/main-menu.scm

.

The menus texmacs-extra-menu (inserted in the menu bar before Focus), texmacs-extra-icons, plugin-menu and plugin-icons are empty by default and are intended to be extended by users and plug-ins. For instance:

(menu-bind texmacs-extra-menu
  (former)
  (=> "Greetings"
      ("Hello" (insert "Hello"))
      ("Goodbye" (insert "Goodbye"))))

In a toolbar, the entries are usually icons with a tooltip, as in the following excerpt of texmacs-main-icons:

(=> (balloon (icon "tm_open.xpm") "Load a file") (link load-menu))
((balloon (icon "tm_build.xpm") "Update this buffer")
 (update-document "all"))
Menus in other places

A menu can also be displayed in a separate window with (top-window menu title), or included in a dialog with (link menu). Conversely, the entries of a menu are rendered as flat buttons outside menus, unless they are enclosed in explicit-buttons. Menus which are expensive to compute should be declared lazily in the initialization files with (lazy-menu module names) (see “The module system and lazy definitions”).

The way menus are expanded and turned into native widgets is described in “The Scheme widget language and its interpreter”.

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