![]() |
The Scheme interface to buffers, views and windows | ![]() |
Almost everything described in this chapter is exported to Scheme, and most of the user visible behaviour (which questions are asked when a document is loaded, saved or closed, where a new document appears) is programmed there. This page relates the three levels:
the C++ routines of
Texmacs/Data/
, of the server and of the editor;
the glue routines, which export them under Scheme names and are generated from the files
build-glue-basic.scm
,
build-glue-server.scm
and
build-glue-editor.scm
of
src/src/Scheme/Glue/
the Scheme library and the user level commands, in
kernel/library/base.scm
,
texmacs/texmacs/tm-files.scm
and
texmacs/texmacs/tm-server.scm
(relative to
src/TeXmacs/progs/
).
The user level documentation of the Scheme functions is in the Scheme buffer API, which describes buffers, views and windows.
The three glue files differ by the object on which the exported routines are called:
build-glue-basic.scm
Free functions, without a receiver. Among those are all buffer, view, window and project routines of
Texmacs/Data/
(the block starting with the comment ;; buffers in that file). They take buffer names, view and window URLs as arguments and therefore work on any buffer.
build-glue-server.scm
Routines called as get_server()->…. Those which concern windows (properties, bars, zoom, footer, dialogs) act on the window of the current view.
build-glue-editor.scm
Routines called as get_current_editor()->…: all editing commands, the cursor, the selection, the undo history and the environment at the cursor. They always act on the current view.
To apply a routine of the last two kinds to another buffer or window, change the current view temporarily with with-buffer or with-window; see working in the context of another view for the limitations of these macros.
The correspondence is mostly one to one, with the Scheme name obtained by replacing underscores by dashes. The noteworthy exceptions are listed in parentheses.
buffer-list (get_all_buffers), current-buffer-url (get_current_buffer_safe), path-to-buffer (path_to_buffer), buffer-new (make_new_buffer), buffer-rename (rename_buffer), buffer-set and buffer-get (set_buffer_tree, get_buffer_tree), buffer-set-body and buffer-get-body, buffer-set-master and buffer-get-master, buffer-set-title and buffer-get-title, buffer-last-save, buffer-last-visited, buffer-modified? (buffer_modified), buffer-modified-since-autosave?, buffer-pretend-modified, buffer-pretend-saved, buffer-pretend-autosaved, buffer-attach-notifier, buffer-has-name?, buffer-aux? (is_aux_buffer), buffer-embedded? (is_embedded_buffer), buffer-import, buffer-load, buffer-export, buffer-save, buffer-focus (focus_on_buffer), buffer-focus* (var_focus_on_buffer) and cpp-buffer-close (kill_buffer).
view-list (get_all_views), buffer->views, current-view-url, window->view, view->buffer, view->window-url, view-new (get_new_view), view-passive (get_passive_view), view-recent (get_recent_view), view-delete (delete_view), window-set-view (window_set_view), switch-to-buffer (switch_to_buffer) and set-drd (set_current_drd).
window-list (windows_list), windows-number (get_nr_windows, which counts all toolkit windows), current-window, buffer->windows, window-to-buffer, window-set-buffer, window-focus, switch-to-window, new-buffer (create_buffer ()), open-buffer-in-window (new_buffer_in_new_window), open-window, clone-window, kill-window and kill-current-window-and-buffer.
project-attach, project-detach (which is project_attach with the default empty name), project-attached? and project-get.
The family alt-window-handle, alt-window-create-quit, alt-window-create-plain, alt-window-create-popup, alt-window-create-tooltip, alt-window-delete, alt-window-show, alt-window-hide, alt-window-get-size, alt-window-set-size, alt-window-get-position, alt-window-set-position and alt-window-search, which wraps the functions at the end of
tm_window.hpp
; these use integer handles, except alt-window-search, which maps a buffer name to the list of handles of its windows; see alternative windows.
(
build-glue-server.scm
) window-get-serial, window-set-property, window-get-property, show-header, show-icon-bar, show-side-tools, show-bottom-tools, show-footer, full-screen-mode, set-window-zoom-factor, set-message, recall-message, cpp-choose-file, tm-interactive, insert-kbd-wildcard, set-variant-keys, kbd-system-rewrite, update-all-buffers, quit-TeXmacs, …
(
build-glue-editor.scm
) root-tree, buffer-path, buffer-tree, cursor-path, key-press, mouse-any, get-input-mode, get-env, go-to-path, the selection routines (selection-active-any?, selection-get-start, …), the undo routines (start-editing, end-editing, archive-state, mark-start, mark-end, mark-cancel, undo, redo, clear-undo-history), notify-change, idle-time, update-menus, …
Several glue routines return url_none () or the empty URL when there is no answer. The library
kernel/library/base.scm
defines wrappers which return #f in that case, and which most Scheme code uses: current-buffer, current-view, window->buffer, view->window, path->buffer, buffer->window, as well as buffer-exists?, buffer->tree, tree->buffer and buffer-master.
The commands bound to menus and keyboard shortcuts are rarely glue routines themselves. They are Scheme functions which add confirmations, autosave handling, recent file lists and the like on top of the glue:
load-buffer, load-buffer-in-new-window, load-browse-buffer, open-buffer (with a file chooser), revert-buffer, open-auxiliary (
tm-files.scm
); see loading.
save-buffer, save-buffer-as, export-buffer, autosave-buffer, autosave-all (
tm-files.scm
); see saving and exporting.
safely-kill-buffer, safely-kill-window, safely-quit-TeXmacs, buffer-close (
tm-server.scm
); see closing a buffer and closing windows.
new-document, new-document*, close-document, close-document* (
tm-server.scm
) choose between the buffer and the window versions of these commands according to the buffer management preference (window-per-buffer?).
New code should normally call the user level commands when it acts on behalf of the user, and the glue routines (or the
base.scm
wrappers) when it manipulates buffers programmatically, for instance to build an auxiliary document in the background without showing it.
A new routine of
Texmacs/Data/
is exported by declaring it in the corresponding header (
new_buffer.hpp
,
new_view.hpp
,
new_window.hpp
) and adding a line such as
(buffer-has-name? buffer_has_name (bool url)) |
to the buffer block of
build-glue-basic.scm
. A new editing command is declared as a pure virtual method of editor_rep, implemented in the appropriate edit_*_rep class (see the editor classes) and added to
build-glue-editor.scm
; a new routine of the server is added to server_rep, implemented in one of the three server classes and added to
build-glue-server.scm
. In all cases the glue has to be regenerated (see the C++/Scheme glue).