Hello,
Here’s a basic OCaml plugin.
Thank to @jeroen for his remarks, debug and interest !!!
Cheers, Nicolas
Tools -> Update -> Plugins
Insert -> Session -> OCaml
Result inside TeXmacs:
Hello
Ocaml] 1+1;;
- : int = 2
Ocaml] let a = 10;;
val a : int = 10
Ocaml] let b = "bbb";;
val b : string = "bbb"
Ocaml] Printf.printf("Coucou");;
Coucou
- : unit = ()
Ocaml]
Here are the files:
$TEXMACS_HOME_PATH/plugins/ocaml/src/tmrepl.ml
#use "topfind";;
let () = Toploop.initialize_toplevel_env ();;
let eval s =
let lexbuf = Lexing.from_string s in
let phrase = !Toploop.parse_toplevel_phrase lexbuf in
let success = Toploop.execute_phrase true Format.err_formatter phrase in
ignore success;;
let dDATA_BEGIN = Char.chr 2;;
let dDATA_END = Char.chr 5;;
let dDATA_ESCAPE = Char.chr 27;;
print_char dDATA_BEGIN;;
Printf.printf "verbatim:";;
Printf.printf "Hello";;
print_char dDATA_END;;
flush stdout;;
while true do
let str = read_line () in
eval str;
print_char dDATA_BEGIN;
Printf.printf "verbatim:";
print_char dDATA_END;
flush stdout;
done
$TEXMACS_HOME_PATH/plugins/ocaml/bin/tm_ocaml
#!/bin/bash
### REMOVE THIS LINE (from @jeroen): echo -ne "\002verbatim:"
# start OCaml for plugin session
ocaml $TEXMACS_HOME_PATH/plugins/ocaml/src/tmrepl.ml
$TEXMACS_HOME_PATH/plugins/ocaml/progs/init-ocaml.scm
(plugin-configure ocaml
(:require (url-exists-in-path? "ocaml"))
(:launch "tm_ocaml")
(:session "OCaml"))