--- Begin Message ---
Subject: |
[PATCH] file-size-human-readable: fix glitches and add optional space |
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.
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
Description: Binary data
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#35756: [PATCH] file-size-human-readable: fix glitches and add optional space |
Date: |
Sun, 23 Jun 2019 20:29:47 +0200 |
23 juni 2019 kl. 18.56 skrev Lars Ingebrigtsen <address@hidden>:
>
> Looks good to me. The only thing is:
>
> In end of data:
> files.el:7717:1:Warning: the function `string-empty-p' is not known to be
> defined.
>
> That function is from subr-x, and I if I remember correctly, files.el
> isn't supposed to load that file...
Thanks, pushed with that function call eliminated in favour of (string= x "").
--- End Message ---