bug#35756: [PATCH] file-size-human-readable: fix glitches and add optional space

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

bug#35756: [PATCH] file-size-human-readable: fix glitches and add optional space

Mattias Engdegård-2
The `file-size-human-readable' function is very useful but could do with some better formatting: normally, a space goes between the number and unit; you don't write '3kg' or '25m/s' but '3 kg' and '25 m/s' (sloppy British newspapers notwithstanding). We could add an optional argument so that the caller can use the spacing of preference; the default should probably be no space, for compatibility.

For some reason, only the `iec' mode adds an actual unit (B) to the result; the default and `si' modes just append a scale prefix. Of course a user can append the unit of choice, as in:

  (concat (file-size-human-readable size 'si) "B")

which permits the function to be used for other units than bytes, such as "bit/s" (although the name makes it clear that it is intended for file sizes only). However, spacing complicates things, since we want

  (file-size-human-readable 14 'si " ")

to return "14", not "14 ", but the latter is what we need when appending the unit.
I'm not sure how to fix this. We could add another optional argument, UNIT say, which is the string to use as unit, defaulting to "B" in `iec' mode and the empty string otherwise. The attached patch does not address this.

There is also a small glitch to be fixed:

 (file-size-human-readable 3 'iec) => "3iB"

which of course should be "3B".


0001-Optional-space-in-file-size-human-readable.patch (12K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

bug#35756: [PATCH] file-size-human-readable: fix glitches and add optional space

Eli Zaretskii
> From: Mattias Engdegård <[hidden email]>
> Date: Wed, 15 May 2019 22:02:50 +0200
>
> The `file-size-human-readable' function is very useful but could do with some better formatting: normally, a space goes between the number and unit; you don't write '3kg' or '25m/s' but '3 kg' and '25 m/s' (sloppy British newspapers notwithstanding). We could add an optional argument so that the caller can use the spacing of preference; the default should probably be no space, for compatibility.

I have no opinion regarding the change, but I have a minor comment
about the documentation:

> +** The function 'file-size-human-readable' accepts another optional argument.
> +The new third argument is a string put between the number and unit;
> +if nil or omitted, the empty string is used.  It is recommended to use
> +a single space or non-breaking space for readability.

This uses the passive tense too much.  The "if nil or omitted, the
empty string is used" part could be worded more clearly as "it
defaults to the empty string".  The "It is recommended" part is better
worded as "We recommend".

> +Optional third argument SPACE is a string put between the number and unit.
> +If nil or omitted, the empty string is used.

Same here.

Thanks.



Reply | Threaded
Open this post in threaded view
|

bug#35756: [PATCH] file-size-human-readable: fix glitches and add optional space

Mattias Engdegård-2
17 maj 2019 kl. 07.56 skrev Eli Zaretskii <[hidden email]>:
>
> This uses the passive tense too much.  The "if nil or omitted, the
> empty string is used" part could be worded more clearly as "it
> defaults to the empty string".  The "It is recommended" part is better
> worded as "We recommend".

Thank you, fixed.

>> +Optional third argument SPACE is a string put between the number and unit.
>> +If nil or omitted, the empty string is used.
>
> Same here.

Fixed.

I also added the optional argument UNIT to settle that problem. New patch attached.


0001-Optional-space-and-unit-in-file-size-human-readable-.patch (13K) Download Attachment