aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2020-04-24 23:42:37 +0200
committerStefan Kangas2020-05-12 19:10:03 +0200
commitee5c5daad5f8560d0107301b67b49daf7f523588 (patch)
tree22bf27d86a9febf9fc38e1fb145f0bccd8d247b9
parenta2792ad54c310fdfabc8a9a8cf5bdf6c98a8ed20 (diff)
downloademacs-ee5c5daad5f8560d0107301b67b49daf7f523588.tar.gz
emacs-ee5c5daad5f8560d0107301b67b49daf7f523588.zip
Base timer-list-mode on tabulated-list-mode (Bug#40854)
* lisp/emacs-lisp/timer-list.el (list-timers) (timer-list-mode): Inherit from 'tabulated-list-mode' instead of 'special-mode' and make the necessary changes to support that. * doc/lispref/os.texi (Timers): Update documentation.
-rw-r--r--doc/lispref/os.texi6
-rw-r--r--lisp/emacs-lisp/timer-list.el105
2 files changed, 52 insertions, 59 deletions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index 5c0b1e2edf0..8bf48b1dbba 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -2182,9 +2182,9 @@ cause anything special to happen.
2182 2182
2183@findex list-timers 2183@findex list-timers
2184The @code{list-timers} command lists all the currently active timers. 2184The @code{list-timers} command lists all the currently active timers.
2185There's only one command available in the buffer displayed: @kbd{c} 2185The command @kbd{c} (@code{timer-list-cancel}) will cancel the timer
2186(@code{timer-list-cancel}) that will cancel the timer on the line 2186on the line under point. You can sort the list by column using the
2187under point. 2187command @kbd{S} (@code{tabulated-list-sort}).
2188 2188
2189@node Idle Timers 2189@node Idle Timers
2190@section Idle Timers 2190@section Idle Timers
diff --git a/lisp/emacs-lisp/timer-list.el b/lisp/emacs-lisp/timer-list.el
index 4cebd739c3b..17e5eb05928 100644
--- a/lisp/emacs-lisp/timer-list.el
+++ b/lisp/emacs-lisp/timer-list.el
@@ -32,41 +32,49 @@
32 "List all timers in a buffer." 32 "List all timers in a buffer."
33 (interactive) 33 (interactive)
34 (pop-to-buffer-same-window (get-buffer-create "*timer-list*")) 34 (pop-to-buffer-same-window (get-buffer-create "*timer-list*"))
35 (let ((inhibit-read-only t)) 35 (timer-list-mode)
36 (erase-buffer) 36 (tabulated-list-init-header)
37 (timer-list-mode) 37 (setq tabulated-list-entries
38 (dolist (timer (append timer-list timer-idle-list)) 38 (mapcar
39 (insert (format "%4s %10s %8s %s" 39 (lambda (timer)
40 ;; Idle. 40 (list
41 (if (aref timer 7) "*" " ") 41 nil
42 ;; Next time. 42 `[ ;; Idle.
43 (let ((time (list (aref timer 1) 43 ,(propertize
44 (aref timer 2) 44 (if (aref timer 7) " *" " ")
45 (aref timer 3)))) 45 'help-echo "* marks idle timers"
46 (format "%.2f" 46 'timer timer)
47 (float-time 47 ;; Next time.
48 (if (aref timer 7) 48 ,(propertize
49 time 49 (let ((time (list (aref timer 1)
50 (time-subtract time nil))))) 50 (aref timer 2)
51 ;; Repeat. 51 (aref timer 3))))
52 (let ((repeat (aref timer 4))) 52 (format "%10.2f"
53 (cond 53 (float-time
54 ((numberp repeat) 54 (if (aref timer 7)
55 (format "%.1f" repeat)) 55 time
56 ((null repeat) 56 (time-subtract time nil)))))
57 "-") 57 'help-echo "Time in sec till next invocation")
58 (t 58 ;; Repeat.
59 (format "%s" repeat)))) 59 ,(propertize
60 ;; Function. 60 (let ((repeat (aref timer 4)))
61 (let ((cl-print-compiled 'static) 61 (cond
62 (cl-print-compiled-button nil) 62 ((numberp repeat)
63 (print-escape-newlines t)) 63 (format "%8.1f" repeat))
64 (cl-prin1-to-string (aref timer 5))))) 64 ((null repeat)
65 (put-text-property (line-beginning-position) 65 " -")
66 (1+ (line-beginning-position)) 66 (t
67 'timer timer) 67 (format "%8s" repeat))))
68 (insert "\n"))) 68 'help-echo "Symbol: repeat; number: repeat interval in sec")
69 (goto-char (point-min))) 69 ;; Function.
70 ,(propertize
71 (let ((cl-print-compiled 'static)
72 (cl-print-compiled-button nil)
73 (print-escape-newlines t))
74 (cl-prin1-to-string (aref timer 5)))
75 'help-echo "Function called by timer")]))
76 (append timer-list timer-idle-list)))
77 (tabulated-list-print))
70;; This command can be destructive if they don't know what they are 78;; This command can be destructive if they don't know what they are
71;; doing. Kids, don't try this at home! 79;; doing. Kids, don't try this at home!
72;;;###autoload (put 'list-timers 'disabled "Beware: manually canceling timers can ruin your Emacs session.") 80;;;###autoload (put 'list-timers 'disabled "Beware: manually canceling timers can ruin your Emacs session.")
@@ -74,35 +82,20 @@
74(defvar timer-list-mode-map 82(defvar timer-list-mode-map
75 (let ((map (make-sparse-keymap))) 83 (let ((map (make-sparse-keymap)))
76 (define-key map "c" 'timer-list-cancel) 84 (define-key map "c" 'timer-list-cancel)
77 (define-key map "n" 'next-line)
78 (define-key map "p" 'previous-line)
79 (easy-menu-define nil map "" 85 (easy-menu-define nil map ""
80 '("Timers" 86 '("Timers"
81 ["Cancel" timer-list-cancel t])) 87 ["Cancel" timer-list-cancel t]))
82 map)) 88 map))
83 89
84(define-derived-mode timer-list-mode special-mode "Timer-List" 90(define-derived-mode timer-list-mode tabulated-list-mode "Timer-List"
85 "Mode for listing and controlling timers." 91 "Mode for listing and controlling timers."
86 (setq bidi-paragraph-direction 'left-to-right)
87 (setq truncate-lines t)
88 (buffer-disable-undo) 92 (buffer-disable-undo)
89 (setq-local revert-buffer-function #'list-timers) 93 (setq-local revert-buffer-function #'list-timers)
90 (setq buffer-read-only t) 94 (setq tabulated-list-format
91 (setq header-line-format 95 '[("Idle" 4)
92 (concat (propertize " " 'display '(space :align-to 0)) 96 (" Next" 10)
93 (format "%4s %10s %8s %s" 97 (" Repeat" 8)
94 (propertize "Idle" 98 ("Function" 0)]))
95 'mouse-face 'highlight
96 'help-echo "* marks idle timers")
97 (propertize "Next"
98 'mouse-face 'highlight
99 'help-echo "Time in sec till next invocation")
100 (propertize "Repeat"
101 'mouse-face 'highlight
102 'help-echo "Symbol: repeat; number: repeat interval in sec")
103 (propertize "Function"
104 'mouse-face 'highlight
105 'help-echo "Function called by timer")))))
106 99
107(defun timer-list-cancel () 100(defun timer-list-cancel ()
108 "Cancel the timer on the line under point." 101 "Cancel the timer on the line under point."