0

org-agenda-sorting-strategy priority sorting doesn't work in my setup. I have a single file for all the tasks for agenda. Its structure looks similar to this:

#+STARTUP: overview
#+CATEGORY: Tasks
#+ARCHIVE: ../archive/tasks_archive.org::

* Tasks
:PROPERTIES:
:CATEGORY: Single
:END:
** TODO [#B] task 1
SCHEDULED: <2020-08-06 Thu>
** TODO [#B] task 2
SCHEDULED: <2020-08-06 Thu>
** TODO [#C] task 3
SCHEDULED: <2020-08-06 Thu>
** TODO [#A] task 4
SCHEDULED: <2020-08-06 Thu>

* Repeatable
:PROPERTIES:
:CATEGORY: Repeat
:END:
** TODO [#B] task 5
SCHEDULED: <2020-08-06 Thu .+1d>
:PROPERTIES:
:STYLE:    habit
:END:
** TODO [#D] task 6
SCHEDULED: <2020-08-06 Thu .+1d>
:PROPERTIES:
:STYLE:    habit
:END:
** TODO [#C] task 7
SCHEDULED: <2020-02-02 Sun ++1m>
:PROPERTIES:
:LAST_REPEAT: [2020-08-06 Thu 20:44]
:STYLE:    habit
:END:
** TODO [#A] task 8
SCHEDULED: <2020-08-06 Thu .+1d>
:PROPERTIES:
:STYLE:    habit
:END:

* Waiting
:PROPERTIES:
:CATEGORY: Wait
:END:
** TODO [#A] task 9
SCHEDULED: <2020-08-06 Thu>
** TODO [#C] task 10
SCHEDULED: <2020-08-06 Thu>
** TODO [#B] task 11
SCHEDULED: <2020-08-06 Thu>
** TODO [#D] task 12
SCHEDULED: <2020-08-06 Thu>

* Projects
:PROPERTIES:
:CATEGORY: Project
:END:
** TODO [#B] task 13
SCHEDULED: <2020-08-06 Thu>
** TODO [#D] task 14
SCHEDULED: <2020-08-06 Thu>
** TODO [#C] task 15
SCHEDULED: <2020-08-06 Thu>
** TODO [#B] task 16
SCHEDULED: <2020-08-06 Thu>

My setup to display agenda looks similar to this:

(agenda ""
  ((org-agenda-skip-function
     '(or
        (org-agenda-skip-entry-if 'todo '("WAITING"))
        ))
    (org-agenda-cmp-user-defined 'jarfar/org-agenda-cmp-user-defined-birthday)
    (org-agenda-sorting-strategy '(time-up todo-state-down user-defined-down habit-down priority-up deadline-up scheduled-up effort-down alpha-up))
    (org-agenda-remove-tags nil)
    (ps-number-of-columns 2)
    (ps-landscape-mode 1)
    (org-agenda-files (append org-agenda-files `(,my/org-events-file-path)))))

(defun jarfar/org-agenda-cmp-user-defined-birthday (a b)
  "Org Agenda user function to sort categories against other categories. The birthday category is considered to be behind other category by default."
  (let* ((pla (get-text-property 0 "CATEGORY" a))
          (plb (get-text-property 0 "CATEGORY" b))
          (pla (string-equal pla "Birthday"))
          (plb (string-equal plb "Birthday"))
          )
    (if (or (and pla plb) (and (not pla) (not plb)))
      0
      (if pla
        1
        -1))))

The agenda show records with different priorities totally mixed up. When I run agenda with org-agenda-sorting-strategy set to just priority-up it doesn't change anything.

Any hint what could be wrong?


EDIT: I solved most of the problem. The main issue was caused by wrong implementation of jarfar/org-agenda-cmp-user-defined-birthday the correct one is:

(defun jarfar/org-agenda-cmp-user-defined-birthday (a b)
  "Org Agenda user function to sort categories against other categories. The birthday category is considered to be behind other category by default."
  (let* ((pla (get-text-property 0 "CATEGORY" a))
          (plb (get-text-property 0 "CATEGORY" b))
          (pla (string-equal pla "Birthday"))
          (plb (string-equal plb "Birthday"))
          )
    (if (or (and pla plb) (and (not pla) (not plb)))
      nil
      (if pla
        +1
        -1))))

The tasks are now sorting fine, but habits still not. They still sort in a weird way.

My current sorting setting is:

(setq org-agenda-sorting-strategy '(time-up todo-state-down user-defined-down habit-down priority-down deadline-up scheduled-up effort-down alpha-up))

Any clue?

  • Your agenda file does not contain any priorities at all. See Priorities – NickD Aug 5 '20 at 14:20
  • @NickD thanks, sorry I forget to add priorities in example structure. Of course I have priorities assigned to my task list. I added them, plus some more tasks and scheduled them, as they would look in the real life. They are all scheduled the same day to eliminate the time factor and focus on priorities. – farynaio Aug 6 '20 at 6:16
  • When you run this example you will see that the tasks are not sorted at all, they are all listed as they occur in the file. The value of option 'org-agenda-sorting-strategy' is ignored. – farynaio Aug 6 '20 at 8:16
  • Are you sure you are not screwing things up with your settings? Did you try it with default settings? BTW, I just did and I get all the A items, then the B items, then the C items, then the D iems. I'm pretty sure your settings are wrong, but I have not checked how they are wrong. – NickD Aug 6 '20 at 17:51
  • @NickD, thanks. I set the repeatable tasks as real repeatable with proper timestamp and changed most of them to habit. I managed to replicate problem with incorrect sorting priorities in this configuration. Can you please check it? – farynaio Aug 6 '20 at 20:01

Your Answer

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

Browse other questions tagged or ask your own question.