Insert text from an external editor (ex:vim)

I’m new to Texmacs, and I’m really interested in knowing how to create plugins to simplify my workflow.

I’m coming from LaTeX + Vim to do my presentation, and I’m quite a big fan of plain-text, and the unix tools to process it.

I find myself in the same situation as the browser: modern browser offer amazing features, but I’m lacking the text editing experience from vim. So for example I use a plugin to edit every text-area in the browser in an emulation of vim.

My question is: how can I do that in texmacs ?

If I want to type an entire paragraph in my favorite editor, how can I do it ?

The behavior I would like to implement is:
I use a shortcut key, that opens my editor, I create my text, I save and close my editor, and the text I just was editing is inserted.

Any help would be amazing !

I just discovered the function “eval-system”, and It somewhat works.

Whene I do

(insert (eval-system "date"))

I get unicode errors, and newlines are not printed.
Is there another way to do that ?

Hi @rambi and welcome to the forum.

I have the feeling that what you want is possible, but I am able to help you only partially.

For inserting texts that are more complex than a string, you need to have a basic grasp of TeXmacs document format.

In the official documentation this is explained in a bit of fragmented way (as far as I know), but you can help yourself combining e.g. https://www.texmacs.org/tmweb/manual/webman-format.en.html with chapter 1.7 of http://www.texmacs.org/tmweb/documents/manuals/texmacs-scheme.en.pdf

In particular chapter 1.7 of http://www.texmacs.org/tmweb/documents/manuals/texmacs-scheme.en.pdf introduces Scheme trees, which I think are the most interesting for you, as they are the easiest to write with a text editor.

Newlines are encoded using the document tag, e.g. you could do

(stree->tree `(document "line 1" "line 2"))

You have to use a quasiquote (backtick) so that you can execute commands in the list (which you need to mark with a comma):

(stree->tree `(document "now" ,(eval-system "date")))

These are Scheme S-expressions.

For opening an external editor and have TeXmacs pick up a document part from there I would have to do much experimentation, let us see if anyone else can help first. And I am not able to help with Unicode, sorry.

Apart this, the first few paragraph of section 1.7 in http://www.texmacs.org/tmweb/documents/manuals/texmacs-scheme.en.pdf give some indications on how to control a document from another document, which you could find interesting (even if it is not what you are asking for).

Here is a note: TeXmacs is a structured editor, and there are very few “text areas” as in browsers (almost all texts are stylesheets), but maybe you are also interested in vim keybindings: A very tiny vim in Texmacs