From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [elpa] externals/consult-recoll c5926ca3eb 1/2: format for size annotation Date: Thu, 13 Oct 2022 18:08:56 -0400 Message-ID: References: <166569465562.12992.2240825905795534702@vcs2.savannah.gnu.org> <20221013205735.EF3DEC03F23@vcs2.savannah.gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13390"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: jao To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Oct 14 00:27:35 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oj6fu-0003HR-NP for ged-emacs-devel@m.gmane-mx.org; Fri, 14 Oct 2022 00:27:34 +0200 Original-Received: from localhost ([::1]:42722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oj6ft-0003Uc-Or for ged-emacs-devel@m.gmane-mx.org; Thu, 13 Oct 2022 18:27:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oj6O8-0001r0-Bk for emacs-devel@gnu.org; Thu, 13 Oct 2022 18:09:14 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:55723) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oj6Nz-0000Ad-SI; Thu, 13 Oct 2022 18:09:10 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 82264100142; Thu, 13 Oct 2022 18:08:59 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id CEAB61000EF; Thu, 13 Oct 2022 18:08:57 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1665698937; bh=+Ju6ujCiBl8VfbUswV/D7ziudVab0O5Wb/LOcmpl4no=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=kMY+XBHwNKaQh2tgR8dzfwuDHO9yqdWuIN883FG0iwR05wwjt5OreTNy64jP5K5fi wLAmEvLtsYgl2Z13xoa4EQ8IPYHuhwiLZh3sbcQpM1d1Wj1IR8kGqETeZAFFixRMO6 9hWLYT0rq2OVdSs1tHlxsFt4Jnd3MQPY3c9WmEwExcU8eNK5fzT9ga2EhZb2laHWcj XAVgIqTM4KLOYwogFJlcTmSEjVooeQgodqZFLpHpR9S5jSDhpLE5OWfs/xzdv2upau wtVPeXGIq+Wp2qrR6o3Ptmis+Ksa3N1QKSBE/HA2DnmV5BfGseWwxaNmENqA0FbO1g 57qvPilpuVc0A== Original-Received: from pastel (65-110-220-202.cpe.pppoe.ca [65.110.220.202]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 8912A120DA7; Thu, 13 Oct 2022 18:08:57 -0400 (EDT) In-Reply-To: <20221013205735.EF3DEC03F23@vcs2.savannah.gnu.org> (ELPA Syncer's message of "Thu, 13 Oct 2022 16:57:35 -0400 (EDT)") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:297700 Archived-At: 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=E2=84=A2 introduce a function in `subr.el` or somesuch to so= lve it once and for all? Stefan ELPA Syncer [2022-10-13 16:57:35] wrote: > branch: externals/consult-recoll > commit c5926ca3eb9151ebac817689113cb5fe2067f4ae > Author: jao > Commit: jao > > 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))) >=20=20 > +(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 candidat= e))))) > - (format " (%s bytes%s)" size mime))) > + (and (not (consult-recoll--candidate-page candidate)) > + (format " (%s)" (consult-recoll--format-size > + (consult-recoll--candidate-size candidate))))) >=20=20 > (defun consult-recoll--search (&optional initial) > "Perform an asynchronous recoll search via `consult--read'.