9

I want child org items to inherit priority from their parent.

I tried setting org-use-property-inheritance '("PRIORITY"), but it did not have any apparent effect.

Use case: I often have high priority projects whose tasks are mostly equally important. I don't want to waste time setting priorities for each individual child task unless it differs from the parent (e.g., an optional subtask may have lower priority).

Update: I e-mailed the org mailing list. Will report back if I get a useful response.

9
  • The mailing-list thread referenced: lists.gnu.org/archive/html/emacs-orgmode/2018-01/msg00075.html Unresolved as of 12-03-2018. Mar 13, 2018 at 0:18
  • 1
    FWIW, I wrote a semi-working implementation in org-mode. Need to finish it and submit a patch. Mar 13, 2018 at 18:17
  • Wow, looking forward do it! Mar 13, 2018 at 21:36
  • 1
    Update: went back and fleshed out my implementation of priority inheritance so it both sorts correctly in various agenda views and is visible in both agenda and colview. Preparing to submit a patch. Apr 22, 2018 at 20:46
  • That's exciting! Thanks for the updates. :D Apr 23, 2018 at 17:29

2 Answers 2

4

The mailing list referenced in the first comment of the question states the following:

Note that you can already achieve inheritance by setting `org-get-priority-function' to a function that searches priority cookies among ancestors of the current headline.

I went ahead and implemented that suggestion (note that org-get-priority-function is just an alias for org-priority-get-priority-function):

(defun my/org-inherited-priority (s)
  (cond

   ;; Priority cookie in this heading
   ((string-match org-priority-regexp s)
    (* 1000 (- org-priority-lowest
               (org-priority-to-value (match-string 2 s)))))

   ;; No priority cookie, but already at highest level
   ((not (org-up-heading-safe))
    (* 1000 (- org-priority-lowest org-priority-default)))

   ;; Look for the parent's priority
   (t
    (my/org-inherited-priority (org-get-heading)))))

(setq org-priority-get-priority-function #'my/org-inherited-priority)

Along with adding %l to org-agenda-prefix-format, this bit of code gives me an Org Agenda with indented subtasks that immediately follow their parent tasks (why I went down this rabbit hole in the first place).

6
  • 1
    It doesn't work. Apr 30, 2021 at 18:25
  • 1
    @EvgenyMikhaylov Works for me. Note, this doesn't cause the agenda to display the priority as the function returns it, but it does affect the ordering.
    – JoL
    Aug 18, 2021 at 0:35
  • @JoL I am sorry, it seems to work, if you don't mess priorities up enabling specific priority ranges for each org file. I would like ancestor to take a priority value of its predecessor, but it doesn't work that way. If priority value is not set, it's get calculated and you can see that priorities may be different for a child and it's parent, by using (org-priority-show) on them. When I made equal lowest and highest priority levels for individual files it calculated more predictably. Jul 11, 2022 at 9:06
  • Where does function org-priority-to-value come from? It's undefined for me. Oct 22, 2022 at 20:50
  • @EvgenyMikhaylov The function is defined directly in org.el.
    – eeowaa
    Oct 24, 2022 at 8:30
1

In the absence of a genuine answer to this at the moment, I'm going to post this partial solution to the problem, if not to the literal question. The second pair of functions here raise and lower the priority of all items in the selected region:

(defun my/org-priority-up ()
  (org-priority 'up))

(defun my/org-priority-down ()
  (org-priority 'down))

(defun my/org-priority-up-region ()
  (interactive)
  (org-map-entries #'my/org-priority-up nil 'region)
  (setq deactivate-mark nil))

(defun my/org-priority-down-region ()
  (interactive)
  (org-map-entries #'my/org-priority-down nil 'region)
  (setq deactivate-mark nil))

You can just bind those last two to keys in the normal way.

For spacemacs users, here's a fancier way (,r. puts you in a transient state which lets you raise and lower the priorities on all items in the selected region using just the up and down arrow keys -- q to escape the transient state):

(spacemacs|define-transient-state my/org-region
  :title "Org region transient state"
  :bindings
  ("<up>" my/org-priority-up-region "up")
  ("<down>" my/org-priority-down-region "down")
  ("q" (lambda () (interactive) (setq deactivate-mark t)) "quit" :exit t))

(with-eval-after-load 'org
  (spacemacs/set-leader-keys-for-major-mode 'org-mode
    "r." 'spacemacs/my/org-region-transient-state/body))
2

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.