GNU bug report logs -
#35756
[PATCH] file-size-human-readable: fix glitches and add optional space
Previous Next
Reported by: Mattias Engdegård <mattiase <at> acm.org>
Date: Wed, 15 May 2019 20:11:01 UTC
Severity: minor
Tags: patch
Done: Mattias Engdegård <mattiase <at> acm.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
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 (application/octet-stream, attachment)]
This bug report was last modified 5 years and 329 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.