branch: externals/tmr commit fb57e9163f4697c68db16b34a8aff5e5b50b2af2 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Add tmr-confirm configuration option - I prefer uniform behavior for one and multiple timers, in particular if destructive operations are involved. - Setting tmr-confirm=t also helps Embark support if we use embark--restart. Without this setting if we we have two timers, invoke tmr-cancel, cancel the second via embark-act, then the restart of the command will also automatically cancel the second. - The alternative would be to not add such an option and remove the special handling for single timers. But I see that some users may prefer the behavior enabled by tmr-confirm=nil. --- tmr.el | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tmr.el b/tmr.el index 8b3167c26b..3a6cc87010 100644 --- a/tmr.el +++ b/tmr.el @@ -67,6 +67,12 @@ If nil, don't play any sound." file (const :tag "Off" nil))) +(defcustom tmr-confirm t + "Confirm timer operations. +If set to nil and if there is only a single timer, +the operation is performed without confirmation." + :type 'boolean) + (defcustom tmr-timer-created-functions (list #'tmr-print-message-for-created-timer) "Functions to execute when a timer is created. @@ -269,13 +275,12 @@ cancelling the original one." (format " (%s remaining)" (tmr--format-remaining timer)))) (defun tmr--read-timer (&optional active) - "Let the user choose a timer among all timers. -Return the selected timer. If there is a single timer, use that. -If there are multiple timers, prompt for one with completion. If -there are no timers, return nil. + "Let the user choose a timer among all (or ACTIVE) timers. -If optional ACTIVE is non-nil, limit the list of timers to those -that are still running." +Return the selected timer. If there is a single timer and +`tmr-confirm' is nil, use that. If there are multiple timers, +prompt for one with completion. If there are no timers, throw an +error." (or (run-hook-with-args-until-success 'tmr--read-timer-hook) (pcase @@ -283,7 +288,7 @@ that are still running." (seq-remove #'tmr--timer-finishedp tmr--timers) tmr--timers) ('nil (user-error "No timers available")) - (`(,timer) timer) + ((and `(,timer) (guard (not tmr-confirm))) timer) (timers (let* ((timer-list (mapcar (lambda (x)