![]() |
The macro and shortcut editors | ![]() |
macro-edit.scm
looks for the definition of a tag in two places:
get-definition* searches the document, descending into document, concat, surround, with and the preamble, for an <assign|name|…>. get-definition falls back on the current value in the environment, so that it always returns an assign.
search-style-package loads the style files and packages of the document (tree-load-style*), following use-package, and returns the last one which assigns the name.
edit-macro-source (Focus\(\rightarrow\)Preferences\(\rightarrow\)Edit source) goes to the definition: in the preamble, which is shown for the purpose, or in the .ts file found on $TEXMACS_STYLE_PATH, which is opened in a new buffer.
open-macro-editor (
macro-widgets.scm
) edits one macro in a dialog, or in the side tool when side tools are enabled. It builds a small document in the auxiliary buffer tmfs://aux/edit-name, whose master is the edited buffer, with the style package macro-editor: the preamble of the edited document (so that its macros are known) followed by an edit-macro tag with the name, the arguments and the body of the macro, or an edit-tag tag for a definition which is not a macro. The body is shown in one of three modes, chosen in the dialog: Text, Source (the body wrapped in inactive*) or Mathematics (edit-math).
Apply (macro-apply) reads the definition back and stores it according to the mode of the editor:
The definition replaces the existing assign of the document wherever it is, or, if there is none, is added to its preamble, which is created if needed (macro-set-value); in the latter case, when the edited buffer has a master (a project), the definition is added to the master as well. The style files are never modified; a macro defined in a style file is overridden by a definition in the preamble.
The definition only applies to the tag under focus: it is stored in a with around that tag (tree-with-set). This is Focus\(\rightarrow\)Rendering\(\rightarrow\)Customize macro. The macro-valued parameters of a tag are edited in either mode, depending on the menu: :global from Focus\(\rightarrow\)Preferences, :local from Focus\(\rightarrow\)Rendering.
Variants of the editor:
Source\(\rightarrow\)New macro starts with an empty name, or with the selection as the body;
Source\(\rightarrow\)Create context macro (create-context-macro) makes a macro of one argument from the tags around the cursor (with, unary tags, table formats, …), so that the current layout can be reused;
Source\(\rightarrow\)Create table macro does the same for the format of the current table;
Source\(\rightarrow\)Edit macros (open-macros-editor) shows the list of all names defined in the environment (macros of the style and of the document, and other variables) in one editor; there, edit-focus-macro moves to the macro under the cursor and edit-previous-macro goes back.
The focus menus of a tag offer its style options and its parameters, both computed by
macro-search.scm
from the definitions of the tag and of the macros it expands to. search-tag-options collects the style packages declared for each of these tags with standard-options (for instance the packages which change the rendering of theorems); search-tag-parameters collects the environment variables which the macros read, so that they can be changed for the document (:global) or around the tag. Both results are cached per tag during one search.
shortcut-edit.scm
keeps a list of pairs (key sequence, command), where the command is Scheme code in a string, in $TEXMACS_HOME_PATH/system/shortcuts.scm. Shortly after start-up (when the editor is first idle), if the file exists, init-user-shortcuts reads it and defines each pair with kbd-map (
init-texmacs.scm:306
); set-user-shortcut and remove-user-shortcut update the list, save the file and apply the change with kbd-map or kbd-unmap. The shortcuts are defined without a mode condition.
The shortcut editor (
shortcut-widgets.scm
) records the keys in a preview-shortcut tag: while the cursor is in such a tag, keyboard-press is overloaded to append each key to it instead of executing it. The macro editor and the focus menus open it with the command (make 'name), to create a shortcut which inserts the tag.