Doxygen @code line numbers
doxygen
Solution
Short Answer
It seems that at least in the current version (1.8.9) line numbers are added:
- to C code only when using `\includelineno` tag
- to any Python code
Details
Python code formatter
Python code formatter includes line numbers if `g_sourceFileDef` evaluates as `TRUE`:
/*! start a new line of code, inserting a line number if g_sourceFileDef
* is TRUE. If a definition starts at the current line, then the line
* number is linked to the documentation of that definition.
*/
static void startCodeLine()
{
//if (g_currentFontClass) { g_code->endFontClass(); }
if (g_sourceFileDef)
( https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/pycode.l#L356 )
It's initialized from `FileDef *fd` passed into `parseCode`/`parsePythonCode` if it was provided (non-zero) or from `new FileDef(<...>)` otherwise:
g_sourceFileDef = fd;
<...>
if (fd==0)
{
// create a dummy filedef for the example
g_sourceFileDef = new FileDef("",(exName?exName:"generated"));
cleanupSourceDef = TRUE;
}
( https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/pycode.l#L1458 ) so it seems all Python code is having line numbers included
C code formatter
C code formatter has an additional variable `g_lineNumbers` and includes line numbers if both `g_sourceFileDef` and `g_lineNumbers` evaluate as `TRUE`:
/*! start a new line of code, inserting a line number if g_sourceFileDef
* is TRUE. If a definition starts at the current line, then the line
* number is linked to the documentation of that definition.
*/
static void startCodeLine()
{
//if (g_currentFontClass) { g_code->endFontClass(); }
if (g_sourceFileDef && g_lineNumbers)
( https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/code.l#L486 )
They are initialized in the following way:
g_sourceFileDef = fd;
g_lineNumbers = fd!=0 && showLineNumbers;
<...>
if (fd==0)
{
// create a dummy filedef for the example
g_sourceFileDef = new FileDef("",(exName?exName:"generated"));
cleanupSourceDef = TRUE;
}
( https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/code.l#L3623 )
Note that `g_lineNumbers` remains `FALSE` if provided `fd` value was 0
HtmlDocVisitor
Among `parseCode` calls in `HtmlDocVisitor::visit` there is only one (for `DocInclude::IncWithLines`, what corresponds to `\includelineno`) which passes non-zero `fd`: https://github.com/doxygen/doxygen/blob/Release_1_8_9/src/htmldocvisitor.cpp#L540 so this seems to be the only command which will result in line numbers included into C code listing
Problem
Is there a way to display code line numbers inside a `@code` ... `@endcode` block? From the screenshots in the doxygen manual it would seem that there is, but I was unable to find an option for doxygen itself, or a tag syntax to accomplish this. I need this to be able to write something like "In the above code, line 3" after a code block. Tested also for fenced code blocks, still getting no numbers.