1

I want to change the font and color of chunks of text in org mode, the way I can in OmniOutliner. Is it possible? Using the markdown or some other method.

Screenshot of my emacs, in org-mode:

In the raw markdown those are /italic/, *bold*, _underline_.

Screenshot of OmniOutliner:

1 Answer 1

1

To get this

Level-based fontification of list items + Ad-hoc emphasis with org-extra-emphasis

org-extra-emphasis and level-based fontification of list items

do this

  1. Install org-extra-emphasis.

  2. Create a file demo.org with following contents

Ad proident, nisi laboris !!minim irure!! cillum non.  Ad ea deserunt
veniam, labore excepteur proident, voluptate @!qui est minim nulla ea.
!@Anim duis velit et dolor sunt lorem officia do mollit veniam!@.
Laborum ex pariatur proident, officia nulla voluptate ex.

- Ad commodo magna cupidatat et aute velit magna cillum.  Eu quis
  magna culpa ut consectetur id sint exercitation aute ullamco.

  - Magna eiusmod qui esse tempor amet, do velit labore ullamco nisi.
    Dolore nisi tempor deserunt elit, dolor nisi in qui et quis
    pariatur ullamco reprehenderit ipsum commodo eiusmod proident, eu
    commodo.

- Aliquip pariatur qui exercitation fugiat anim aliquip non officia in
  fugiat ea exercitation nisi nulla sunt excepteur voluptate ex id.
  Incididunt aute amet, in laborum aute reprehenderit excepteur et ex
  ex aliqua qui !@culpa et!@ nisi.  Culpa laboris pariatur aliquip laboris
  est tempor veniam,.  Nisi eiusmod ex quis exercitation cupidatat
  deserunt id fugiat excepteur.

  - Deserunt ex fugiat sint velit est qui in pariatur non
    reprehenderit.  Quis dolor anim commodo anim proident, sint
    aliquip est veniam, !@incididunt est!@.  Ex consequat anim do tempor
    lorem pariatur anim irure excepteur labore adipiscing aute do
    irure excepteur.

    - Exercitation ipsum in nostrud dolor sed qui lorem excepteur
      cillum.  Pariatur id consectetur mollit excepteur consectetur
      nulla ullamco.  Fugiat irure anim irure dolor est consectetur
      proident.

  1. Create a file org-fontify-items.el with following contents

org-fontify-items.el

(require 'org)
(require 'org-element)
(require 'org-extra-emphasis)
(require 'hi-lock)

(defun my-org-fontify-item ()
  (let* ((faces '(nil hi-blue-b hi-green-b hi-red-b hi-black-b))
         (this (org-element-context))
         (level (let* ((item (org-element-lineage this '(item) t))
                       (i 0))
                  (while item
                    (cl-incf i)
                    (setq item (org-element-lineage item '(item))))
                  i))
         (index (mod level (length faces)))
         (face (nth index faces)))
    (when face
      (add-text-properties (org-element-property :contents-begin this)
                           (org-element-property :contents-end this)
                           `(font-lock-face ,face)))))


(defun my-org-fontify-items (limit)
  (let* ((case-fold-search t))
    (while (re-search-forward org-list-full-item-re limit t)
      (my-org-fontify-item))))

(add-hook 'org-font-lock-set-keywords-hook
          (defun my-org-font-lock-set-keywords-hook ()
            (setcdr (last org-font-lock-extra-keywords)
                    '((my-org-fontify-items)))))

(custom-set-variables
 '(org-hide-emphasis-markers t))

(custom-set-faces
 '(org-default ((t (
                    :background "#fff8ca"
                    :inherit default))))
 '(org-extra-emphasis ((t (
                           :background "#fff8ca"
                           :height 1.1
                           :inherit default
                           :weight bold
                           :width normal))))
 '(org-extra-emphasis-01 ((t (
                              :family "Noto Serif"
                              :foreground "deep pink"
                              :inherit org-extra-emphasis
                              :underline t))))
 '(org-extra-emphasis-02 ((t (
                              :family "Courier New"
                              :foreground "firebrick"
                              :italic t
                              :inherit org-extra-emphasis
                              :weight heavy)))))

  1. emacs -Q, M-x load-file RET org-extra-emphasis.el RET, M-x load-file RET org-fontify-items.el
  2. C-x C-f demo.org
  3. See also Custom fontification of org headlines
  4. Enjoy!

org-mode is a very complex library, and my understanding of font-lock mechanism is very minimal. So, expect breakages.

My code is good enough as a protoype. I am sure you will run in to issues if you org-mode heavily, and for each of those problems a solution exists, but hasn't be written yet.

Enjoy!

1
  • Nice! I'm need to read more about custom faces. I wish markdown styles combined, but that's probably a limitation of markdown syntax. Eg: it seems I can't do: /italic *bold and italic*/.
    – Rob N
    Commented Oct 1, 2022 at 15:37

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.