~bzg/dev

org-contrib: Fix org-expiry inadvertent side-effect when loaded v1 PROPOSED

Aaron L. Zeng: 2
 lisp/org-expiry.el: Do not activate advice when feature is loaded
 lisp/org-expiry.el: Respect org-expiry-advised-functions defcustom

 2 files changed, 13 insertions(+), 21 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~bzg/dev/patches/55677/mbox | git am -3
Learn more about email & git

[PATCH org-contrib 1/2] lisp/org-expiry.el: Do not activate advice when feature is loaded Export this patch

define-advice, unlike defadvice, enables the advice immediately when
it is defined, but org-expiry's advice should not be enabled until
org-expiry-insinuate is called.

Rather than defining three separate advice functions, define a single
advice that can be added to each advised function.

This commit also fixes org-expiry-insinuate to use the new advice
mechanism.
---
 lisp/org-expiry.el | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/lisp/org-expiry.el b/lisp/org-expiry.el
index 61d061b..032f489 100644
--- a/lisp/org-expiry.el
+++ b/lisp/org-expiry.el
@@ -159,16 +159,10 @@ functions.  `org-expiry-deinsinuate' will deactivate them."

;;; Advices and insinuation:

(define-advice org-schedule (:after (&rest _) org-schedule-update-created)
  "Update the creation-date property when calling `org-schedule'."
  (org-expiry-insert-created))
(defun org-expiry--update-created (&rest _)
  "Update the creation-date property for the current heading.

(define-advice org-deadline (:after (&rest _) org-deadline-update-created)
  "Update the creation-date property when calling `org-deadline'."
  (org-expiry-insert-created))

(define-advice org-time-stamp (:after (&rest _) org-time-stamp-update-created)
  "Update the creation-date property when calling `org-time-stamp'."
Used as an :after advice."
  (org-expiry-insert-created))

(defun org-expiry-insinuate (&optional arg)
@@ -176,9 +170,9 @@ functions.  `org-expiry-deinsinuate' will deactivate them."
If ARG, also add a hook to `before-save-hook' in `org-mode' and
restart `org-mode' if necessary."
  (interactive "P")
  (ad-activate 'org-schedule)
  (ad-activate 'org-time-stamp)
  (ad-activate 'org-deadline)
  (advice-add 'org-schedule :after #'org-expiry--update-created)
  (advice-add 'org-time-stamp :after #'org-expiry--update-created)
  (advice-add 'org-deadline :after #'org-expiry--update-created)
  (add-hook 'org-insert-heading-hook 'org-expiry-insert-created)
  (add-hook 'org-after-todo-state-change-hook 'org-expiry-insert-created)
  (add-hook 'org-after-tags-change-hook 'org-expiry-insert-created)
@@ -197,9 +191,9 @@ restart `org-mode' if necessary."
If ARG, also remove org-expiry hook in Org's `before-save-hook'
and restart `org-mode' if necessary."
  (interactive "P")
  (advice-remove 'org-schedule #'org-schedule@org-schedule-update-created)
  (advice-remove 'org-time-stamp #'org-time-stamp@org-time-stamp-update-created)
  (advice-remove 'org-deadline #'org-deadline@org-deadline-update-created)
  (advice-remove 'org-schedule #'org-expiry--update-created)
  (advice-remove 'org-time-stamp #'org-expiry--update-created)
  (advice-remove 'org-deadline #'org-expiry--update-created)
  (remove-hook 'org-insert-heading-hook 'org-expiry-insert-created)
  (remove-hook 'org-after-todo-state-change-hook 'org-expiry-insert-created)
  (remove-hook 'org-after-tags-change-hook 'org-expiry-insert-created)
-- 
2.44.1

[PATCH org-contrib 2/2] lisp/org-expiry.el: Respect org-expiry-advised-functions defcustom Export this patch

---
 lisp/org-expiry.el | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/lisp/org-expiry.el b/lisp/org-expiry.el
index 032f489..c3bd323 100644
--- a/lisp/org-expiry.el
+++ b/lisp/org-expiry.el
@@ -170,9 +170,8 @@ Used as an :after advice."
If ARG, also add a hook to `before-save-hook' in `org-mode' and
restart `org-mode' if necessary."
  (interactive "P")
  (advice-add 'org-schedule :after #'org-expiry--update-created)
  (advice-add 'org-time-stamp :after #'org-expiry--update-created)
  (advice-add 'org-deadline :after #'org-expiry--update-created)
  (dolist (f org-expiry-advised-functions)
    (advice-add f :after #'org-expiry--update-created))
  (add-hook 'org-insert-heading-hook 'org-expiry-insert-created)
  (add-hook 'org-after-todo-state-change-hook 'org-expiry-insert-created)
  (add-hook 'org-after-tags-change-hook 'org-expiry-insert-created)
@@ -191,9 +190,8 @@ restart `org-mode' if necessary."
If ARG, also remove org-expiry hook in Org's `before-save-hook'
and restart `org-mode' if necessary."
  (interactive "P")
  (advice-remove 'org-schedule #'org-expiry--update-created)
  (advice-remove 'org-time-stamp #'org-expiry--update-created)
  (advice-remove 'org-deadline #'org-expiry--update-created)
  (dolist (f org-expiry-advised-functions)
    (advice-remove f #'org-expiry--update-created))
  (remove-hook 'org-insert-heading-hook 'org-expiry-insert-created)
  (remove-hook 'org-after-todo-state-change-hook 'org-expiry-insert-created)
  (remove-hook 'org-after-tags-change-hook 'org-expiry-insert-created)
-- 
2.44.1