GNU bug report logs -
#78678
[PATCH v1] world-clock: Sort entries based on a user-provided function
Previous Next
Full log
Message #11 received at 78678 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hello,
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?).
Thank you!
--
Jacob S. Gordon
jacob.as.gordon <at> gmail.com
======================
Please avoid sending me HTML emails and MS Office documents.
https://useplaintext.email/#etiquette
https://www.gnu.org/philosophy/no-word-attachments.html
[v2-0001-world-clock-Add-user-option-to-control-entry-order.patch (text/x-patch, attachment)]
This bug report was last modified 1 day ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.