From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SL1wB5w1Xl/vLwAA0tVLHw (envelope-from ) for ; Sun, 13 Sep 2020 15:07:08 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id KESwAZw1Xl+0UQAAB5/wlQ (envelope-from ) for ; Sun, 13 Sep 2020 15:07:08 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4F8B29404D7 for ; Sun, 13 Sep 2020 15:07:07 +0000 (UTC) Received: from localhost ([::1]:55232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHTar-0004WJ-Ky for larch@yhetil.org; Sun, 13 Sep 2020 11:07:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHTYw-0004W1-87 for emacs-orgmode@gnu.org; Sun, 13 Sep 2020 11:05:06 -0400 Received: from static.214.254.202.116.clients.your-server.de ([116.202.254.214]:39592 helo=ciao.gmane.io) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHTYu-00023p-2u for emacs-orgmode@gnu.org; Sun, 13 Sep 2020 11:05:05 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1kHTYr-0006MU-Q1 for emacs-orgmode@gnu.org; Sun, 13 Sep 2020 17:05:01 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: =?utf-8?Q?Peter_M=C3=BCnster?= Subject: [PATCH] patches for org-notify.el Date: Sun, 13 Sep 2020 17:03:12 +0200 Message-ID: <87sgbln2hb.fsf@a16n.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) Cancel-Lock: sha1:cP45WQ75Sgi/gGSE7LQnl0fmLe0= Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/13 09:46:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -0.51 X-TUID: CtgEj5a11xCX --=-=-= Content-Type: text/plain Hi, Please find attached 2 patches for org-notify.el. Kind regards, -- Peter --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-contrib-lisp-org-notify.el-use-cl-prefixed-functions.patch >From 9ffa89dc99bfe967d9c591948d84dddb2eccdc38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=BCnster?= 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-contrib-lisp-org-notify.el-org-notify-max-notificati.patch >From 54134c8d07bafee3d8fc7492658c3a1c067aea5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20M=C3=BCnster?= 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 --=-=-=--