Meta information and logical programming |
Small software projects usually consist of a collection of routines and data. In a large software project, where a typical contributor has no complete overview of the program, it is a good practive to associate additional meta-information to the individual routines and data. This meta-information typically serves documentation purposes, but becomes even more interesting if it can be used in an automized fashion to implement more general additional functionality.
The tm-define macro supports several options for associating
meta-information to
(tm-define (square x)
(:synopsis "Compute the square of @x")
(:argument x "A number")
(:returns "The square of @x")
(* x x))
This information is exploited by TeXmacs in several ways. For instance, the synopsis of the function can be retrieved by executing (help square). More interestingly, assuming that we defined square as above, typing M-x followed by square and return allows you to execute square in an interactive way: you will be prompted for “A number” on the footer. Moreover, after typing M-x, you will be able to use “tab-completion” in order to enter square: typing s q u tab will usually complete into square.
In a similar vein, the :interactive and :check-mark options allow you to specify that a given routine requires interactive user input or when it should give rise to a check-mark when used in a menu. For instance, the statement
(tm-property (choose-file fun text type)
(:interactive #t))
in the source code of TeXmacs states that choose-file is an
interactive command. As a consquence, the
("Load" (choose-file load-buffer "Load
file" ""))
will be followed by dots ... in the
(tm-define (toggle-session-math-input)
(:check-mark "v" session-math-input?)
(session-use-math-input (not
(session-math-input?))))
Given a menu item with (toggle-session-math-input) as its associated action, this definition specifies in particular that a check-mark should be displayed before the menu item whenever the session-math-input? predicate holds.
Another frequently used option is :secure, which specifies that a
given routine is secure. For instance, the default implementation of
the
(tm-define (mouse-unfold)
(:secure #t)
(with-action t
(tree-go-to t :start)
(fold)))
The :secure option is also needed in combination with other
tags which depend on
In the future, the number of options for entering meta-information is likely to increase. TeXmacs also supports an additional mechanism for the automatic deduction of new meta-properties from existing meta-properties. This mechanism is based on a less general, but more efficient form of logical programming. However, since it is not fully stable yet, it will be documented only later.