How add something authomatically in preamble?

That particular function happens to be defined in the C++ part of GNU TeXmacs, it’s the buffer_has_name function in src/Texmacs/Data/new_buffer.cpp
It is exported to Scheme as buffer-has-name? in src/Scheme/Glue/build-glue-basic.scm

Thank you. I’m a physicist and learning a little bit scheme and did not produce a program. I read that the TexMacs was written by using scheme. But the source code of the Texmacs is C++. I thought that I could read the source code in scheme and (maybe) understand it. Could you explain me this point?

Before @jeroen tells you how-to find the place where a Scheme function is defined—Scheme is used by TeXmacs as an extension language: that means that TeXmacs is written in C++, but one can modify the behaviour of the program without recompiling it through Scheme code. I do not know how this works, but there are interfaces (I think that they are called the “glue”) through which Scheme communicates with the compiled C++ code.

Thanks a lot. In directory Texmacs, all files are written in scheme.

Probably the most convenient way to explore the source code is via Help -> Search -> Source Code inside TeXmacs.

According to Github 25.7% of the TeXmacs repo is C++, while 22.7% is Scheme.

I’m not a developer either, but from browsing the C++ code, it seems to contain various important functionality: the GUI interface, font handling, the typesetter, datatypes such as tree,…

I can’t say I know what rationale determines what is done in C++ and what is done in Scheme. My guess is that if you only need to access the document tree structure and can make do with the functionality exposed by the C++ code, you can stick to Scheme. This is what we did previously in our development of new label selection functionality, we searched the tree and used GUI elements that were already present.

If you want to implement more fundamental functionality, such as line numbering or wrapping figures, you’ll most likely have to dig into the C++ code.

See also “The gory details” section in this blog post.