I'm using line-number-mode
to have an indicator of the current line in my modeline, however for large files or rather, files with long lines, it starts displaying two question marks instead of a line number. I've digged a bit and found out that while line-number-mode
is defined in simple.el
, the customizable variables (and probably all logic involved) are defined in xdisp.c
. Changing the line-number-display-width
variable to an arbitrarily high number might fix this, but I'm far more interested in the piece of code and the logic that makes it print the two question marks. It'd be very useful if any of you could find it for me, maybe even explain the logic behind it.
1 Answer
Thanks to @lunaryorn's suggestions I've been able to locate the piece of code causing this. It looks like format-mode-line
eventually calls decode_mode_spec
to turn the format codes given into values. For the case of %l
this function does a few sanity checks to avoid spending too much time calculating, then checks whether the current line is exceeding line-number-display-limit-width
. Since that is the case for my file in question, it jumps to a no_value
label which returns a padded ??
as value.
"Solving" this involves setting the variable to a sufficiently high value:
(setq line-number-display-limit-width 2000000)
This value was derived by looking at the corresponding heuristics in xdisp.c
which takes the window height times two plus thirty and multiplies it with line-number-display-limit-width
, to avoid overflowing most-positive-fixnum
on a 32bit system, a value of 2000000 would be a safe bet.
-
2Instead of keeping two similar questions, shouldn't the other question be closed as a duplicate and update this answer instead? Commented Apr 21, 2015 at 17:37
-
-
3For temporary changes:
M-x set-variable <RET> line-number-display-limit-width <RET> 2000000 <RET>
Commented Jun 15, 2017 at 13:41 -
I suppose this made sense back when computers were much slower. I've had it set to a high value in my init file for several decades. Commented Oct 7, 2018 at 3:24
M-: (format-mode-line "%l")
show questions marks, too?format-mode-line
.