5

I'm new to the org-mode in Emacs and I can't seem to find anything on how to sort a list of todos while editing in org-mode. I know that they can be sorted through some view (e.g. agenda), but I'd really like it to sort based on due date while listing them in the file. How do I accomplish this?

3
  • 1
    You wrote: "to sort based on due date while listing them in the file". Does that mean that the buffer is modified by the sorting? Your question is not as simple as it seems at the first glance. The org file has tree structure and TODO items can occur on each level of the tree. What do we do with that?? You cannot decompose a branch in the tree to get the right order. I think that was the main reason for the agenda view.
    – Tobias
    Commented Jan 29, 2018 at 16:26
  • Yes. I knew it would probably be tricky, but I've learned to never underestimate Emacs. That's fine if it's not really possible. Honestly, though, it would be fine to just sort the TODO items that appear together. Commented Jan 29, 2018 at 16:28
  • You can use this tool made by me: github.com/felipelalli/org-sort-tasks
    – Felipe
    Commented Jan 15, 2020 at 16:59

1 Answer 1

9

As discussed in the comments of your question the general case of sorting a whole org-tree does not make sense.

But, you can sort the entries on the first level of a (sub-)tree below a heading with org-sort with respect to the scheduled time.

Place point on the heading and call M-x org-sort RET. Afterwards press s for the scheduled time.

This command changes the org buffer

* Sorting
** TODO do something
   SCHEDULED: <2018-01-29 Mon 22:00>
** TODO do the second thing
   SCHEDULED: <2018-01-29 Mon 10:00>
** TODO do the first thing
   SCHEDULED: <2018-01-29 Mon 08:00>

into:

* Sorting
** TODO do the first thing
   SCHEDULED: <2018-01-29 Mon 08:00>
** TODO do the second thing
   SCHEDULED: <2018-01-29 Mon 10:00>
** TODO do something
   SCHEDULED: <2018-01-29 Mon 22:00>

If you prefer menu handling you can call org-sort with
Org->Edit Structure->Sort region/children.

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.