all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: [elpa] externals/consult-recoll c5926ca3eb 1/2: format for size annotation
       [not found] ` <20221013205735.EF3DEC03F23@vcs2.savannah.gnu.org>
@ 2022-10-13 22:08   ` Stefan Monnier
  2022-10-14  1:44     ` Visuwesh
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2022-10-13 22:08 UTC (permalink / raw)
  To: emacs-devel; +Cc: jao

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




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [elpa] externals/consult-recoll c5926ca3eb 1/2: format for size annotation
  2022-10-13 22:08   ` [elpa] externals/consult-recoll c5926ca3eb 1/2: format for size annotation Stefan Monnier
@ 2022-10-14  1:44     ` Visuwesh
  2022-10-14 19:15       ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Visuwesh @ 2022-10-14  1:44 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel, jao

[வியாழன் அக்டோபர் 13, 2022] Stefan Monnier wrote:

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

Don't we already have `file-size-human-readable' for that?

>         Stefan
>> +(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))))))
>> +



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [elpa] externals/consult-recoll c5926ca3eb 1/2: format for size annotation
  2022-10-14  1:44     ` Visuwesh
@ 2022-10-14 19:15       ` Stefan Monnier
  2022-10-14 20:04         ` jao
  2022-10-15  2:57         ` Stefan Kangas
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Monnier @ 2022-10-14 19:15 UTC (permalink / raw)
  To: Visuwesh; +Cc: emacs-devel, jao

Visuwesh [2022-10-14 07:14:02] wrote:
> [வியாழன் அக்டோபர் 13, 2022] Stefan Monnier wrote:
>> 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?
> Don't we already have `file-size-human-readable' for that?

Ah, that's it, thanks!
So Consult should simply use that instead of `consult-recoll--format-size`.


        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [elpa] externals/consult-recoll c5926ca3eb 1/2: format for size annotation
  2022-10-14 19:15       ` Stefan Monnier
@ 2022-10-14 20:04         ` jao
  2022-10-15  2:57         ` Stefan Kangas
  1 sibling, 0 replies; 5+ messages in thread
From: jao @ 2022-10-14 20:04 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Visuwesh, emacs-devel

On Fri, Oct 14 2022, Stefan Monnier wrote:

> Visuwesh [2022-10-14 07:14:02] wrote:
>> [வியாழன் அக்டோபர் 13, 2022] Stefan Monnier wrote:
>>> 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?
>> Don't we already have `file-size-human-readable' for that?
>
> Ah, that's it, thanks!
> So Consult should simply use that instead of `consult-recoll--format-size`.

indeed. done! many thanks both, i've been reinventing this wheel for a
while!!

jao
-- 
The miracle of the appropriateness of the language of mathematics for
the formulation of the laws of physics is a wonderful gift which we
neither understand nor deserve. - Eugene Wigner



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [elpa] externals/consult-recoll c5926ca3eb 1/2: format for size annotation
  2022-10-14 19:15       ` Stefan Monnier
  2022-10-14 20:04         ` jao
@ 2022-10-15  2:57         ` Stefan Kangas
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Kangas @ 2022-10-15  2:57 UTC (permalink / raw)
  To: Stefan Monnier, Visuwesh; +Cc: emacs-devel, jao

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> Visuwesh [2022-10-14 07:14:02] wrote:
>> [வியாழன் அக்டோபர் 13, 2022] Stefan Monnier wrote:
>>> 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?
>> Don't we already have `file-size-human-readable' for that?
>
> Ah, that's it, thanks!
> So Consult should simply use that instead of `consult-recoll--format-size`.

I changed `memory-report--format' to use `file-size-human-readable'
(commit 8300899953).



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-15  2:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <166569465562.12992.2240825905795534702@vcs2.savannah.gnu.org>
     [not found] ` <20221013205735.EF3DEC03F23@vcs2.savannah.gnu.org>
2022-10-13 22:08   ` [elpa] externals/consult-recoll c5926ca3eb 1/2: format for size annotation Stefan Monnier
2022-10-14  1:44     ` Visuwesh
2022-10-14 19:15       ` Stefan Monnier
2022-10-14 20:04         ` jao
2022-10-15  2:57         ` Stefan Kangas

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.