![]() |
The tmfs Scheme API | ![]() |
This page documents the Scheme interface of the TeXmacs file system. Unless stated otherwise, the functions and macros are defined in the module (kernel texmacs tm-file-system), file
src/TeXmacs/progs/kernel/texmacs/tm-file-system.scm
, and are available everywhere. In the descriptions, class is the first component of a tmfs URL and name the rest of the URL after tmfs://class/. See the primer for an introduction and the internals for the way these functions are used by the rest of TeXmacs.
Register the procedure handle for the operation action on the URLs of the class class. class is a string, or #t for the default handler of the operation. action is one of the symbols load, save, autosave, remove, wrap, date, title, permission?, master and format; the arguments of handle are those of the corresponding macros below. Registering a handler for a class and action which already have one replaces the old handler.
The following macros are more convenient. Each of them takes a head (class arg1 …), where class is a symbol and the other elements are the names of the variables to which the arguments of the handler are bound, followed by the body of the handler.
The body returns the document tmfs://class/name, either as a Scheme tree ((document (TeXmacs …) (style …) (body …))) or as a string in the format returned by tmfs-format. It should never return the empty string, which is interpreted as a failure. This is the only mandatory handler of a class.
The body saves the document doc, given as a Scheme tree. The save command of TeXmacs refuses to save the buffer unless the permission handler grants "write" access. The result of the handler is ignored.
The body returns a string to be used as the title of the buffer; the loaded document doc is provided so that the title may be extracted from it. Without a title handler, the complete URL is used as title.
The body returns a boolean which tells whether the access kind, either "read" or "write", is granted. Read permission is also what url-exists? tests. Without a permission handler, only read access is granted, unless the class has a wrap handler, in which case the permissions of the wrapped file are used.
The body returns the URL to be used as the master of the buffer (see buffer-set-master) when the document is loaded. Without a master handler, the buffer is its own master.
The body returns the format of the document as a string, such as "texmacs" or "png". The format determines how the string produced by the load handler is parsed, and how the buffer is serialized before saving. Without a format handler, the format is "stm", the Scheme representation of TeXmacs documents. For instance, the revision handler uses the format of the underlying file:
(tmfs-format-handler (revision name)
(with u (tmfs-string->url (tmfs-cdr name))
(url-format u))) |
The body returns the URL of an ordinary file of which the document is a different presentation, or #f. The wrapped file is used by the default permission, date, removal and autosave handlers, and by buffer-last-save.
The body returns the URL where an autosave copy of the document with suffix suf ("~" or "#") should be stored, or #f if autosaving is not supported.
The body returns the date of last modification of the document, in the same unit as url-last-modified, or #f.
The body removes the document and should return #t on success.
Declare that the handlers of the classes class1, …, classn (symbols) are defined in module (a list of symbols such as (part part-tmfs)). None of the arguments is evaluated. The module is loaded when one of these classes is used for the first time.
Load the module registered for class (a string or a symbol), if it has not been loaded yet. All the operations below call this function before looking up a handler.
The following functions take an URL u, as a string or an URL object, decompose it with tmfs-decompose-name and call the appropriate handler, or a default behavior. Most code should use the generic functions for files and buffers instead, which call these functions for tmfs URLs.
Return the document at u as a string. Called by the C++ routine get_from_server.
Save the string what, which is converted from stm into a Scheme tree before being passed to the save handler. Called by the C++ routine save_to_server.
Return the title of the document doc loaded from u. Called by the C++ routine propose_title, and by the menu of recent files.
Check whether the access kind ("read" or "write") to u is permitted. Called by the C++ routine is_of_type, hence by url-test? and url-exists?.
Return the URL which should serve as the master of the buffer u; by default, u itself.
Return the file format of u; by default "stm". Called by the C++ routine file_format, hence by url-format.
Return the file wrapped by u, or #f. The generic function url-wrap in
texmacs/texmacs/tm-files.scm
calls it for tmfs URLs and returns #f for other URLs.
Return the date of last modification of u, or #f. Used by url-last-modified and url-newer?, which are redefined in
tm-files.scm
for tmfs URLs.
Remove u and return #t on success. Used by url-remove.
Return the URL where the autosave copy of u with suffix suf is stored, or #f. Used by url-autosave.
Return #t if (tmfs-autosave u "~") is not #f. Called by the C++ routine get_from_server.
Return #t if no load handler is known for the class of u, even after the lazy loading of its module.
Return the list (class name) of two strings. The prefix tmfs:// is optional; if there is no slash, the class is "file".
(tmfs-decompose-name "tmfs://grep/type=doc&what=tmfs")
;; => ("grep" "type=doc&what=tmfs") |
Given a query string qry of the form var1=val1&var2=val2, return the value of the variable var, for instance "val1" for var equal to "var1". The empty string is returned if the variable does not occur. The value is decoded with tmstring->string.
Return the association list of the variables and values of qry, with the escape %3A replaced by a colon.
Build a query string from an association list of strings, replacing colons by %3A. For instance,
doc/docgrep.scm
opens search results with
(with query (list->query (list (cons "type" "doc") (cons "what" what)))
(load-document (string-append "tmfs://grep/" query))) |
Return a true value if the string s contains a slash.
Return the part of s before the first slash, or #f if there is no slash.
Return the part of s after the first slash, or #f if there is no slash.
Return the list of the components of s.
Join a list of strings with slashes; inverse of tmfs->list.
Encode the URL u as a string which may be embedded in a tmfs name: tm/… for files under $TEXMACS_PATH, file/… for other local files, here/… for relative names and protocol/… otherwise.
Inverse of url->tmfs-string.
Turn c:/dir into c/dir; used by url->tmfs-string on Windows.
Convert the tree t into a Scheme tree and, if it is a document without a TeXmacs version tag, insert the version of TeXmacs. Useful to return imported documents from load handlers.
Serialize obj as a string. tmfs-load converts a (document …) returned by a load handler with texmacs->stm; it only uses object->tmstring for the other results which are not strings.
The module (kernel gui gui-markup) provides macros which simplify the creation of documents: $generic and $tmdoc build complete documents with the generic and tmdoc styles, and $tmfs-title produces a title using the tmfs-title markup. For instance, the history handler is written as
(tmfs-load-handler (history name)
(let* ((u (tmfs-string->url name))
(h (version-history u))
…)
($generic
($tmfs-title "History of " …)
($when (not h)
"This file is not under version control.")
…))) |
Return the URL tmfs://aux/aux.
Set the contents of the auxiliary buffer aux to doc and remember them in the table aux-buffers, so that the buffer can be reloaded.
Set the master of the auxiliary buffer aux and remember it in the table aux-masters.
Defined in
texmacs/texmacs/tm-files.scm
. Set the contents and the master (by default the master of the current buffer) of the auxiliary buffer aux and switch to it.
Return #t if u is a tmfs URL. Glue for the C++ function is_rooted_tmfs.
Return #t if u is a tmfs URL of the class class, as in (url-rooted-tmfs-protocol? u "part").