25

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.

3
  • 2
    Does M-: (format-mode-line "%l") show questions marks, too?
    – user227
    Commented Nov 23, 2014 at 10:46
  • Yes, it does give me "??" as evaluation result.
    – wasamasa
    Commented Nov 23, 2014 at 11:05
  • 1
    Well, then take a look at the definition of format-mode-line.
    – user227
    Commented Nov 23, 2014 at 11:09

1 Answer 1

31

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.

4
  • 2
    Instead 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
  • @kaushalmodi: Done!
    – wasamasa
    Commented Apr 22, 2015 at 9:17
  • 3
    For temporary changes: M-x set-variable <RET> line-number-display-limit-width <RET> 2000000 <RET>
    – Eponymous
    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.
    – Jim Balter
    Commented Oct 7, 2018 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.