Include a text file in texmacs and be able to edit it automatically

Good morning,

I return to my wish to include a text file (python or other…) in texmacs.
And I also want to be able to then edit the text directly in texmacs.

I have several ways to do it but they work more or less well.
I would like some advice and some help.

  1. My first way is the following (I use it with a keyboard shortcut):

(begin (make-include “/home/biz/Bureau/TEXMACS/mes-fichiers-texmacs/Exercice.tm”) (buffer-expand-includes))

However, the (buffer-expand-includes) statement seems finicky. Sometimes it doesn’t work and the text file that is included in texmacs is not editable.

  1. My second solution is the following:

(tree-load-inclusion (string->url “/home/biz/Documents/fichier.tex” ))

either

(tm-define (mon-inclusion chemin-fichier) (tree-load-inclusion (string->url chemin-fichier )))
(mon-inclusion “/home/biz/Documents/equation2.tex”)

It works well but I have the impression that by using it locally in a procedure, it may not work.

  1. My third solution uses a python script which copies the content of my text file to the clipboard and writes this content to texmacs with the statement

(clipboard-paste-import “python” “primary”).

It seems to me that it works well in all situations but I avoided using scheme…

  1. I searched and found this solution in scheme which I can’t get to work:

define (fichier-texte-dans-liste filename)
(with-input-from-file filename (lambda ()
(let loop ((l (read-line))
(r '()))
(if (eof-object? l)
(reverse r)
(loop (read-line) (cons l r)))))))

I think this should give me what it takes to get the text file in texmacs but it doesn’t work?

(insert ’ (stm-list->document (fichier-texte-dans-liste “/home/biz/Documents/file.txt”)))

L’instruction ci-dessus ne veut pas me donner ce qu’il me faut pour retrouver mon fichier texte dans texmacs:

(insert ’ (document “ligne 1” “ligne2” “ligne3” “ligne4”))

I progress little by little and I try to create my own functions…
Thanks for your help.

You might want also to check out the literate programming package Packages->Utilities->literate which allows you to include in your document programs and extracts them automatically into independent files. I think is a great tool. It is not difficult to see how to use it if you know a bit the concept of literate programming, see http://www.literateprogramming.com . Note also that there is an old but good literate programming tool for TeXmacs, called fangle see https://savannah.nongnu.org/p/fangle AFAIK it still works with the current TeXmacs and has some more features than the package (but also depends on some external tool).