summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorStefan Kangas <stefankangas@gmail.com>2020-04-24 23:43:57 +0200
committerStefan Kangas <stefankangas@gmail.com>2020-05-12 19:10:20 +0200
commite6837016b02b89a8f393003f85017ade048d8ab1 (patch)
tree4c9eb3f28737e853dca005b487a817d1a7ddf12b /lisp/emacs-lisp
parentee5c5daad5f8560d0107301b67b49daf7f523588 (diff)
downloademacs-e6837016b02b89a8f393003f85017ade048d8ab1.tar.gz
emacs-e6837016b02b89a8f393003f85017ade048d8ab1.tar.bz2
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.
Diffstat (limited to 'lisp/emacs-lisp')
-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 @@
(buffer-disable-undo)
(setq-local revert-buffer-function #'list-timers)
(setq tabulated-list-format
- '[("Idle" 4)
- (" Next" 10)
- (" Repeat" 8)
- ("Function" 0)]))
+ '[("Idle" 6 timer-list--idle-predicate)
+ (" Next" 12 timer-list--next-predicate)
+ (" Repeat" 11 timer-list--repeat-predicate)
+ ("Function" 10 timer-list--function-predicate)]))
+
+(defun timer-list--idle-predicate (A B)
+ "Predicate to sort Timer-List by the Idle column."
+ (let ((iA (aref (cadr A) 0))
+ (iB (aref (cadr B) 0)))
+ (cond ((string= iA iB)
+ (timer-list--next-predicate A B))
+ ((string= iA " *") nil)
+ (t t))))
+
+(defun timer-list--next-predicate (A B)
+ "Predicate to sort Timer-List by the Next column."
+ (let ((nA (string-to-number (aref (cadr A) 1)))
+ (nB (string-to-number (aref (cadr B) 1))))
+ (< nA nB)))
+
+(defun timer-list--repeat-predicate (A B)
+ "Predicate to sort Timer-List by the Repeat column."
+ (let ((rA (aref (cadr A) 2))
+ (rB (aref (cadr B) 2)))
+ (string< rA rB)))
+
+(defun timer-list--function-predicate (A B)
+ "Predicate to sort Timer-List by the Next column."
+ (let ((fA (aref (cadr A) 3))
+ (fB (aref (cadr B) 3)))
+ (string< fA fB)))
(defun timer-list-cancel ()
"Cancel the timer on the line under point."