The library and the editor are not reentrant. The editor use a lot of global variable. Errors should raise in multi-document editors. You should change API library to avoid this program. Add a ghost param (void*) to API library and pass this parameter to new_token and nextchar.
Why not readbuf instead of nextchar ?