org-notify.el: Limit the number of notifications

(org-notify-max-notifications-per-run): New option for limiting the
notifications.
(org-notify-process): Use it.
This commit is contained in:
Peter Münster 2020-09-13 16:18:56 +02:00 committed by Bastien Guerry
parent 54bdd6cbf7
commit b01332c87e
1 changed files with 36 additions and 27 deletions

View File

@ -74,6 +74,11 @@
:type 'boolean
:group 'org-notify)
(defcustom org-notify-max-notifications-per-run 3
"Maximum number of notifications per run of `org-notify-process'."
:type 'integer
:group 'org-notify)
(defconst org-notify-actions
'("show" "show" "done" "done" "hour" "one hour later" "day" "one day later"
"week" "one week later")
@ -158,6 +163,7 @@ PERIOD."
(cl-defun org-notify-process ()
"Process the todo-list, and possibly notify user about upcoming or
forgotten tasks."
(let ((notification-cnt 0))
(cl-macrolet ((prm (k) `(plist-get prms ,k)) (td (k) `(plist-get todo ,k)))
(dolist (todo (org-notify-todo-list))
(let* ((deadline (td :deadline)) (heading (td :heading))
@ -179,12 +185,15 @@ forgotten tasks."
(ding))
(unless (listp actions)
(setq actions (list actions)))
(cl-incf notification-cnt)
(dolist (action actions)
(funcall (if (fboundp action) action
(intern (concat "org-notify-action"
(symbol-name action))))
plist))))
(cl-return)))))))
plist))
(when (>= notification-cnt org-notify-max-notifications-per-run)
(cl-return-from org-notify-process)))
(cl-return)))))))))
(defun org-notify-add (name &rest params)
"Add a new notification type.