emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] patches for org-notify.el
@ 2020-09-13 15:03 Peter Münster
  2020-09-13 16:43 ` Bastien
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Münster @ 2020-09-13 15:03 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 91 bytes --]

Hi,

Please find attached 2 patches for org-notify.el.

Kind regards,
-- 
           Peter

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-contrib-lisp-org-notify.el-use-cl-prefixed-functions.patch --]
[-- Type: text/x-patch, Size: 1991 bytes --]

From 9ffa89dc99bfe967d9c591948d84dddb2eccdc38 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Sun, 13 Sep 2020 15:44:00 +0200
Subject: [PATCH 1/2] org-notify.el: Use cl- prefixed functions, and require cl-lib

---
 contrib/lisp/org-notify.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/contrib/lisp/org-notify.el b/contrib/lisp/org-notify.el
index 9f8677871..56d565c74 100644
--- a/contrib/lisp/org-notify.el
+++ b/contrib/lisp/org-notify.el
@@ -57,7 +57,7 @@
 
 ;;; Code:
 
-(eval-when-compile (require 'cl))
+(eval-when-compile (require 'cl-lib))
 (require 'org-element)
 
 (declare-function appt-delete-window    "appt"          ())
@@ -155,7 +155,7 @@ PERIOD."
       (message "Warning: notification for \"%s\" behind schedule!" heading))
   t)
 
-(defun org-notify-process ()
+(cl-defun org-notify-process ()
   "Process the todo-list, and possibly notify user about upcoming or
 forgotten tasks."
   (cl-macrolet ((prm (k) `(plist-get prms ,k))  (td (k) `(plist-get todo ,k)))
@@ -163,7 +163,7 @@ forgotten tasks."
       (let* ((deadline (td :deadline))  (heading (td :heading))
              (uid (td :uid))            (last-run-sym
                                          (intern (concat ":last-run-" uid))))
-        (dolist (prms (plist-get org-notify-map (td :notify)))
+        (cl-dolist (prms (plist-get org-notify-map (td :notify)))
           (when (< deadline (org-notify-string->seconds (prm :time)))
             (let ((period (org-notify-string->seconds (prm :period)))
                   (last-run (prm last-run-sym))  (now (float-time))
@@ -184,7 +184,7 @@ forgotten tasks."
                              (intern (concat "org-notify-action"
                                              (symbol-name action))))
                            plist))))
-            (return)))))))
+            (cl-return)))))))
 
 (defun org-notify-add (name &rest params)
   "Add a new notification type.
-- 
2.26.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-contrib-lisp-org-notify.el-org-notify-max-notificati.patch --]
[-- Type: text/x-patch, Size: 4524 bytes --]

From 54134c8d07bafee3d8fc7492658c3a1c067aea5d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Peter=20M=C3=BCnster?= <pm@a16n.net>
Date: Sun, 13 Sep 2020 16:18:56 +0200
Subject: [PATCH 2/2] 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.

---
 contrib/lisp/org-notify.el | 63 ++++++++++++++++++++++----------------
 1 file changed, 36 insertions(+), 27 deletions(-)

diff --git a/contrib/lisp/org-notify.el b/contrib/lisp/org-notify.el





diff --git a/contrib/lisp/org-notify.el b/contrib/lisp/org-notify.el
index 56d565c74..7f610a0df 100644
--- a/contrib/lisp/org-notify.el
+++ b/contrib/lisp/org-notify.el
@@ -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,33 +163,37 @@ PERIOD."
 (cl-defun org-notify-process ()
   "Process the todo-list, and possibly notify user about upcoming or
 forgotten tasks."
-  (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))
-             (uid (td :uid))            (last-run-sym
-                                         (intern (concat ":last-run-" uid))))
-        (cl-dolist (prms (plist-get org-notify-map (td :notify)))
-          (when (< deadline (org-notify-string->seconds (prm :time)))
-            (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)))
-                (setq prms (plist-put prms last-run-sym now)
-                      plist (append todo prms))
-                (if (if (plist-member prms :audible)
-                        (prm :audible)
-                      org-notify-audible)
-                    (ding))
-                (unless (listp actions)
-                  (setq actions (list actions)))
-                (dolist (action actions)
-                  (funcall (if (fboundp action) action
-                             (intern (concat "org-notify-action"
-                                             (symbol-name action))))
-                           plist))))
-            (cl-return)))))))
+  (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))
+               (uid (td :uid))            (last-run-sym
+                                           (intern (concat ":last-run-" uid))))
+          (cl-dolist (prms (plist-get org-notify-map (td :notify)))
+            (when (< deadline (org-notify-string->seconds (prm :time)))
+              (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)))
+                  (setq prms (plist-put prms last-run-sym now)
+			plist (append todo prms))
+                  (if (if (plist-member prms :audible)
+                          (prm :audible)
+			org-notify-audible)
+                      (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))
+		  (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.
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] patches for org-notify.el
  2020-09-13 15:03 [PATCH] patches for org-notify.el Peter Münster
@ 2020-09-13 16:43 ` Bastien
  2020-09-13 19:33   ` Peter Münster
  0 siblings, 1 reply; 3+ messages in thread
From: Bastien @ 2020-09-13 16:43 UTC (permalink / raw)
  To: Peter Münster; +Cc: emacs-orgmode

Hi Peter,

Peter Münster <pm@a16n.net> writes:

> Please find attached 2 patches for org-notify.el.

applied, thanks.

Note that after 9.4, we will trim Org's repository off of code that
currently lives in contrib/, so you may want to think about a place
where you want to host org-notify.el for the future.

We are not there yet, but let's think about it.

Thanks,

-- 
 Bastien


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] patches for org-notify.el
  2020-09-13 16:43 ` Bastien
@ 2020-09-13 19:33   ` Peter Münster
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Münster @ 2020-09-13 19:33 UTC (permalink / raw)
  To: emacs-orgmode

On Sun, Sep 13 2020, Bastien wrote:

> you may want to think about a place where you want to host
> org-notify.el for the future.

code.orgmode.org or github.com, as you prefer.

Kind regards,
-- 
           Peter



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-13 19:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-13 15:03 [PATCH] patches for org-notify.el Peter Münster
2020-09-13 16:43 ` Bastien
2020-09-13 19:33   ` Peter Münster

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

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).