Sending commands to TeXmacs |
The application may use command as a very particular
output format in order to send
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 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
(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"))