From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Cc: jao <jao@gnu.org>
Subject: Re: [elpa] externals/consult-recoll c5926ca3eb 1/2: format for size annotation
Date: Thu, 13 Oct 2022 18:08:56 -0400 [thread overview]
Message-ID: <jwvr0zbqsw9.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20221013205735.EF3DEC03F23@vcs2.savannah.gnu.org> (ELPA Syncer's message of "Thu, 13 Oct 2022 16:57:35 -0400 (EDT)")
I see we have `memory-report--format` which does something similar.
I'm pretty sure we have other chunks of code doing the same elsewhere.
Should Someone™ introduce a function in `subr.el` or somesuch to solve
it once and for all?
Stefan
ELPA Syncer [2022-10-13 16:57:35] wrote:
> branch: externals/consult-recoll
> commit c5926ca3eb9151ebac817689113cb5fe2067f4ae
> Author: jao <jao@gnu.org>
> Commit: jao <jao@gnu.org>
>
> format for size annotation
> ---
> consult-recoll.el | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/consult-recoll.el b/consult-recoll.el
> index acb178eba6..92de27b9ce 100644
> --- a/consult-recoll.el
> +++ b/consult-recoll.el
> @@ -269,14 +269,19 @@ Set to nil to use the default 'title (path)' format."
> "If TRANSFORM return candidate, othewise extract mime-type."
> (if transform candidate (consult-recoll--candidate-mime candidate)))
>
> +(defun consult-recoll--format-size (bytes)
> + "Format the given size with adaptive units."
> + (let ((szn (string-to-number bytes)))
> + (cond ((< szn 1024) (format "%s bytes" szn))
> + ((< szn 1048576) (format "%.1f Kbs" (/ szn 1024.0)))
> + ((< szn 1073741824) (format "%.1f Mbs" (/ szn 1024 1024)))
> + (t (format "%.1fs Gbs" (/ szn 1024 1024 1024))))))
> +
> (defun consult-recoll--annotation (candidate)
> "Annotation for the given CANDIDATE (its size by default)"
> - (let* ((head (not (consult-recoll--candidate-page candidate)))
> - (size (consult-recoll--candidate-size candidate))
> - (mime (if head
> - ""
> - (format ", %s" (consult-recoll--candidate-mime candidate)))))
> - (format " (%s bytes%s)" size mime)))
> + (and (not (consult-recoll--candidate-page candidate))
> + (format " (%s)" (consult-recoll--format-size
> + (consult-recoll--candidate-size candidate)))))
>
> (defun consult-recoll--search (&optional initial)
> "Perform an asynchronous recoll search via `consult--read'.
next parent reply other threads:[~2022-10-13 22:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <166569465562.12992.2240825905795534702@vcs2.savannah.gnu.org>
[not found] ` <20221013205735.EF3DEC03F23@vcs2.savannah.gnu.org>
2022-10-13 22:08 ` Stefan Monnier [this message]
2022-10-14 1:44 ` [elpa] externals/consult-recoll c5926ca3eb 1/2: format for size annotation Visuwesh
2022-10-14 19:15 ` Stefan Monnier
2022-10-14 20:04 ` jao
2022-10-15 2:57 ` Stefan Kangas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvr0zbqsw9.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=jao@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).