unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* min-width display property, but with padding at the start
@ 2024-08-19 20:53 Spencer Baugh
  2024-08-20 11:59 ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Spencer Baugh @ 2024-08-19 20:53 UTC (permalink / raw)
  To: emacs-devel


I'm writing a mode which adds an entry to the mode-line containing a
number.  This number can rapidly grow or shrink (it's a number of build
targets left to build, for a build system like Bazel) so I would like to
pad it to a specified width, to avoid the mode-line jittering around as
the number changes.

Adding a `display' property with the value '(min-width (5.0)) works
fine.

However, min-width pads by adding padding at the end.  I'd like to add
padding at the start instead.

Is there a way to achieve this with display properties?



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-19 20:53 min-width display property, but with padding at the start Spencer Baugh
@ 2024-08-20 11:59 ` Eli Zaretskii
  2024-08-20 12:09   ` Spencer Baugh
  2024-08-20 12:21   ` tomas
  0 siblings, 2 replies; 13+ messages in thread
From: Eli Zaretskii @ 2024-08-20 11:59 UTC (permalink / raw)
  To: Spencer Baugh; +Cc: emacs-devel

> From: Spencer Baugh <sbaugh@janestreet.com>
> Date: Mon, 19 Aug 2024 16:53:58 -0400
> 
> 
> I'm writing a mode which adds an entry to the mode-line containing a
> number.  This number can rapidly grow or shrink (it's a number of build
> targets left to build, for a build system like Bazel) so I would like to
> pad it to a specified width, to avoid the mode-line jittering around as
> the number changes.
> 
> Adding a `display' property with the value '(min-width (5.0)) works
> fine.
> 
> However, min-width pads by adding padding at the end.  I'd like to add
> padding at the start instead.
> 
> Is there a way to achieve this with display properties?

Why do you need display properties?  What's wrong with

  (format "%5s" THE-STRING)

?



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 11:59 ` Eli Zaretskii
@ 2024-08-20 12:09   ` Spencer Baugh
  2024-08-20 13:28     ` Eli Zaretskii
  2024-08-20 12:21   ` tomas
  1 sibling, 1 reply; 13+ messages in thread
From: Spencer Baugh @ 2024-08-20 12:09 UTC (permalink / raw)
  To: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:
>> From: Spencer Baugh <sbaugh@janestreet.com>
>> Date: Mon, 19 Aug 2024 16:53:58 -0400
>> 
>> 
>> I'm writing a mode which adds an entry to the mode-line containing a
>> number.  This number can rapidly grow or shrink (it's a number of build
>> targets left to build, for a build system like Bazel) so I would like to
>> pad it to a specified width, to avoid the mode-line jittering around as
>> the number changes.
>> 
>> Adding a `display' property with the value '(min-width (5.0)) works
>> fine.
>> 
>> However, min-width pads by adding padding at the end.  I'd like to add
>> padding at the start instead.
>> 
>> Is there a way to achieve this with display properties?
>
> Why do you need display properties?  What's wrong with
>
>   (format "%5s" THE-STRING)
>
> ?

That is probably what I'll do if I can't find another solution, but
doing it with display properties works with non-fixed-width characters
and faces, which a user might have configured.

If simply padding with spaces sufficed, the display properties in
(info "(elisp) Specified Space") would have little reason to exist.




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 11:59 ` Eli Zaretskii
  2024-08-20 12:09   ` Spencer Baugh
@ 2024-08-20 12:21   ` tomas
  1 sibling, 0 replies; 13+ messages in thread
From: tomas @ 2024-08-20 12:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Spencer Baugh, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 577 bytes --]

On Tue, Aug 20, 2024 at 02:59:51PM +0300, Eli Zaretskii wrote:
> > From: Spencer Baugh <sbaugh@janestreet.com>

[...]

> > Is there a way to achieve this with display properties?
> 
> Why do you need display properties?  What's wrong with
> 
>   (format "%5s" THE-STRING)

This was my "inner question", too. Then I thought that some folks might
like to use proportional fonts (yeah, Computer Modern has explicit fixed
width for numerals, but not everyone's as wise as DEK ;-)

Not that I would allow a proportional font near my Emacs, ever...

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 12:09   ` Spencer Baugh
@ 2024-08-20 13:28     ` Eli Zaretskii
  2024-08-20 13:42       ` Spencer Baugh
                         ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Eli Zaretskii @ 2024-08-20 13:28 UTC (permalink / raw)
  To: Spencer Baugh; +Cc: emacs-devel

