Subject: bug#41250: 28.0.50; Dired displays unconditionally ls-switches on modeline

From: Juri Linkov <[email-masked]>
Date: Sun, 04 Oct 2020 22:44:22 +0300

>> on every use I need to wrap it with such code:
>>
>>   (let ((ellipsis (cond
>>                    (truncate-string-ellipsis)
>>                    ((char-displayable-p ?…) "…")
>>                    ("..."))))
>>     (truncate-string-to-width string max nil nil ellipsis))
>>
>> Preferably, this should be fixed with this patch:
>
> Your patch is a distinct improvement on the current state of affairs, so
> please go ahead and push to master (with a NEWS item).

Pushed now with a NEWS item.

When I grepped for more usages of truncate-string-to-width, I found
one call in Gnus.  It seems this patch could improve gnus-set-mode-line,
but I'm not sure, and moreover I have no idea how to test this:

diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index b3ed5cb664..42ba4fbd71 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -6240,8 +6240,7 @@ gnus-set-mode-line
 	  ;; We might have to chop a bit of the string off...
 	  (when (> (length mode-string) max-len)
 	    (setq mode-string
-		  (concat (truncate-string-to-width mode-string (- max-len 3))
-			  "...")))))
+		  (truncate-string-to-width mode-string (- max-len 3) nil nil t)))))
       ;; Update the mode line.
       (setq mode-line-buffer-identification
 	    (gnus-mode-line-buffer-identification (list mode-string)))

Here is another function, and it needs not just an improvement,
but a plain bug fix because its args were wrong, and this patch should fix
its args, but again currently I don't yet know how to test this:

diff --git a/lisp/ibuffer.el b/lisp/ibuffer.el
index c9a748830c..8ff3b56c5e 100644
--- a/lisp/ibuffer.el
+++ b/lisp/ibuffer.el
@@ -1597,7 +1597,7 @@ ibuffer-compile-make-eliding-form
 (defun ibuffer-compile-make-substring-form (strvar maxvar from-end-p)
   (if from-end-p
       ;; FIXME: not sure if this case is correct (Bug#24972)
-      `(truncate-string-to-width str strlen (- strlen ,maxvar) nil ?\s)
+      `(truncate-string-to-width str strlen (- strlen ,maxvar) ?\s)
     `(truncate-string-to-width ,strvar ,maxvar nil ?\s)))
 
 (defun ibuffer-compile-make-format-form (strvar widthform alignment)