Subject: bug#72309: propertized-buffer-identification with maximum width

From: Heime <[email-masked]>
Date: Sat, 27 Jul 2024 13:08:31 +0000

On Sunday, July 28th, 2024 at 1:00 AM, Eli Zaretskii <[email-masked]> wrote:

> > Date: Sat, 27 Jul 2024 12:23:20 +0000
> > From: Heime [email-masked]
> > Cc: [email-masked]
> > 
> > Sent with Proton Mail secure email.
> > 
> > On Sunday, July 28th, 2024 at 12:05 AM, Eli Zaretskii [email-masked] wrote:
> > 
> > > > Date: Sat, 27 Jul 2024 09:22:21 +0000
> > > > From: Heime [email-masked]
> > > > Cc: [email-masked]
> > > > 
> > > > On Saturday, July 27th, 2024 at 5:48 PM, Eli Zaretskii [email-masked] wrote:
> > > > 
> > > > > tags 72309 notabug
> > > > > thanks
> > > > > 
> > > > > > Date: Fri, 26 Jul 2024 19:04:14 +0000
> > > > > > From: Heime via "Bug reports for GNU Emacs,
> > > > > > the Swiss army knife of text editors" [email-masked]
> > > > > > 
> > > > > > propertized-buffer-identification could be improved so that when using a
> > > > > > maximum width there are three dots and a space at the end to indicate
> > > > > > that the buffer name has been truncated.
> > > > > 
> > > > > Emacs doesn't truncate the buffer name shown on the mode line, so no
> > > > > ellipsis should be needed, ever. IOW, the maximum width is basically
> > > > > infinity.
> > > > > 
> > > > > Where did you see the buffer name truncated on the mode line?
> > > > 
> > > > There is this construct
> > > > 
> > > > (width rest…)
> > > > 
> > > > which specifies truncation or padding of the results of rest.
> > > > 
> > > > If used on the buffer name it just truncates without specification
> > > > that truncation occurred.
> > > 
> > > Where in the Emacs code did you see that? I cannot find anything like
> > > that in bindings.el, which is where we have the code used for
> > > displaying the buffer name on the mode line.
> > 
> > The last entry in "24.4.2 The Data Structure of the Mode Line".
> > 
> > I have tried it and setting a maximum width does work and the abrupt
> > truncation in the buffer name does occur.
> 
> 
> Yes, but the (WIDTH something) construct is not for truncating long
> names, it's for ensuring the string produced by "something" doesn't
> take too many columns. So you are using this for a wrong purpose. If
> you want to truncate a buffer's name, use truncate-string-to-width
> instead, which is also capable of showing the ellipsis at the end.

I do not know how to access the buffer name and apply truncate-string-to-width
when setting mode-line-buffer-identification on propertized-buffer-identification.

It is a very difficult thing.