Subject: bug#28524: 26.0.60; Truncation in %d displayed numbers in minor mode lighter

From: Eli Zaretskii <[email-masked]>
Date: Wed, 20 Sep 2017 19:15:55 +0300

> From: Kaushal Modi <[email-masked]>
> Date: Wed, 20 Sep 2017 13:44:49 +0000
> 
> (defvar test-cache 0)
> 
> (defconst test-format-mode-lighter
> `(" test:" (:eval (format ,(propertize "%d" 'face 'font-lock-warning-face) (test-incr)))))
> 
> (defun test-incr ()
> (setq test-cache (1+ test-cache))
> test-cache)
> 
> (define-minor-mode test-format-mode
> "Test that the dynamic minor mode lighter does not get truncated."
> :lighter test-format-mode-lighter
> (unless test-format-mode
> (setq test-cache 0)))
> =====
> 
> 1. Start emacs -Q (emacs 26+).
> 2. Evaluate the above dummy code snippet.
> 3. M-x test-format-mode
> 
> You will see this:
> image.png
> 
> 4. Now move the cursor around.. you will see the number after "test:" increment.. once it reaches 9, the next
> increment would be 10.. but then the numbers disappear altogether. You see this now:
> 
> image.png
> 
> Upon doing C-h v test-format-mode-lighter, I see:
> 
> test-format-mode-lighter’s value is
> (" test:"
> (:eval
> (format
> #("%d" 0 2
> (face font-lock-warning-face))
> (test-incr))))
> 
> I don't understand the exact meaning of those numbers "0 2", but looks like that limits the number of
> characters to be displayed after "test:"?

No, it means that the face covers 2 characters starting with the first
one.

> As a quick hack, I replace the "%d" in that variable with "%-3d".
> 
> Now the C-h v gives:
> 
> test-format-mode-lighter’s value is
> (" test:"
> (:eval
> (format
> #("%-3d" 0 4
> (face font-lock-warning-face))
> (test-incr))))
> 
> So the number of character limit got raised because "%-3d" is literally 4 characters.
> 
> If I make that "%-10d".. the limit is literally 5 characters!!

Which is all correct, the problem, if there is one, is elsewhere.

I don't think I understand all the complexity you've gone through,
because this works for me in the current emacs-26 branch:

  (insert (format (propertize "%d" 'face 'font-lock-warning-face) 10))

How is this different from what you do?