Skip to content

DIY Add support for engrave-faces ​

The engraved-faces package is used as part of an Org export process to produce decent colors in the output. Its default style though requires changes to use the colors of the active Modus theme.

In the code below we show how to map everything that engrave-faces defines to the corresponding entry in the palette of the active Modus theme. We then use a hook to ensure that the value is updated after we switch to another theme in the collection (DIY Use a hook at the post-load-theme phase).

emacs-lisp
(defun my-modus-themes-engraved-faces (&rest _)
  (modus-themes-with-colors
    (setq engrave-faces-themes
          `((default .
                     (;; faces.el --- excluding: bold, italic, bold-italic, underline, and some others
                      (default                             :short "default"             :slug "D"   :foreground ,fg-main :background ,bg-main :family "Monospace")
                      (variable-pitch                      :short "var-pitch"           :slug "vp"  :foreground ,fg-main                       :family "Sans Serif")
                      (shadow                              :short "shadow"              :slug "h"   :foreground ,fg-dim)
                      (success                             :short "success"             :slug "sc"  :foreground ,green :weight bold)
                      (warning                             :short "warning"             :slug "w"   :foreground ,warning :weight bold)
                      (error                               :short "error"               :slug "e"   :foreground ,err :weight bold)
                      (link                                :short "link"                :slug "l"   :foreground ,fg-link)
                      (link-visited                        :short "link"                :slug "lv"  :foreground ,fg-link-visited)
                      (highlight                           :short "link"                :slug "hi"  :foreground ,info)
                      ;; font-lock.el
                      (font-lock-comment-face              :short "fl-comment"          :slug "c"   :foreground ,comment)
                      (font-lock-comment-delimiter-face    :short "fl-comment-delim"    :slug "cd"  :foreground ,comment)
                      (font-lock-string-face               :short "fl-string"           :slug "s"   :foreground ,string)
                      (font-lock-doc-face                  :short "fl-doc"              :slug "d"   :foreground ,docstring)
                      (font-lock-doc-markup-face           :short "fl-doc-markup"       :slug "m"   :foreground ,docmarkup)
                      (font-lock-keyword-face              :short "fl-keyword"          :slug "k"   :foreground ,keyword)
                      (font-lock-builtin-face              :short "fl-builtin"          :slug "b"   :foreground ,builtin)
                      (font-lock-function-name-face        :short "fl-function"         :slug "f"   :foreground ,fnname)
                      (font-lock-variable-name-face        :short "fl-variable"         :slug "v"   :foreground ,variable)
                      (font-lock-type-face                 :short "fl-type"             :slug "t"   :foreground ,type)
                      (font-lock-constant-face             :short "fl-constant"         :slug "o"   :foreground ,constant)
                      (font-lock-warning-face              :short "fl-warning"          :slug "wr"  :foreground ,warning :weight bold)
                      (font-lock-negation-char-face        :short "fl-neg-char"         :slug "nc")
                      (font-lock-preprocessor-face         :short "fl-preprocessor"     :slug "pp"  :foreground ,preprocessor)
                      (font-lock-regexp-grouping-construct :short "fl-regexp"           :slug "rc"                        :weight bold)
                      (font-lock-regexp-grouping-backslash :short "fl-regexp-backslash" :slug "rb"                        :weight bold)
                      ;; org-faces.el
                      (org-block                           :short "org-block"           :slug "ob") ; forcing no background is preferable
                      (org-block-begin-line                :short "org-block-begin"     :slug "obb") ; forcing no background is preferable
                      (org-block-end-line                  :short "org-block-end"       :slug "obe") ; forcing no background is preferable
                      ;; outlines
                      (outline-1                           :short "outline-1"           :slug "Oa"  :foreground ,fg-heading-1)
                      (outline-2                           :short "outline-2"           :slug "Ob"  :foreground ,fg-heading-2)
                      (outline-3                           :short "outline-3"           :slug "Oc"  :foreground ,fg-heading-3)
                      (outline-4                           :short "outline-4"           :slug "Od"  :foreground ,fg-heading-4)
                      (outline-5                           :short "outline-5"           :slug "Oe"  :foreground ,fg-heading-5)
                      (outline-6                           :short "outline-6"           :slug "Of"  :foreground ,fg-heading-6)
                      (outline-7                           :short "outline-7"           :slug "Og"  :foreground ,fg-heading-7)
                      (outline-8                           :short "outline-8"           :slug "Oh"  :foreground ,fg-heading-8)
                      ;; highlight-numbers.el
                      (highlight-numbers-number            :short "hl-number"           :slug "hn"  :foreground ,number)
                      ;; highlight-quoted.el
                      (highlight-quoted-quote              :short "hl-qquote"           :slug "hq"  :foreground ,string)
                      (highlight-quoted-symbol             :short "hl-qsymbol"          :slug "hs"  :foreground ,constant)
                      ;; rainbow-delimiters.el
                      (rainbow-delimiters-depth-1-face     :short "rd-1"                :slug "rda" :foreground ,rainbow-0)
                      (rainbow-delimiters-depth-2-face     :short "rd-2"                :slug "rdb" :foreground ,rainbow-1)
                      (rainbow-delimiters-depth-3-face     :short "rd-3"                :slug "rdc" :foreground ,rainbow-2)
                      (rainbow-delimiters-depth-4-face     :short "rd-4"                :slug "rdd" :foreground ,rainbow-3)
                      (rainbow-delimiters-depth-5-face     :short "rd-5"                :slug "rde" :foreground ,rainbow-4)
                      (rainbow-delimiters-depth-6-face     :short "rd-6"                :slug "rdf" :foreground ,rainbow-5)
                      (rainbow-delimiters-depth-7-face     :short "rd-7"                :slug "rdg" :foreground ,rainbow-6)
                      (rainbow-delimiters-depth-8-face     :short "rd-8"                :slug "rdh" :foreground ,rainbow-7)
                      (rainbow-delimiters-depth-9-face     :short "rd-9"                :slug "rdi" :foreground ,rainbow-8)
                      ;; ansi-color
                      (ansi-color-yellow                   :short "ansi-yellow"         :slug "any" :foreground ,fg-term-yellow)
                      (ansi-color-red                      :short "ansi-red"            :slug "anr" :foreground ,fg-term-red)
                      (ansi-color-black                    :short "ansi-black"          :slug "anb" :foreground ,fg-term-black)
                      (ansi-color-green                    :short "ansi-green"          :slug "ang" :foreground ,fg-term-green)
                      (ansi-color-blue                     :short "ansi-blue"           :slug "anB" :foreground ,fg-term-blue)
                      (ansi-color-cyan                     :short "ansi-cyan"           :slug "anc" :foreground ,fg-term-cyan)
                      (ansi-color-white                    :short "ansi-white"          :slug "anw" :foreground ,fg-term-white)
                      (ansi-color-magenta                  :short "ansi-magenta"        :slug "anm" :foreground ,fg-term-magenta)
                      (ansi-color-bright-yellow            :short "ansi-bright-yellow"  :slug "ANy" :foreground ,fg-term-yellow-bright)
                      (ansi-color-bright-red               :short "ansi-bright-red"     :slug "ANr" :foreground ,fg-term-red-bright)
                      (ansi-color-bright-black             :short "ansi-bright-black"   :slug "ANb" :foregroun  ,fg-term-black-bright)
                      (ansi-color-bright-green             :short "ansi-bright-green"   :slug "ANg" :foreground ,fg-term-green-bright)
                      (ansi-color-bright-blue              :short "ansi-bright-blue"    :slug "ANB" :foreground ,fg-term-blue-bright)
                      (ansi-color-bright-cyan              :short "ansi-bright-cyan"    :slug "ANc" :foreground ,fg-term-cyan-bright)
                      (ansi-color-bright-white             :short "ansi-bright-white"   :slug "ANw" :foregroun  ,fg-term-white-bright)
                      (ansi-color-bright-magenta           :short "ansi-bright-magenta" :slug "ANm" :foregroun  ,fg-term-magenta-bright)))))))

(add-hook 'enable-theme-functions #'my-modus-themes-engraved-faces)