1 ;;; timer-list.el --- list active timers in a buffer
3 ;; Copyright (C) 2016 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
8 ;; This file is part of GNU Emacs.
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.
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.
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/>.
28 (defun timer-list (&optional _ignore-auto _nonconfirm
)
29 "List all timers in a buffer."
31 (pop-to-buffer-same-window (get-buffer-create "*timer-list*"))
32 (let ((inhibit-read-only t
))
35 (dolist (timer (append timer-list timer-idle-list
))
36 (insert (format "%4s %10s %8s %s"
42 (let ((time (float-time (list (aref timer
1)
48 (- (float-time (list (aref timer
1)
53 (let ((repeat (aref timer
4)))
56 (format "%.2f" (/ repeat
60)))
60 (format "%s" repeat
))))
62 (let ((function (aref timer
5)))
63 (replace-regexp-in-string
66 ((byte-code-function-p function
)
67 (replace-regexp-in-string
69 (format "%s" function
)))
71 (format "%s" function
)))))))
72 (put-text-property (line-beginning-position)
73 (1+ (line-beginning-position))
76 (goto-char (point-min)))
77 ;; This command can be destructive if they don't know what they are
78 ;; doing. Kids, don't try this at home!
79 ;;;###autoload (put 'timer-list 'disabled "Beware: manually canceling timers can ruin your Emacs session.")
81 (defvar timer-list-mode-map
82 (let ((map (make-sparse-keymap)))
83 (define-key map
"c" 'timer-list-cancel
)
84 (easy-menu-define nil map
""
86 ["Cancel" timer-list-cancel t
]))
89 (define-derived-mode timer-list-mode special-mode
"timer-list"
90 "Mode for listing and controlling timers."
91 (setq truncate-lines t
)
93 (setq-local revert-buffer-function
'timer-list
)
94 (setq buffer-read-only t
)
95 (setq header-line-format
96 (format "%4s %10s %8s %s"
97 "Idle" "Next" "Repeat" "Function")))
99 (defun timer-list-cancel ()
100 "Cancel the timer on the line under point."
102 (let ((timer (get-text-property (line-beginning-position) 'timer
))
103 (inhibit-read-only t
))
105 (error "No timer on the current line"))
107 (delete-region (line-beginning-position)
108 (line-beginning-position 2))))
110 (provide 'timer-list
)
112 ;;; timer-list.el ends here