GNU TeXmacsUser manualReferenceAboutEnglish
Source files

The formats of source code (cpp, python, scheme, java… in

code-format.scm

,

python-format.scm

,

prog-format.scm

) load a file with code->texmacs and save it with texmacs->verbatim and the encoding SourceCode (

init-rewrite.scm

). A file is saved as it was loaded, byte for byte, apart from the lines which were edited (suite source-files,

source-files-test.scm

).

Loading

code->texmacs calls source_document_to_tree (cpp-source->texmacs,

verbatim.cpp

), which differs from verbatim_document_to_tree in what it keeps:

The encoding, the line ends and the indentation are in the initial environment of the document: source-encoding (utf-8, iso-8859-1), source-line-ends (unix, dos, mac) and source-indent (tabs, spaces or empty). attach_subformat (

new_buffer.cpp

) sets prog-tab-width there too, from the preference editor:code tab width (8 by default).

Code which is pasted in a program is converted by source_snippet_to_tree (code-snippet->texmacs), which keeps its tabs and its control characters in the same way; its line ends are LF.

Saving

tree_to_verbatim with the encoding SourceCode follows the initial environment of a document which has source-line-ends (tree_to_source): the lines are converted by cork_to_sourcecode, which writes a character <#9> as the byte 9 (and the ASCII as it is, unlike cork_to_utf8, which writes a backquote as an opening quote and three dots as an ellipsis); a file of ISO-8859-1 is written in it; the line ends are those of the file (not those of the system, as for the other documents). A document without these variables is saved as before.

Tabs in the typesetter

typeset_prog_string (

concat_text.cpp

) typesets a tab as a gap up to the next tab stop, every prog-tab-width columns. The column of a tab is counted from the start of its line (prog_column: a tab goes to its stop, any other character of Cork is one column, the font of programs being monospaced), also when the line is typeset from its middle (the range primitive). The gap (typeset_prog_tab) is a light arrow resized to the width of the gap, whose box has a decorated path, between two empty boxes at the ends of the tab: the cursor goes over it at once, as over a space. A token of a language which contains tabs (a string, a comment) is typeset in pieces (typeset_prog_piece), the tabs at their stops.

The tokenizers take a tab for a blank (is_source_tab in

analyze.hpp

): the blanks_parser of the generic program languages, and cpp_language_rep, scheme_language_rep and verb_language_rep, so that the words after a tab keep their colours.

Indentation
prog-edit.scm

counts the indentation in columns, a tab going to its stop (string-column, string-get-indent), and writes it as the program is indented (program-indent-tabs?: source-indent, else tabs for Go and makefiles, else the preference editor:code indent): string-set-indent writes as many tabs as fit and spaces for the rest, or spaces. One level of indentation (program-indent-step, used by the indentation of Python, Java, Scala, Fortran and dot) is a tab where the lines are indented by tabs, else get-tabstop. insert-tabstop inserts a tab there, else spaces up to the next stop from the column of the cursor. program-indent-line returns the offset of the end of the indentation, where the cursor goes (with tabs, it is not the column).

The indentation of Python strips the comments of a line before it looks at its last character: a # of a character of Cork, as in <#9>, is not a comment (

python-edit.scm

).

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".