5

By customizing org-agenda-confirm-kill, I am able to get confirmation when I kill a task in an agenda view. I can set this to t to always ask for confirmation (which I don't want to do, because I usually just kill one off tasks instead of marking them DONE), or to a number n so that I have to confirm when a TODO spans n or more lines. I currently have this set as follows:

(setq org-agenda-confirm-kill 2) 

This will prevent me from accidentally removing a TODO with notes or other information that I am not seeing when in agenda view. However, I am also worried about accidentally deleting repeating tasks. Is there any way to get confirmation in the agenda views before killing repeating tasks?

1 Answer 1

4

Advise org-agenda-kill to check org-get-repeat and prompt if there is a repeater. Use a :before-while advice so that execution stops if the querying function returns false. Since we're doing this from the agenda we will first have to find and go to the actual location to check the repeater.

(defun org-agenda-repeating-p () (let ((pos (get-text-property 0 'org-marker (thing-at-point 'line)))) (save-window-excursion (org-goto-marker-or-bmk pos) (org-get-repeat)) )) (defun query-if-repeating (&rest args) (if (not (org-agenda-repeating-p)) t (y-or-n-p "Entry repeats. Kill?")) ) (advice-add 'org-agenda-kill :before-while 'query-if-repeating) 
6
  • This works great for TODOs with a repeater, but for some reason prevents me from killing any tasks without a repeater. Commented Nov 29, 2016 at 18:56
  • @elethan query-if-repeating needs to return t if the task isn't repeating, which it wasn't. I edited in a fix. Commented Nov 29, 2016 at 23:34
  • One more little hiccup...Now if I press "n" when prompted, it will still kill the line... Commented Nov 30, 2016 at 2:47
  • Fixed again. Try this version Commented Dec 1, 2016 at 0:18
  • That did it. Thanks for all the work! Commented Dec 1, 2016 at 2:28

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.