0

In Org Agenda, I use Org priorities to know when I should get on something (A=now, B=soon or C=later).

I use :STYLE: property with a custom important value for some entries (no matter when I need to do it).

I would like to color the line for such entries in the global TODO list in the agenda buffer.

I see no help in :STYLE: habit related customization.

How could I do that?

0

Here's one way to fontify all entries matching :STYLE: important.

(defun fontify-important-entries ()
  ;; Move the point to the start of the buffer.
  (goto-char (point-min))
  ;; Then keep moving down one line until the end of the buffer.
  (while (progn (forward-line 1) (not (eobp)))
    ;; Now get the text property at the start of each line. If there
    ;; are no markers, do nothing.
    (when-let (marker (org-get-at-bol 'org-marker))
      (let* ((buffer (marker-buffer marker))
             (pos (marker-position marker))
             prop)
        ;; From the agenda buffer, move to the org file.
        (with-current-buffer buffer
          (widen) (goto-char pos)
          ;; The point is at the heading, so get the value of the
          ;; STYLE properties and set it to prop.
          (setq prop (org-entry-get nil "STYLE")))
        ;; Now move back to the agenda buffer and check if the value
        ;; of prop matches the string important.
        (when (string= prop "important")
          ;; If it does, change the face of that line/entry.
          (add-text-properties (point-at-bol)
                               (point-at-eol)
                               '(face org-habit-overdue-future-face)))))))

(add-hook 'org-agenda-finalize-hook 'fontify-important-entries)
|improve this answer|||||
  • Thank you very much, that works great! Would you comment your code a bit to help me understand it and get to write the function myself next time? What would I need to change to set a color among colors used in org? I specifically don't understand the add-text-properties part… Also, I don't understand the org-get-at-bol part. – teabow Oct 28 '19 at 11:11
  • @teabow see the comments. I'm not sure I understand your second question. If you want to use a different color you can do so by replacing the org-habit-overdue-future-face face wtih something else. – jagrg Oct 28 '19 at 16:30
  • Thanks for the comments. I tried to change org-habit-overdue-future-face to something else such as '(face :foreground "#FF0000") (or simply '(:foreground "#FF0000")) but nothing happens (items color doesn't change). – teabow Nov 6 '19 at 19:29
  • It should be '(face '(((:foreground "#FF0000")))) – jagrg Nov 7 '19 at 0:40
  • That's great, thank you! Really encouraging for learning some Elisp. – teabow Nov 7 '19 at 8:08

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.