I has been struggling with this very annoying bug when code blocks in the org mode are messed up badly when the global-whitespace-mode is enabled.

This global-whitespace-mode is especially important to see the actual mess which is usually invisible (like decease causing bacteria).

My “quality benchmark” is how my configuration renders Sacha.org, you know.

So, here is how to fix it.

Doom themes (as a standalone package)

(use-package doom-themes
  :demand
  :hook (after-init . (lambda ()
                        (load-theme 'doom-gruvbox t)))
  :hook (org-mode . (lambda ()
                      (require 'doom-themes-ext-org)
                      (doom-themes-org-config)))
  :init
  (setq doom-themes-enable-bold t    ; if nil, bold is universally disabled
        doom-themes-enable-italic t) ; if nil, italics is universally
  :config
  (load-theme 'doom-gruvbox t))

Built-in whitespace-mode

(use-package whitespace
  :straight '(:type built-in)
  :after doom-themes
  :hook (after-init . global-whitespace-mode)
  :custom
  (whitespace-style
   (quote
    (face tabs spaces trailing space-before-tab newline indentation
  empty space-after-tab space-mark tab-mark))))

The kludge

  (use-package org
    :hook (org-mode . (lambda ()
                        (set-face-background 'org-block 'unspecified) ;; the fix
                        (set-face-attribute 'org-table nil :inherit 'fixed-pitch)
                        (set-face-attribute 'org-link nil :inherit 'fixed-pitch)
                        (set-face-attribute 'org-code nil :inherit 'fixed-pitch)
                        (set-face-attribute 'org-block nil :inherit 'fixed-pitch)
                        (set-face-attribute 'org-date nil :inherit 'fixed-pitch)
                        (set-face-attribute 'org-special-keyword nil
                                            :inherit 'fixed-pitch)
                        (mixed-pitch-mode t)
                        (variable-pitch-mode t))))

By the way, my full .emacs (permanent work in progress) can be found at https://github.com/schiptsov/e/