emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/tmr e18496d187 07/14: Add tmr--update-hook


From: ELPA Syncer
Subject: [elpa] externals/tmr e18496d187 07/14: Add tmr--update-hook
Date: Mon, 27 Jun 2022 12:58:04 -0400 (EDT)

branch: externals/tmr
commit e18496d187894a0aae4498da09beb2bc9bd2fc30
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Protesilaos Stavrou <info@protesilaos.com>

    Add tmr--update-hook
    
    This hook should be called always when tmr--timers or
    any timer changes.
---
 tmr-tabulated.el |  8 +++-----
 tmr.el           | 10 ++++++++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/tmr-tabulated.el b/tmr-tabulated.el
index 2c07298a03..35d9254ab0 100644
--- a/tmr-tabulated.el
+++ b/tmr-tabulated.el
@@ -115,7 +115,7 @@ prompt for a duration."
     (tmr-tabulated--get-timer-at-point)
     (tmr--description-prompt)))
   (setf (tmr--timer-description timer) description)
-  (revert-buffer))
+  (run-hooks 'tmr--update-hook))
 
 (defun tmr-tabulated--move-point-to-closest-entry ()
   "Move the point to the next entry if there is one or to the previous one.
@@ -145,15 +145,13 @@ Point isn't moved if point is on the only entry."
   "Return the timer on the current line or nil."
   (tmr--get-timer-by-creation-date (tabulated-list-get-id)))
 
-(defun tmr-tabulated--refresh (_timer)
+(defun tmr-tabulated--refresh ()
   "Refresh *tmr-tabulated-view* buffer if it exists."
   (when-let (buf (get-buffer "*tmr-tabulated-view*"))
     (with-current-buffer buf
       (revert-buffer))))
 
-(add-hook 'tmr-timer-completed-functions #'tmr-tabulated--refresh)
-(add-hook 'tmr-timer-created-functions #'tmr-tabulated--refresh)
-(add-hook 'tmr-timer-cancelled-functions #'tmr-tabulated--refresh)
+(add-hook 'tmr--update-hook #'tmr-tabulated--refresh)
 
 (provide 'tmr-tabulated)
 ;;; tmr-tabulated.el ends here
diff --git a/tmr.el b/tmr.el
index 23bd4d60de..b6ec15e746 100644
--- a/tmr.el
+++ b/tmr.el
@@ -190,6 +190,9 @@ original input for TIMER's duration."
   "List of timer objects.
 Populated by `tmr' and then operated on by `tmr-cancel'.")
 
+(defvar tmr--update-hook nil
+  "Hooks to execute when timers are changed.")
+
 (defun tmr--active-timers ()
   "Retun list of active timers."
   (cl-remove-if
@@ -215,13 +218,14 @@ With optional NO-HOOKS refrain from calling
     (cancel-timer (tmr--timer-timer-object timer))
     (setq tmr--timers (delete timer tmr--timers))
     (unless no-hooks
+      (run-hooks 'tmr--update-hook)
       (run-hook-with-args 'tmr-timer-cancelled-functions timer))))
 
 (defun tmr-remove-finished ()
   "Remove all finished timers."
   (interactive)
-  ;; TODO call tabulated refresh
-  (setq tmr--timers (cl-delete-if #'tmr--timer-donep tmr--timers)))
+  (setq tmr--timers (cl-delete-if #'tmr--timer-donep tmr--timers))
+  (run-hooks 'tmr--update-hook))
 
 (defun tmr--read-timer (&optional active description)
   "Let the user choose a timer among all timers.
@@ -308,6 +312,7 @@ If optional DEFAULT is provided use it as a default 
candidate."
 (defun tmr--complete (timer)
   "Mark TIMER as completed and execute `tmr-timer-completed-functions'."
   (setf (tmr--timer-donep timer) t)
+  (run-hooks 'tmr--update-hook)
   (run-hook-with-args 'tmr-timer-completed-functions timer))
 
 ;;;###autoload
@@ -345,6 +350,7 @@ command `tmr-with-description' instead of this one."
                         #'tmr--complete timer)))
     (setf (tmr--timer-timer-object timer) timer-object)
     (push timer tmr--timers)
+    (run-hooks 'tmr--update-hook)
     (run-hook-with-args 'tmr-timer-created-functions timer)))
 
 ;;;###autoload



reply via email to

[Prev in Thread] Current Thread [Next in Thread]