3

I was wondering if org-mode offers a function to sort a list by the item states? So that checked items appear on top and unchecked items at the bottom? For example with this list

- [ ] Not yet done
- [x] Already done
- [ ] Not yet done
- [x] Already done
- [ ] Not yet done
- [x] Already done
- [ ] Not yet done
- [x] Already done

I would get this list:

- [x] Already done
- [x] Already done
- [x] Already done
- [x] Already done
- [ ] Not yet done
- [ ] Not yet done
- [ ] Not yet done
- [ ] Not yet done
4

org-sort (bound to C-c ^) on a plain list will prompt for the sort method. One of the sorting options is [x]checked.

So C-c ^ x will do the job.

1

I don't know if Org has the function, but since the list is well-organized, you can simply use Emacs' sorting commands (see (info "(emacs) Sorting"))

If you don't mind changing exiting order, select the list and M-x sort-lines, this command simply sorts lines in region alphabetically. If you mind, you can use one of the following two methods.

  • Select the region from the first [ to the last ] and C-u M-x sort-columns
  • Select the list and type C-u M-x sort-regexp-fields RET ^.*$ RET \[.\] RET

(Note that - [ ] is lexicographically smaller than - [x] since ASCII code of (white space) is 32 and x's is 120).

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.