mirror of
https://github.com/org-roam/org-roam
synced 2025-09-28 16:50:58 -05:00
fix(capture): self-remove org-roam-capture-run-new-node-hook-a advice
This was incorrectly removing advice that doesn't exist, leading to the
actual advice being perpetually added without removal.
Amend: ed94524964
This commit is contained in:
@@ -607,7 +607,7 @@ capture target."
|
||||
"Advice to run after the Org-capture template is placed."
|
||||
(when (org-roam-capture--get :new-node-p)
|
||||
(run-hooks 'org-roam-capture-new-node-hook))
|
||||
(advice-remove #'org-capture-place-template #'org-roam-capture--place-template-a))
|
||||
(advice-remove #'org-capture-place-template #'org-roam-capture-run-new-node-hook-a))
|
||||
|
||||
(defun org-roam-capture--create-id-for-entry ()
|
||||
"Create the ID for the new entry."
|
||||
|
@@ -177,30 +177,54 @@
|
||||
#'org-capture-place-template)
|
||||
:to-be nil)))
|
||||
|
||||
(it "org-roam-capture-run-new-node-hook-a runs hook when new node"
|
||||
(let ((hook-ran nil))
|
||||
(describe "org-roam-capture-run-new-node-hook-a"
|
||||
(it "runs hook when new node"
|
||||
(let ((hook-ran nil))
|
||||
(cl-letf* (((symbol-function 'org-roam-capture--get)
|
||||
(lambda (prop)
|
||||
(if (eq prop :new-node-p)
|
||||
t
|
||||
nil))))
|
||||
|
||||
;; Add test hook
|
||||
(add-hook 'org-roam-capture-new-node-hook
|
||||
(lambda () (setq hook-ran t)))
|
||||
|
||||
;; Add the advice
|
||||
(advice-add #'org-capture-place-template :after #'org-roam-capture-run-new-node-hook-a)
|
||||
|
||||
;; Call the function
|
||||
(org-roam-capture-run-new-node-hook-a nil)
|
||||
|
||||
;; Verify hook ran
|
||||
(expect hook-ran :to-be t)
|
||||
|
||||
;; Clean up
|
||||
(remove-hook 'org-roam-capture-new-node-hook
|
||||
(lambda () (setq hook-ran t))))))
|
||||
|
||||
(it "removes itself as advice after running"
|
||||
(cl-letf* (((symbol-function 'org-roam-capture--get)
|
||||
(lambda (prop)
|
||||
(if (eq prop :new-node-p)
|
||||
t
|
||||
nil))))
|
||||
|
||||
;; Add test hook
|
||||
(add-hook 'org-roam-capture-new-node-hook
|
||||
(lambda () (setq hook-ran t)))
|
||||
|
||||
;; Add the advice
|
||||
(advice-add #'org-capture-place-template :after #'org-roam-capture-run-new-node-hook-a)
|
||||
|
||||
;; Verify advice is added
|
||||
(expect (advice-member-p #'org-roam-capture-run-new-node-hook-a
|
||||
#'org-capture-place-template)
|
||||
:to-be-truthy)
|
||||
|
||||
;; Call the function
|
||||
(org-roam-capture-run-new-node-hook-a nil)
|
||||
|
||||
;; Verify hook ran
|
||||
(expect hook-ran :to-be t)
|
||||
|
||||
;; Clean up
|
||||
(remove-hook 'org-roam-capture-new-node-hook
|
||||
(lambda () (setq hook-ran t)))))))
|
||||
;; Verify advice was removed after running
|
||||
(expect (advice-member-p #'org-roam-capture-run-new-node-hook-a
|
||||
#'org-capture-place-template)
|
||||
:to-be nil)))))
|
||||
|
||||
(describe "org-roam-capture target-entry-p detection"
|
||||
(it "detects entry target for file+olp"
|
||||
|
Reference in New Issue
Block a user