aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2020-04-24 23:43:57 +0200
committerStefan Kangas2020-05-12 19:10:20 +0200
commite6837016b02b89a8f393003f85017ade048d8ab1 (patch)
tree4c9eb3f28737e853dca005b487a817d1a7ddf12b
parentee5c5daad5f8560d0107301b67b49daf7f523588 (diff)
downloademacs-e6837016b02b89a8f393003f85017ade048d8ab1.tar.gz
emacs-e6837016b02b89a8f393003f85017ade048d8ab1.zip
Support sorting timer-list-mode by column (Bug#40854)
* lisp/emacs-lisp/timer-list.el (timer-list-mode) (timer-list--idle-predicate, timer-list--next-predicate) (timer-list--repeat-predicate) (timer-list--function-predicate): Add support for sorting by column.
-rw-r--r--lisp/emacs-lisp/timer-list.el35
1 files changed, 31 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/timer-list.el b/lisp/emacs-lisp/timer-list.el
index 17e5eb05928..00d09696d2a 100644
--- a/lisp/emacs-lisp/timer-list.el
+++ b/lisp/emacs-lisp/timer-list.el
@@ -92,10 +92,37 @@
92 (buffer-disable-undo) 92 (buffer-disable-undo)
93 (setq-local revert-buffer-function #'list-timers) 93 (setq-local revert-buffer-function #'list-timers)
94 (setq tabulated-list-format 94 (setq tabulated-list-format
95 '[("Idle" 4) 95 '[("Idle" 6 timer-list--idle-predicate)
96 (" Next" 10) 96 (" Next" 12 timer-list--next-predicate)
97 (" Repeat" 8) 97 (" Repeat" 11 timer-list--repeat-predicate)
98 ("Function" 0)])) 98 ("Function" 10 timer-list--function-predicate)]))
99
100(defun timer-list--idle-predicate (A B)
101 "Predicate to sort Timer-List by the Idle column."
102 (let ((iA (aref (cadr A) 0))
103 (iB (aref (cadr B) 0)))
104 (cond ((string= iA iB)
105 (timer-list--next-predicate A B))
106 ((string= iA " *") nil)
107 (t t))))
108
109(defun timer-list--next-predicate (A B)
110 "Predicate to sort Timer-List by the Next column."
111 (let ((nA (string-to-number (aref (cadr A) 1)))
112 (nB (string-to-number (aref (cadr B) 1))))
113 (< nA nB)))
114
115(defun timer-list--repeat-predicate (A B)
116 "Predicate to sort Timer-List by the Repeat column."
117 (let ((rA (aref (cadr A) 2))
118 (rB (aref (cadr B) 2)))
119 (string< rA rB)))
120
121(defun timer-list--function-predicate (A B)
122 "Predicate to sort Timer-List by the Next column."
123 (let ((fA (aref (cadr A) 3))
124 (fB (aref (cadr B) 3)))
125 (string< fA fB)))
99 126
100(defun timer-list-cancel () 127(defun timer-list-cancel ()
101 "Cancel the timer on the line under point." 128 "Cancel the timer on the line under point."