Sending commands to TeXmacs

The application may use command as a very particular output format in order to send Scheme commands to TeXmacs. In other words, the block

DATA_BEGINcommand:cmdDATA_END

will send the command cmd to TeXmacs. Such commands are executed immediately after reception of DATA_END. We also recall that such command blocks may be incorporated recursively in larger DATA_BEGIN-DATA_END blocks.

The menus plug-in

The nested plug-in shows how an application can modify the TeXmacs menus in an interactive way. The plug-in consists of the files

    menus/Makefile
    menus/progs/init-menus.scm
    menus/src/menus.cpp

The body of the main loop of menus.cpp simply contains

char buffer[100];
cin.getline (buffer, 100, '\n');
cout << DATA_BEGIN << "verbatim:";
cout << DATA_BEGIN << "command:(menus-add \""
     << buffer << "\")" << DATA_END;
cout << "Added " << buffer << " to menu";
cout << DATA_END;
fflush (stdout);

The Scheme macro menus-add is defined in init-menus.scm:

(menu-bind menus-menu

("Hi" (insert "Hello world")))

(menu-extend texmacs-extra-menu

(if (equal? (get-env "prog language") "menus")

(=> "Menus" (link menus-menu))))

(define-macro (menus-add s)

‘(menu-extend menus-menu

(,s (insert ,s))))

The configuration of menus proceeds as usual:

(plugin-configure menus

(:require (url-exists-in-path? "menus.bin"))

(:launch "menus.bin")

(:session "Menus"))

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