21

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.

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

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.

  • 2
    Instead of keeping two similar questions, shouldn't the other question be closed as a duplicate and update this answer instead? – Kaushal Modi Apr 21 '15 at 17:37
  • @kaushalmodi: Done! – wasamasa Apr 22 '15 at 9:17
  • 1
    For temporary changes: M-x set-variable <RET> line-number-display-limit-width <RET> 2000000 <RET> – Eponymous Jun 15 '17 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 Oct 7 '18 at 3:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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