GNU bug report logs - #78678
[PATCH v1] world-clock: Sort entries based on a user-provided function

Previous Next

Package: emacs;

Reported by: "Jacob S. Gordon" <jacob.as.gordon <at> gmail.com>

Date: Tue, 3 Jun 2025 06:32:06 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eli Zaretskii <eliz <at> gnu.org>
To: "Jacob S. Gordon" <jacob.as.gordon <at> gmail.com>
Cc: 78678 <at> debbugs.gnu.org
Subject: bug#78678: [PATCH v2] world-clock: Add user option to control order of entries
Date: Thu, 12 Jun 2025 10:16:29 +0300
> Date: Sun, 8 Jun 2025 23:54:06 -0400
> From: "Jacob S. Gordon" <jacob.as.gordon <at> gmail.com>
> Cc: 78678 <at> debbugs.gnu.org
> 
> On 2025-06-03 08:00, Eli Zaretskii wrote:
> > This requires users to be Lisp programmers.  If there are
> > reasonably-useful cases where a certain order would be desirable,
> > allowing users to customize a variable using symbol values makes the
> > feature much more friendly to users who are not programmers.  Would
> > it make sense to add a couple of such values?
> 
> I agree, and I think it does make sense. After trying a version with
> symbols for common use-cases, I think the most flexible option is to
> allow the user to provide a format for `format-time-string' to act as
> the sorting key. This is similar in complexity to the variable
> `world-clock-time-format', and some predefined values can be put in
> the `:type' block of the `defcustom':
> 
> #+begin_src emacs-lisp
> :type '(choice (const :tag "No sorting" nil)
>                (const :tag "Chronological order" "%FT%T")
>                (const :tag "Reverse chronological order" ("%FT%T" . t))
>                (const :tag "Time of day order" "%T")
>                (const :tag "Reverse time of day order" ("%T" . t))
>                (string :tag "Format string")
>                (cons :tag "Format string and reverse flag"
>                      (string :tag "Format string")
>                      (boolean :tag "Reverse"))
>                (function :tag "Sorting function")))
> #+end_src
> 
> Then, sorting can be switched based on the type in a helper function:
> 
> #+begin_quote
> (defun world-clock--sort-entries (tzlist time)
>   "Sort TZLIST according to `world-clock-sort-order' at a given TIME."
>   (pcase world-clock-sort-order
>     ((pred null) tzlist)
>     ((or (and (pred stringp) format)
>         `(,(and (pred stringp) format) .
>           ,(and (pred booleanp) reverse)))
>      (sort tzlist
>            :key (lambda (entry)
>                    (format-time-string format time (car entry)))
>            :reverse reverse))
>     ((pred functionp) (funcall world-clock-sort-order tzlist time))
>     (_ (error "Invalid `world-clock-sort-order': `%s'"
>               world-clock-sort-order))))
> #+end_quote
> 
> In terms of coding standards:
> 
> + I could do this without `pcase', if desired.
> + I can write unit tests if we’re okay with the idea.
> 
> > Please reformat the log message according to our conventions
> > (described in CONTRIBUTE).
> 
> Done in the updated patch (I think?).

Thanks, this version LGTM.

However, before we can accept this contribution, we need you to sign a
copyright-assignment agreement, given the size of this contribution.
If you are willing to do that, I will send you the form to fill and
the instructions to go with it, to start your assignment paperwork
rolling.




This bug report was last modified 34 days ago.

Previous Next


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