~bzg/dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 2

[PATCH org-contrib] Fix org-expiry inadvertent side-effect when loaded

Aaron L. Zeng <me@bcc32.com>
Details
Message ID
<20241029052437.242454-2-me@bcc32.com>
DKIM signature
pass
Download raw message
These patches fix a bug whereby *loading* org-expiry has an unintended
side-effect (its advice on org-schedule and similar commands is activated).
Normally org-expiry-insinuate must be called before loading the file will have
any effect, but the refactor 2a77f1d changed to use define-advice, which
activates the advice immediately (unlike defadvice).

I also saw a bug where the value of org-expiry-advised-functions was not used,
so I decided to fix it as well.

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

Aaron L. Zeng <me@bcc32.com>
Details
Message ID
<20241029052437.242454-3-me@bcc32.com>
In-Reply-To
<20241029052437.242454-2-me@bcc32.com> (view parent)
DKIM signature
pass
Download raw message
Patch: +9 -15
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

Aaron L. Zeng <me@bcc32.com>
Details
Message ID
<20241029052437.242454-4-me@bcc32.com>
In-Reply-To
<20241029052437.242454-2-me@bcc32.com> (view parent)
DKIM signature
pass
Download raw message
Patch: +4 -6
---
 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
Details
Message ID
<87ed3zfnjw.fsf@bzg.fr>
In-Reply-To
<20241029052437.242454-2-me@bcc32.com> (view parent)
DKIM signature
pass
Download raw message
Hi Aaron,

I applied the patches, thank you!

-- 
 Bastien Guerry
Reply to thread Export thread (mbox)