> From: Spencer Baugh <sbaugh@janestreet.com>
> Date: Tue, 20 Aug 2024 08:09:51 -0400
> 
> >> Is there a way to achieve this with display properties?
> >
> > Why do you need display properties?  What's wrong with
> >
> >   (format "%5s" THE-STRING)
> >
> > ?
> 
> That is probably what I'll do if I can't find another solution, but
> doing it with display properties works with non-fixed-width characters
> and faces, which a user might have configured.

Using variable-pitch fonts on the mode line is not recommended, as the
results could be problematic around fields that change dynamically.
The min-width property was introduced to make that easier during the
short period when we considered switching to variable-pitch font by
default, but we later decided not to do that for several reasons.

Are there many people who use variable-pitch fonts on the mode line?

> If simply padding with spaces sufficed, the display properties in
> (info "(elisp) Specified Space") would have little reason to exist.

As an alternative to min-width, you could use a :space display spec
whose width you calculate in Lisp, given string-width of the string
you want to pad.  I think this should work.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 13:28     ` Eli Zaretskii
@ 2024-08-20 13:42       ` Spencer Baugh
  2024-08-20 14:03       ` Ihor Radchenko
                         ` (2 subsequent siblings)
  3 siblings, 0 replies; 13+ messages in thread
From: Spencer Baugh @ 2024-08-20 13:42 UTC (permalink / raw)
  To: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Spencer Baugh <sbaugh@janestreet.com>
>> Date: Tue, 20 Aug 2024 08:09:51 -0400
>> 
>> >> Is there a way to achieve this with display properties?
>> >
>> > Why do you need display properties?  What's wrong with
>> >
>> >   (format "%5s" THE-STRING)
>> >
>> > ?
>> 
>> That is probably what I'll do if I can't find another solution, but
>> doing it with display properties works with non-fixed-width characters
>> and faces, which a user might have configured.
>
> Using variable-pitch fonts on the mode line is not recommended, as the
> results could be problematic around fields that change dynamically.
> The min-width property was introduced to make that easier during the
> short period when we considered switching to variable-pitch font by
> default, but we later decided not to do that for several reasons.

Ah, okay, that makes sense.  I'll just use a format invocation as you
described, then.

> Are there many people who use variable-pitch fonts on the mode line?
>
>> If simply padding with spaces sufficed, the display properties in
>> (info "(elisp) Specified Space") would have little reason to exist.
>
> As an alternative to min-width, you could use a :space display spec
> whose width you calculate in Lisp, given string-width of the string
> you want to pad.  I think this should work.

Yes, that makes sense as a way to support variable-pitch fonts (although
probably a little less reliable than something supported directly by the
display engine)




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 13:28     ` Eli Zaretskii
  2024-08-20 13:42       ` Spencer Baugh
@ 2024-08-20 14:03       ` Ihor Radchenko
  2024-08-20 14:26         ` Eli Zaretskii
  2024-08-20 19:31       ` Petteri Hintsanen
  2024-08-20 19:46       ` Jim Porter
  3 siblings, 1 reply; 13+ messages in thread
From: Ihor Radchenko @ 2024-08-20 14:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Spencer Baugh, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Are there many people who use variable-pitch fonts on the mode line?

I think that it is fairly common to use various Unicode symbols or
emojis that may come from different fonts that may or may not have the
same symbol width (even if each single font is monospaced).

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 14:03       ` Ihor Radchenko
@ 2024-08-20 14:26         ` Eli Zaretskii
  2024-08-20 14:34           ` Ihor Radchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2024-08-20 14:26 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: sbaugh, emacs-devel

> From: Ihor Radchenko <yantar92@posteo.net>
> Cc: Spencer Baugh <sbaugh@janestreet.com>, emacs-devel@gnu.org
> Date: Tue, 20 Aug 2024 14:03:53 +0000
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Are there many people who use variable-pitch fonts on the mode line?
> 
> I think that it is fairly common to use various Unicode symbols or
> emojis that may come from different fonts that may or may not have the
> same symbol width (even if each single font is monospaced).

Spencer's problem was not with such symbols.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 14:26         ` Eli Zaretskii
@ 2024-08-20 14:34           ` Ihor Radchenko
  2024-08-20 18:23             ` Eli Zaretskii
  0 siblings, 1 reply; 13+ messages in thread
From: Ihor Radchenko @ 2024-08-20 14:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: sbaugh, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> > Are there many people who use variable-pitch fonts on the mode line?
>> 
>> I think that it is fairly common to use various Unicode symbols or
>> emojis that may come from different fonts that may or may not have the
>> same symbol width (even if each single font is monospaced).
>
> Spencer's problem was not with such symbols.

