2

I'm new to emacs and org-mode and this seems like it should be easy but I haven't been able to find an answer.

Let's say I'm typing a todo list in ~/my_todo.org and i type up something like this:

* item 1
* item 2
** item 2.1
** item 2.2
* item 3

and now I want to make all of them TODOs. I could move the cursor on to each line and do C-c C-t but then I have to do that a bunch of times. Is there a way to select all of the lines and apply something like C-c C-t to each one to get something like

* TODO item 1
* TODO item 2
** TODO item 2.1
** TODO item 2.2
* TODO item 3

in one fell swoop?

4
  • did you try macros? F3 C-c C-t C-n F4, then C-u 5 F5.
    – Hellseher
    Feb 1, 2018 at 21:42
  • Check out Magnar's multiple-cursors library and watch the Emacs Rocks video on that subject. It is a cannot-live-without library, in my opinion.
    – lawlist
    Feb 2, 2018 at 1:04
  • @Hellseher Thank you, i was not familiar with emacs macros. That sounds very promising
    – alfalfa
    Feb 2, 2018 at 2:49
  • @lawlist will do, thanks for the suggestion
    – alfalfa
    Feb 2, 2018 at 2:49

1 Answer 1

3

You can achieve this, with a caveat, by defining your own org function. Something like so:

(defun my/mark-todo-in-region ()
  (interactive)
  (let ((scope (if mark-active 'region 'tree))
        (state (org-fast-todo-selection)))
    (org-map-entries (lambda () (org-todo state)) nil scope)))

This has a few behaviors that are nice:

  1. It will prompt you for a TODO state to use, meaning it respects custom TODO keyword lists. (Also meaning you can mark the entire subtree with whatever state you're in the mood for.)
  2. If you select a region manually, everything in it gets marked with the TODO state you select.
  3. If you don't mark a region manually, it will operate on the subtree under point.

However: the caveat is, everything will be marked with the same keyword. This function is fairly naive -- pick one state, map entries, boom, done.

3
  • Thank you for this, I'll accept it as soon as I've had a chance to try it
    – alfalfa
    Feb 5, 2018 at 14:45
  • unfortunately this doesn't always work for nested TODOs. I think the top-level one is attempted to be updated first but can't because of its subitems.
    – xeruf
    Mar 30, 2021 at 18:13
  • fixed by letting (org-enforce-todo-dependencies nil) as well, see emacs.stackexchange.com/a/64212/30278
    – xeruf
    Mar 30, 2021 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.