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?

  • did you try macros? F3 C-c C-t C-n F4, then C-u 5 F5. – Hellseher Feb 1 '18 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 '18 at 1:04
  • @Hellseher Thank you, i was not familiar with emacs macros. That sounds very promising – alfalfa Feb 2 '18 at 2:49
  • @lawlist will do, thanks for the suggestion – alfalfa Feb 2 '18 at 2:49

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

(defun my/mark-todo-in-region ()
  (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.

  • Thank you for this, I'll accept it as soon as I've had a chance to try it – alfalfa Feb 5 '18 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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