aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoruch Baum <[email protected]>2024-02-04 18:59:32 -0500
committerThanos Apollo <[email protected]>2024-02-10 10:50:07 +0200
commit0b8718ccef5017c1fbf6051bee2fabd6712afbe0 (patch)
tree4bfbfa5ce7ebc156644960b9a11fd909b9d9555e
parent87143791c21235b1bd674ef17f8affd77c3fbaa5 (diff)
fix: sorting of numeric columns "Duration", "Views"
-rw-r--r--yeetube.el21
1 files changed, 20 insertions, 1 deletions
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)