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

Previous Next

Package: emacs;

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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 35756 in the body.
You can then email your comments to 35756 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#35756; Package emacs. (Wed, 15 May 2019 20:11:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mattias Engdegård <mattiase <at> acm.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 15 May 2019 20:11:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] file-size-human-readable: fix glitches and add optional space
Date: Wed, 15 May 2019 22:02:50 +0200
[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)]

Severity set to 'minor' from 'normal' Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 16 May 2019 12:00:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35756; Package emacs. (Fri, 17 May 2019 05:57:01 GMT) Full text and rfc822 format available.

Message #10 received at 35756 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mattias Engdegård <mattiase <at> acm.org>
Cc: 35756 <at> debbugs.gnu.org
Subject: Re: bug#35756: [PATCH] file-size-human-readable: fix glitches and add
 optional space
Date: Fri, 17 May 2019 08:56:26 +0300
> From: Mattias Engdegård <mattiase <at> acm.org>
> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35756; Package emacs. (Fri, 17 May 2019 11:02:01 GMT) Full text and rfc822 format available.

Message #13 received at 35756 <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 35756 <at> debbugs.gnu.org
Subject: Re: bug#35756: [PATCH] file-size-human-readable: fix glitches and add
 optional space
Date: Fri, 17 May 2019 13:01:19 +0200
[Message part 1 (text/plain, inline)]
17 maj 2019 kl. 07.56 skrev Eli Zaretskii <eliz <at> gnu.org>:
> 
> 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 (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35756; Package emacs. (Sun, 23 Jun 2019 16:57:02 GMT) Full text and rfc822 format available.

Message #16 received at 35756 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Mattias Engdegård <mattiase <at> acm.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 35756 <at> debbugs.gnu.org
Subject: Re: bug#35756: [PATCH] file-size-human-readable: fix glitches and add
 optional space
Date: Sun, 23 Jun 2019 18:56:16 +0200
Mattias Engdegård <mattiase <at> acm.org> writes:

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

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...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Reply sent to Mattias Engdegård <mattiase <at> acm.org>:
You have taken responsibility. (Sun, 23 Jun 2019 18:30:02 GMT) Full text and rfc822 format available.

Notification sent to Mattias Engdegård <mattiase <at> acm.org>:
bug acknowledged by developer. (Sun, 23 Jun 2019 18:30:02 GMT) Full text and rfc822 format available.

Message #21 received at 35756-done <at> debbugs.gnu.org (full text, mbox):

From: Mattias Engdegård <mattiase <at> acm.org>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 35756-done <at> debbugs.gnu.org
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 <larsi <at> gnus.org>:
> 
> 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 "").





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 22 Jul 2019 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 280 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.