branch: externals/org-notify
commit 93345acfd576a5971b539e21e13959f81bc73afe
Author: Peter Münster <[email protected]>
Commit: Peter Münster <[email protected]>

    Add support for turning off uncritical notifications
---
 org-notify.el | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/org-notify.el b/org-notify.el
index 890be46d48..aefb186807 100644
--- a/org-notify.el
+++ b/org-notify.el
@@ -72,6 +72,8 @@
 
 ;;;;; Changes since 0.1.1:
 
+;; - Add support for turning off uncritical notifications.
+
 ;;;;; Changes since 0.1.0:
 
 ;; - Add support for SCHEDULED timestamps with new option
@@ -124,6 +126,19 @@
 (defvar org-notify-on-action-map nil
   "Mapping between on-action identifiers and parameter lists.")
 
+(defvar org-notify-only-critical nil
+  "Activate only critical notifications.")
+
+(defun org-notify-toggle-only-critical ()
+  "Toggle `org-notify-only-critical'."
+  (interactive)
+  (if org-notify-only-critical
+      (progn
+        (message "Turning on ALL notifications.")
+        (setq org-notify-only-critical nil))
+    (message "Turning on only CRITICAL notifications.")
+    (setq org-notify-only-critical t)))
+
 (defun org-notify-string->seconds (str)
   "Convert time string STR to number of seconds."
   (when str
@@ -190,6 +205,11 @@ PERIOD."
       (message "Warning: notification for \"%s\" behind schedule!" heading))
   t)
 
+(defun org-notify-urgent (urgency)
+  "Check if the notification has high enough urgency."
+  (or (null org-notify-only-critical)
+      (equal urgency 'critical)))
+
 (cl-defun org-notify-process ()
   "Process the todo-list, and possibly notify user about upcoming or
 forgotten tasks."
@@ -204,9 +224,12 @@ forgotten tasks."
               (let ((period (org-notify-string->seconds (prm :period)))
                     (last-run (prm last-run-sym))  (now (float-time))
                     (actions (prm :actions))       diff  plist)
-                (when (or (not last-run)
-                          (and period (< period (setq diff (- now last-run)))
-                               (org-notify-maybe-too-late diff period 
heading)))
+                (when (and
+                       (org-notify-urgent (prm :urgency))
+                       (or (not last-run)
+                           (and period (< period (setq diff (- now last-run)))
+                                (org-notify-maybe-too-late
+                                 diff period heading))))
                   (setq prms (plist-put prms last-run-sym now)
                         plist (append todo prms))
                   (if (if (plist-member prms :audible)

Reply via email to