unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 1e1c22b8f7760f2ca6a308cba18c21b9f6eefec5 5438 bytes (raw)
name: lisp/emacs-lisp/timer-list.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
 
;;; timer-list.el --- list active timers in a buffer  -*- lexical-binding:t -*-

;; Copyright (C) 2016-2023 Free Software Foundation, Inc.

;; Maintainer: emacs-devel@gnu.org
;; Package: emacs

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

(require 'timer)

(defvar cl-print-compiled)
(defvar cl-print-compiled-button)

;;;###autoload
(defun list-timers (&optional _ignore-auto _nonconfirm)
  "List all timers in a buffer."
  (interactive)
  (pop-to-buffer-same-window (get-buffer-create "*timer-list*"))
  (timer-list-mode)
  (tabulated-list-init-header)
  (setq tabulated-list-entries
        (mapcar
         (lambda (timer)
           (list
            nil
            `[ ;; Idle.
              ,(propertize
                (if (timer--idle-delay timer) "   *" " ")
                'help-echo "* marks idle timers"
                'timer timer)
              ;; Next time.
              ,(propertize
                (let* ((time (timer--time timer))
                       (idle-p (timer--idle-delay timer))
                       (inverted-p (and (not idle-p)
                                        (time-less-p time nil)))
                       (formatted (format-seconds
                                   "%1dd %2hh %2mm %z%,1ss"
		                   (float-time
		                    (if idle-p
			                time
                                      (if inverted-p
                                          (time-subtract nil time)
			                (time-subtract time nil)))))))
                  (when (equal formatted "0.0s")
                    (setq inverted-p nil))
                  (format "%13s" (concat (if inverted-p "-" "") formatted)))
                'help-echo "Time until next invocation")
              ;; Repeat.
              ,(let ((repeat (timer--repeat-delay timer)))
                 (cond
                  ((numberp repeat)
                   (propertize
                    (format "%12s" (format-seconds
                                    "%x%dd %hh %mm %z%,1ss" repeat))
                    'help-echo "Repeat interval"))
                  ((null repeat)
                   (propertize "           -" 'help-echo "Runs once"))
                  (t
                   (format "%12s" repeat))))
              ;; Function.
              ,(propertize
                (let ((cl-print-compiled 'static)
                      (cl-print-compiled-button nil)
                      (print-escape-newlines t))
                  (cl-prin1-to-string (timer--function timer)))
                'help-echo "Function called by timer")]))
         (append timer-list timer-idle-list)))
  (tabulated-list-print))
;; This command can be destructive if they don't know what they are
;; doing.  Kids, don't try this at home!
;;;###autoload (put 'list-timers 'disabled "Beware: manually canceling timers can ruin your Emacs session.")

(defvar-keymap timer-list-mode-map
  "c" #'timer-list-cancel
  :menu
  '("Timers"
    ["Cancel" timer-list-cancel t]
    ["Quit" quit-window]))

(define-derived-mode timer-list-mode tabulated-list-mode "Timer-List"
  "Mode for listing and controlling timers."
  (buffer-disable-undo)
  (setq-local revert-buffer-function #'list-timers)
  (setq tabulated-list-format
        '[("Idle" 6 timer-list--idle-predicate)
          ("Next" 13 timer-list--next-predicate :right-align t :pad-right 1)
          ("Repeat" 12 timer-list--repeat-predicate :right-align t :pad-right 1)
          ("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 Function 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."
  (interactive)
  (let ((timer (get-text-property (line-beginning-position) 'timer))
        (inhibit-read-only t))
    (unless timer
      (error "No timer on the current line"))
    (cancel-timer timer)
    (delete-region (line-beginning-position)
                   (line-beginning-position 2))))

(provide 'timer-list)

;;; timer-list.el ends here

debug log:

solving 1e1c22b8f77 ...
found 1e1c22b8f77 in https://yhetil.org/emacs-bugs/87r0ugtdop.fsf@dick/
found b9a171adc07 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 b9a171adc07c99413b118b78149b9b43f8257d94	lisp/emacs-lisp/timer-list.el

applying [1/1] https://yhetil.org/emacs-bugs/87r0ugtdop.fsf@dick/
diff --git a/lisp/emacs-lisp/timer-list.el b/lisp/emacs-lisp/timer-list.el
index b9a171adc07..1e1c22b8f77 100644

Checking patch lisp/emacs-lisp/timer-list.el...
Applied patch lisp/emacs-lisp/timer-list.el cleanly.

index at:
100644 1e1c22b8f7760f2ca6a308cba18c21b9f6eefec5	lisp/emacs-lisp/timer-list.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).