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."
|
"Advice to run after the Org-capture template is placed."
|
||||||
(when (org-roam-capture--get :new-node-p)
|
(when (org-roam-capture--get :new-node-p)
|
||||||
(run-hooks 'org-roam-capture-new-node-hook))
|
(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 ()
|
(defun org-roam-capture--create-id-for-entry ()
|
||||||
"Create the ID for the new entry."
|
"Create the ID for the new entry."
|
||||||
|
@@ -177,7 +177,8 @@
|
|||||||
#'org-capture-place-template)
|
#'org-capture-place-template)
|
||||||
:to-be nil)))
|
:to-be nil)))
|
||||||
|
|
||||||
(it "org-roam-capture-run-new-node-hook-a runs hook when new node"
|
(describe "org-roam-capture-run-new-node-hook-a"
|
||||||
|
(it "runs hook when new node"
|
||||||
(let ((hook-ran nil))
|
(let ((hook-ran nil))
|
||||||
(cl-letf* (((symbol-function 'org-roam-capture--get)
|
(cl-letf* (((symbol-function 'org-roam-capture--get)
|
||||||
(lambda (prop)
|
(lambda (prop)
|
||||||
@@ -200,7 +201,30 @@
|
|||||||
|
|
||||||
;; Clean up
|
;; Clean up
|
||||||
(remove-hook 'org-roam-capture-new-node-hook
|
(remove-hook 'org-roam-capture-new-node-hook
|
||||||
(lambda () (setq hook-ran t)))))))
|
(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 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 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"
|
(describe "org-roam-capture target-entry-p detection"
|
||||||
(it "detects entry target for file+olp"
|
(it "detects entry target for file+olp"
|
||||||
|
Reference in New Issue
Block a user