How is it possible to sort todos by completion?

* Bar [0%]
** TODO Bar1
** TODO Bar2
* Foo [100%]
** DONE Foo1
   CLOSED: [2017-06-18 So 17:51]
** DONE Foo2
   CLOSED: [2017-06-18 So 17:51]
* Foo1 [0%]
** TODO Foo1
** TODO Foo2

For example I might constantly add new todos and finish other todos. How is it possible to sort the todos so that the todos with 100% will stay at the bottom?


The following should work, at least with your example, but you'll need to add at least one new line before the first heading.

(defun my-sort-entries ()
    (goto-char (point-min))
    (org-sort-entries nil ?f
                      (lambda ()
                        (let ((item (org-entry-get (point) "ITEM"))
                              (stats ".+\\[\\([0-9].+\\)%.+"))
                          (replace-regexp-in-string stats "\\1" item)))
                      'org-string-collate-greaterp nil t)))

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.