2

My org-agenda view is made out of 5-6 files. Can one define a different face (mainly color) per file?

  • What portion of the entry do you want to color differently? The file name should already be shown by default as part of the org-agenda-prefix-format. – lawlist Jun 9 '16 at 7:12
  • yes the name of the file is there but all files have the same color. i would love to define a different color per filenname entry – zeltak Jun 9 '16 at 9:01
2

I don't understand lisp, but the following worked for me. It does not change the color of the complete entries, but it changes the color in which the file name (or rather: category name) preceding each entry is displayed.

  1. Add a category name to each of your agenda files, e.g. #+CATEGORY: Home in one file and #+CATEGORY: Work in another. It's conceivable that this step is completey unnecessary and that you can continue using file names.

  2. Add the following to your .emacs file:

    (add-hook 'org-finalize-agenda-hook
      (lambda ()
        (save-excursion
          (color-org-header "Home:" "azure" "black")
          (color-org-header "Work:" "RosyBrown1" "red"))))
    
    (defun color-org-header (tag backcolor forecolor)
      ""
      (interactive)
      (goto-char (point-min))
      (while (re-search-forward tag nil t)
        (add-text-properties (match-beginning 0) (+ (match-beginning 0) 10)
                         `(face (:background, backcolor, :foreground, forecolor)))))
    
  3. Customize the lines of the form (color-org-header "Home:" "azure" "black") to your liking. Here's a list of predefined colors.

  • Just tried the solution and found out that in Emacs 26.1 the hook's name is org-agenda-finalize-hook. – caseneuve Jul 30 '18 at 23:28

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.