aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2016-02-09 13:36:15 +1100
committerLars Ingebrigtsen2016-02-09 13:36:15 +1100
commit54b198af77449135980ce36fcfb42a5eea18c5c4 (patch)
tree985a0691bd550eede3727386ff89ec568ef3e352
parentc93cc660ac85db9e7932ffae6bd886034defffba (diff)
downloademacs-54b198af77449135980ce36fcfb42a5eea18c5c4.tar.gz
emacs-54b198af77449135980ce36fcfb42a5eea18c5c4.zip
Add a mode to list and cancel timers
* doc/lispref/os.texi (Timers): Menton `timer-list'. * lisp/emacs-lisp/timer-list.el: New file.
-rw-r--r--doc/lispref/os.texi6
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/emacs-lisp/timer-list.el108
3 files changed, 118 insertions, 0 deletions
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi
index c5e3672a35a..d57cbcfeb94 100644
--- a/doc/lispref/os.texi
+++ b/doc/lispref/os.texi
@@ -1849,6 +1849,12 @@ one of these functions; the arrival of the specified time will not
1849cause anything special to happen. 1849cause anything special to happen.
1850@end defun 1850@end defun
1851 1851
1852@findex timer-list
1853The @code{timer-list} command lists all the currently active timers.
1854There's only one command available in the buffer displayed: @kbd{c}
1855(@code{timer-list-cancel}) that will cancel the timer on the line
1856under point.
1857
1852@node Idle Timers 1858@node Idle Timers
1853@section Idle Timers 1859@section Idle Timers
1854@cindex idle timers 1860@cindex idle timers
diff --git a/etc/NEWS b/etc/NEWS
index fd56f0c317a..bcb70d4aeed 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -269,6 +269,10 @@ puny.el library, so that one can visit web sites like
269** The new M-s M-w key binding uses eww to search the web for the 269** The new M-s M-w key binding uses eww to search the web for the
270text in the region. 270text in the region.
271 271
272+++
273** The new `timer-list' command lists all active timers in a buffer
274where you can cancel them with the `c' command.
275
272** M-x suggests shorthands and ignores obsolete commands for completion. 276** M-x suggests shorthands and ignores obsolete commands for completion.
273** x-select-enable-clipboard is renamed select-enable-clipboard. 277** x-select-enable-clipboard is renamed select-enable-clipboard.
274x-select-enable-primary and renamed select-enable-primary. 278x-select-enable-primary and renamed select-enable-primary.
diff --git a/lisp/emacs-lisp/timer-list.el b/lisp/emacs-lisp/timer-list.el
new file mode 100644
index 00000000000..b54902a45f8
--- /dev/null
+++ b/lisp/emacs-lisp/timer-list.el
@@ -0,0 +1,108 @@
1;;; timer-list.el --- list active timers in a buffer
2
3;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5;; Maintainer: emacs-devel@gnu.org
6;; Package: emacs
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software: you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23;;; Commentary:
24
25;;; Code:
26
27;;;###autoload
28(defun timer-list ()
29 "List all timers in a buffer."
30 (interactive)
31 (pop-to-buffer-same-window (get-buffer-create "*timer-list*"))
32 (let ((inhibit-read-only t))
33 (erase-buffer)
34 (timer-list-mode)
35 (dolist (timer (append timer-list timer-idle-list))
36 (insert (format "%4s %10s %8s %s"
37 ;; Idle.
38 (if (aref timer 7)
39 "*"
40 " ")
41 ;; Next time.
42 (let ((time (float-time (list (aref timer 1)
43 (aref timer 2)
44 (aref timer 3)))))
45 (format "%.2f"
46 (if (aref timer 7)
47 time
48 (- (float-time (list (aref timer 1)
49 (aref timer 2)
50 (aref timer 3)))
51 (float-time)))))
52 ;; Repeat.
53 (let ((repeat (aref timer 4)))
54 (cond
55 ((numberp repeat)
56 (format "%.2f" (/ repeat 60)))
57 ((null repeat)
58 "-")
59 (t
60 (format "%s" repeat))))
61 ;; Function.
62 (let ((function (aref timer 5)))
63 (replace-regexp-in-string
64 "\n" " "
65 (cond
66 ((byte-code-function-p function)
67 (replace-regexp-in-string
68 "[^-A-Za-z0-9 ]" ""
69 (format "%s" function)))
70 (t
71 (format "%s" function)))))))
72 (put-text-property (line-beginning-position)
73 (1+ (line-beginning-position))
74 'timer timer)
75 (insert "\n")))
76 (goto-char (point-min)))
77
78(defvar timer-list-mode-map
79 (let ((map (make-sparse-keymap)))
80 (define-key map "c" 'timer-list-cancel)
81 (easy-menu-define nil map ""
82 '("Timers"
83 ["Cancel" timer-list-cancel t]))
84 map))
85
86(define-derived-mode timer-list-mode special-mode "timer-list"
87 "Mode for listing and controlling timers."
88 (setq truncate-lines t)
89 (buffer-disable-undo)
90 (setq buffer-read-only t)
91 (setq header-line-format
92 (format "%4s %10s %8s %s"
93 "Idle" "Next" "Repeat" "Function")))
94
95(defun timer-list-cancel ()
96 "Cancel the timer on the line under point."
97 (interactive)
98 (let ((timer (get-text-property (line-beginning-position) 'timer))
99 (inhibit-read-only t))
100 (unless timer
101 (error "No timer on the current line"))
102 (cancel-timer timer)
103 (delete-region (line-beginning-position)
104 (line-beginning-position 2))))
105
106(provide 'timer-list)
107
108;;; timer-list.el ends here