From 0b8718ccef5017c1fbf6051bee2fabd6712afbe0 Mon Sep 17 00:00:00 2001 From: Boruch Baum Date: Sun, 4 Feb 2024 18:59:32 -0500 Subject: fix: sorting of numeric columns "Duration", "Views" --- yeetube.el | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/yeetube.el b/yeetube.el index 3bc992d..e29dc54 100644 --- a/yeetube.el +++ b/yeetube.el @@ -372,6 +372,7 @@ SUBSTRING-END is the end of the string to return, interger." :videoid videoid :view-count (yeetube-view-count-format view-count) :duration video-duration + :published-time published-time :channel channel :thumbnail thumbnail) yeetube-content)))))) @@ -494,10 +495,28 @@ FIELDS-FACE-PAIRS is a list of fields and faces." "C-q" #'yeetube-mpv-change-video-quality "q" #'quit-window) +(defun yeetube--sort-views (a b) + "PREDICATE for function 'sort'. +Used by variable 'tabulated-list-format' to sort the \"Views\" +column." + (< (string-to-number (replace-regexp-in-string "," "" (aref (cadr a) 1))) + (string-to-number (replace-regexp-in-string "," "" (aref (cadr b) 1))))) + +(defun yeetube--sort-duration (a b) + "PREDICATE for function 'sort'. +Used by variable 'tabulated-list-format' to sort the \"Duration\" +column." + (< (string-to-number (replace-regexp-in-string ":" "" (aref (cadr a) 2))) + (string-to-number (replace-regexp-in-string ":" "" (aref (cadr b) 2))))) + (define-derived-mode yeetube-mode tabulated-list-mode "Yeetube" "Yeetube mode." :keymap yeetube-mode-map - (setf tabulated-list-format [("Title" 60 t) ("Views" 12 t) ("Duration" 9 t) ("Channel" 12 t)] + (setf tabulated-list-format + [("Title" 60 t) + ("Views" 12 yeetube--sort-views) + ("Duration" 9 yeetube--sort-duration) + ("Channel" 12 t)] tabulated-list-entries (cl-map 'list (lambda (content) -- cgit v1.2.3