[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tmr aaad527cf5 1/3: Fix sorting in tmr-tabulated
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tmr aaad527cf5 1/3: Fix sorting in tmr-tabulated |
Date: |
Tue, 28 Jun 2022 13:58:30 -0400 (EDT) |
branch: externals/tmr
commit aaad527cf51f4f72c78df456f910795b17f80d7c
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Fix sorting in tmr-tabulated
---
tmr-tabulated.el | 12 ++++++++----
tmr.el | 13 +++++--------
2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/tmr-tabulated.el b/tmr-tabulated.el
index 9566e11675..49fd2564df 100644
--- a/tmr-tabulated.el
+++ b/tmr-tabulated.el
@@ -92,9 +92,8 @@
;; Optimized refreshing
(dolist (entry tabulated-list-entries)
(setf (aref (cadr entry) 2)
(tmr--format-remaining (car entry))))
- (tabulated-list-print t t)
- (when end
- (goto-char (point-max))))
+ (tabulated-list-print t)
+ (when end (goto-char (point-max))))
;; HACK: For some reason the hl-line
highlighting gets lost here
(when (and (bound-and-true-p global-hl-line-mode)
(fboundp 'global-hl-line-highlight))
@@ -111,12 +110,17 @@
(cancel-timer tmr-tabulated--refresh-timer)
(setq tmr-tabulated--refresh-timer nil))))
+(defun tmr-tabulated--compare-remaining (a b)
+ "Compare remaining time of timers A and B."
+ (time-less-p (tmr--timer-end-date (car a))
+ (tmr--timer-end-date (car b))))
+
(define-derived-mode tmr-tabulated-mode tabulated-list-mode "TMR"
"Major mode to display tmr timers."
(setq-local tabulated-list-format
[("Start" 10 t)
("End" 10 t)
- ("Remaining" 10 t)
+ ("Remaining" 10 tmr-tabulated--compare-remaining)
("Description" 0 t)])
(add-hook 'window-configuration-change-hook #'tmr-tabulated--window-hook nil
t)
(add-hook 'tabulated-list-revert-hook #'tmr-tabulated--set-entries nil t)
diff --git a/tmr.el b/tmr.el
index b3ff0fafd5..c1ab8945f0 100644
--- a/tmr.el
+++ b/tmr.el
@@ -104,10 +104,10 @@ Each function must accept a timer as argument."
nil
:read-only t
:documentation "Time at which the timer was created.")
- (duration
+ (end-date
nil
:read-only t
- :documentation "Number of seconds after `start' indicating when the timer
finishes.")
+ :documentation "Time at which the timer finishes.")
(finishedp
nil
:read-only nil
@@ -183,8 +183,7 @@ original input for TIMER's duration."
(defun tmr--format-end-date (timer)
"Return a string representing when TIMER should finish."
- (tmr--format-time (time-add (tmr--timer-creation-date timer)
- (tmr--timer-duration timer))))
+ (tmr--format-time (tmr--timer-end-date timer)))
(defun tmr--format-remaining (timer &optional finished prefix)
"Format remaining time of TIMER.
@@ -193,9 +192,7 @@ PREFIX is used as prefix for running timers."
(setq prefix (or prefix ""))
(if (tmr--timer-finishedp timer)
(or finished "✔")
- (let ((secs (round (- (float-time
- (time-add (tmr--timer-creation-date timer)
- (tmr--timer-duration timer)))
+ (let ((secs (round (- (float-time (tmr--timer-end-date timer))
(float-time)))))
(if (> secs 3600)
(format "%s%sh %sm" prefix (/ secs 3600) (/ (% secs 3600) 60))
@@ -405,7 +402,7 @@ command `tmr-with-description' instead of this one."
(timer (tmr--timer-create
:description description
:creation-date creation-date
- :duration duration
+ :end-date (time-add creation-date duration)
:input time))
(timer-object (run-with-timer
duration nil