Yes, of course. But the topic is more broad.
I do not think that the proposed min-width property is something that is
inherently limited to using on numbers.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 14:34           ` Ihor Radchenko
@ 2024-08-20 18:23             ` Eli Zaretskii
  2024-08-20 18:33               ` Ihor Radchenko
  0 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2024-08-20 18:23 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: sbaugh, emacs-devel

> From: Ihor Radchenko <yantar92@posteo.net>
> Cc: sbaugh@janestreet.com, emacs-devel@gnu.org
> Date: Tue, 20 Aug 2024 14:34:27 +0000
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> > Are there many people who use variable-pitch fonts on the mode line?
> >> 
> >> I think that it is fairly common to use various Unicode symbols or
> >> emojis that may come from different fonts that may or may not have the
> >> same symbol width (even if each single font is monospaced).
> >
> > Spencer's problem was not with such symbols.
> 
> Yes, of course. But the topic is more broad.

No, it isn't, not AFAIU.  Spencer wanted to pad dynamically-generated
strings, so fixed symbols are not very relevant.

> I do not think that the proposed min-width property is something that is
> inherently limited to using on numbers.

Numbers are usually padded on the left, unlike strings.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 18:23             ` Eli Zaretskii
@ 2024-08-20 18:33               ` Ihor Radchenko
  0 siblings, 0 replies; 13+ messages in thread
From: Ihor Radchenko @ 2024-08-20 18:33 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: sbaugh, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> >> > Are there many people who use variable-pitch fonts on the mode line?
>> >> 
>> >> I think that it is fairly common to use various Unicode symbols or
>> >> emojis that may come from different fonts that may or may not have the
>> >> same symbol width (even if each single font is monospaced).
>> >
>> > Spencer's problem was not with such symbols.
>> 
>> Yes, of course. But the topic is more broad.
>
> No, it isn't, not AFAIU.  Spencer wanted to pad dynamically-generated
> strings, so fixed symbols are not very relevant.

Unicode symbols can also be dynamically generated.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 13:28     ` Eli Zaretskii
  2024-08-20 13:42       ` Spencer Baugh
  2024-08-20 14:03       ` Ihor Radchenko
@ 2024-08-20 19:31       ` Petteri Hintsanen
  2024-08-20 19:46       ` Jim Porter
  3 siblings, 0 replies; 13+ messages in thread
From: Petteri Hintsanen @ 2024-08-20 19:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Spencer Baugh, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Are there many people who use variable-pitch fonts on the mode line?

I do.  Haven't spotted any problems, although I haven't looked too
closely either.

FWIW, Emacs tsdh-dark theme uses also variable pitch font on the mode
line.

Thanks,
Petteri



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: min-width display property, but with padding at the start
  2024-08-20 13:28     ` Eli Zaretskii
                         ` (2 preceding siblings ...)
  2024-08-20 19:31       ` Petteri Hintsanen
@ 2024-08-20 19:46       ` Jim Porter
  3 siblings, 0 replies; 13+ messages in thread
From: Jim Porter @ 2024-08-20 19:46 UTC (permalink / raw)
  To: Eli Zaretskii, Spencer Baugh; +Cc: emacs-devel

On 8/20/2024 6:28 AM, Eli Zaretskii wrote:
>> That is probably what I'll do if I can't find another solution, but
>> doing it with display properties works with non-fixed-width characters
>> and faces, which a user might have configured.
[snip]
> Are there many people who use variable-pitch fonts on the mode line?

For what it's worth, I could see 'visual-wrap-line-mode' + SHR/EWW using 
this. If I make an ordered list like so,

   1. Here is
      some text
   2. Here is
      some more
   ...
   10. Here is
       even more

the two-digit items won't line up. It's not hard to compute the max 
number of characters for the numbers, but then you'd end up with:

   1.  Here is
       some text
   ...
   10. Here is
       even more

It'd be nice to right-align the numbers. As you mention up-thread, we 
could do this today via 'format', but that only works because SHR 
currently uses a fixed-pitch font for item numbers no matter what. (I'd 
like to change that so the fonts in EWW are consistent.)

That's not to say we need to add this feature; but if it existed 
already, I'd probably be tinkering with it right now. :)



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-08-20 19:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-19 20:53 min-width display property, but with padding at the start Spencer Baugh
2024-08-20 11:59 ` Eli Zaretskii
2024-08-20 12:09   ` Spencer Baugh
2024-08-20 13:28     ` Eli Zaretskii
2024-08-20 13:42       ` Spencer Baugh
2024-08-20 14:03       ` Ihor Radchenko
2024-08-20 14:26         ` Eli Zaretskii
2024-08-20 14:34           ` Ihor Radchenko
2024-08-20 18:23             ` Eli Zaretskii
2024-08-20 18:33               ` Ihor Radchenko
2024-08-20 19:31       ` Petteri Hintsanen
2024-08-20 19:46       ` Jim Porter
2024-08-20 12:21   ` tomas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).