Fontify R Code Blocks in Org Mode 8

I'm trying to change the background color of R code blocks in Org-mode 8. In Org-mode 7 I was able to use:

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

      

But the variable org-block-background

seems to have disappeared in version 8 ...?

I tried:

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

      

which works for:

#+BEGIN_SRC
#+END_SRC

      

and

#+BEGIN_latex
#+END_latex

      

But for some reason, the background color disappears as soon as I specify the language, like ...

#+BEGIN_SRC R
#+END_SRC

      

I'm working on a Mac, running Emacs 24.3 and upgrading org-mode to v8 using:

cd ~/.emacs.d/lisp
git clone git://orgmode.org/org-mode.git
cd org-mode
make autoloads
make
make doc

      

Here is the config from the init.el file:

;;;----- Startup ----------------------------;

;;; Add src directory to path
(add-to-list 'load-path "~/.emacs.d/lisp/")

;;;----- Org-Mode ---------------------------;

;;; Add upgraded org-mode to load path
(add-to-list 'load-path "~/.emacs.d/lisp/org-mode/lisp")
(add-to-list 'load-path "~/.emacs.d/lisp/org-mode/contrib/lisp" t)

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

(defface org-block-begin-line
  '((t (:foreground "#666666" :background "#dadada")))
  "Face used for the line delimiting the begin of source blocks.")

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

(defface org-block-end-line
  '((t (:foreground "#666666" :background "#dadada")))
  "Face used for the line delimiting the end of source blocks.")

(require 'org)

;;;----- ESS/R ------------------------------;

(add-to-list 'load-path "~/.emacs.d/lisp/ess/lisp/")
(load "ess-site")

;;;------ Babel ------------------------------;

;;; Support R
(org-babel-do-load-languages
  'org-babel-load-languages
  '((R . t)
    (latex . t)))

;;;----- Look & feel ----------------------------;

;;; Set default theme
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(load-theme 'solarized-light t)

      

Any ideas?

Thank!

+3


source to share


3 answers


I understood that. It turns out I cloned an old org-mode branch that was missing a variable org-block-background

! Deleted my folder in org-mode and reinstalled with:

cd ~/.emacs.d/lisp
git clone https://github.com/Konubinix/org-mode.git
cd org-mode
make autoloads
make
make doc

      

Then changed my init.el as follows:



;;;----- Org-Mode ---------------------------;


;;; Add upgraded org-mode to load path
(add-to-list 'load-path "~/.emacs.d/lisp/org-mode/lisp")
(add-to-list 'load-path "~/.emacs.d/lisp/org-mode/contrib/lisp" t)

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

(defface org-block-begin-line
  '((t (:foreground "#666666" :background "#dadada")))
  "Face used for the line delimiting the begin of source blocks.")

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

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

(defface org-block-end-line
  '((t (:foreground "#666666" :background "#dadada")))
  "Face used for the line delimiting the end of source blocks.")

(require 'org)

      

And presto!

+1


source


FYI, this won't work for current versions of Org Mode (from the master Git branch) after this commit http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=f8b42e8 - at least not yet something will not change. Announced here (July 2014) and continues to apply to Org users. see here (April 2015). Anyone tinkering with restoring old behavior locally could do this with a diff commit - I haven't tried it. Future versions of Org Mode may restore this feature, perhaps going differently. So far, this is all you can get:

enter image description here



(The first SRC block above gets the background from my setup for org-block

.)

+5


source


It turns out the org-block-background

person was removed in org version 8.3.1 in the commit f8b42e8

, thus the error. The rationale seems

  • it throws an error with ps

    export
  • it is ineffective

There may be an alternative in the future, but not yet.

Fontify R Code Blocks in Org Mode 8

https://lists.gnu.org/archive/html/emacs-orgmode/2015-08/msg00510.html

Currently, it seems that the only way to revert the old behavior is to manually change the changes made in commit f8b42e8

. You can see the commit here:

http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=f8b42e8

diff --git a/lisp/org-faces.el b/lisp/org-faces.el
index e693dab..83453e8 100644
--- a/lisp/org-faces.el
+++ b/lisp/org-faces.el
@@ -537,9 +537,6 @@ follows a #+DATE:, #+AUTHOR: or #+EMAIL: keyword."
   :group 'org-faces
   :version "22.1")

-(defface org-block-background '((t ()))
-  "Face used for the source block background.")
-
 (org-copy-face 'org-meta-line 'org-block-begin-line
   "Face used for the line delimiting the begin of source blocks.")

diff --git a/lisp/org.el b/lisp/org.el
index a153151..7e30061 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5930,15 +5930,7 @@ by a #."
          (cond
           ((and lang (not (string= lang "")) org-src-fontify-natively)
        (org-src-font-lock-fontify-block lang block-start block-end)
-       ;; remove old background overlays
-       (mapc (lambda (ov)
-           (if (eq (overlay-get ov 'face) 'org-block-background)
-               (delete-overlay ov)))
-             (overlays-at (/ (+ beg1 block-end) 2)))
-       ;; add a background overlay
-       (setq ovl (make-overlay beg1 block-end))
-                (overlay-put ovl 'face 'org-block-background)
-                (overlay-put ovl 'evaporate t)) ; make it go away when empty
+       (add-text-properties beg1 block-end '(src-block t)))
           (quoting
        (add-text-properties beg1 (min (point-max) (1+ end1))
                     '(face org-block))) ; end of source block
@@ -21828,9 +21820,7 @@ and end of string."
 When INSIDE is non-nil, don't consider we are within a src block
 when point is at #+BEGIN_SRC or #+END_SRC."
   (let ((case-fold-search t) ov)
-    (or (and (setq ov (overlays-at (point)))
-        (memq 'org-block-background
-          (overlay-properties (car ov))))
+    (or (and (eq (get-char-property (point) 'src-block) t))
    (and (not inside)
         (save-match-data
           (save-excursion

      

+3


source







All Articles