fontify-src-code-blocks.org 2.6 KB

Description

This article is some "theming guide" about customizing the look and feel of an Org-Babel buffer inside Emacs. We'll show you how you can improve the appearance of source code blocks.

Note that coloring the background of code blocks with native fontification no longer works as of commit f8b42e8.

Screenshot

Screenshot for the Leuven theme (light theme, i.e. with a white background):

../images/fontified-src-code-blocks.png

To configure "native fontification" (as in the above screenshot), set the following in your =.emacs= file:

;; fontify code in code blocks (setq org-src-fontify-natively t)

Configuration File

  • To get the above full contributed theme, please visit [[file:../../../org-color-themes.org][Installing Org Color
  • themes]] and copy the file [[https://github.com/fniessen/color-theme-leuven/blob/master/color-theme-leuven.el][color-theme-leuven.el]] in your =load-path=.
  • If you want to keep your existing Emacs color theme, and you only want to
  • customize the "delimiter lines" of the code blocks, either:
  • Add the following lines to your current color theme:

#+begin_src emacs-lisp (org-block-begin-line ((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF")))) (org-block-background ((t (:background "#FFFFEA")))) (org-block-end-line ((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF")))) #+end_src

  • Define these faces, in your =.emacs= file, before requiring Org (if you
  • don't have your own color theme):

#+begin_src emacs-lisp (defface org-block-begin-line '((t (:underline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))) "Face used for the line delimiting the begin of source blocks.")

(defface org-block-background '((t (:background "#FFFFEA"))) "Face used for the source block background.")

(defface org-block-end-line '((t (:overline "#A7A6AA" :foreground "#008ED1" :background "#EAEAFF"))) "Face used for the line delimiting the end of source blocks.") #+end_src

Further extensions

When we will have some spare time, our intention is to get the reserved keywords of Org-Babel (such as :var and :exports) somehow highlighted. Stay tuned -- or give some help!