What I need:
Using `org-capture-finalize` in `org-capture-mode` while having some certain text, example ("* TODO \n") exits without doing anything (similar to the functionality of `org-capture-kill`)
My progress:
(defun my-finalize-if-no-todo ()
(interactive)
(setq matches (count-matches "* TODO \n" 0))
(if (= matches 1)
(org-capture-kill) ;; Should be changed to function properly
nil
))
(add-hook 'org-capture-prepare-finalize-hook #'my-finalize-if-no-todo) ;; Is this the right hook to use?
Post notes:
I tried to figure out how `org-capture-kill` does it, and it seems that it sets `org-note-abort` to `t`, but I am not sure how to do that in a hook. I tried to use `setq` and `let`, but I didn't manage to make it work.
I am noob when it comes to Emacs and Emacs Lisp, so the answer might be simple.
EDIT: I found a hack to get the behavior that I wanted.
;; Don't capture empty TODO tasks
(defun my-finalize-if-no-todo ()
(interactive)
(setq matches (count-matches "* TODO \n" 0))
(if (= matches 1)
(setq org-note-abort t)
nil
))
(defun my-finalize-reset-abort ()
(interactive)
(setq org-note-abort nil))
(add-hook 'org-capture-prepare-finalize-hook #'my-finalize-if-no-todo)
(add-hook 'org-capture-after-finalize-hook #'my-finalize-reset-abort)
The hook post finalization is needed, otherwise every capture afterwards won't work.