Andreas Leha <[email protected]> writes:
> My Org mode experience would also benefit a lot from having source block
> backgrounds again and with per-language configurable background colour.
That’s possible with the attache patch. An example of the horrors you can
subject yourself to is also attached.
--
Lasciate ogni speranza, voi che leggete questo.
>From 5d39108d319dc321af95e22c6cb25164dd61e891 Mon Sep 17 00:00:00 2001
From: Rasmus <[email protected]>
Date: Thu, 9 Jun 2016 16:52:05 +0200
Subject: [PATCH] org-src: Allow per language block face
* lisp/org-src.el (org-src-font-lock-fontify-block):
* lisp/org.el (org-fontify-meta-lines-and-blocks-1): Allow per-block
face.
---
lisp/org-src.el | 9 ++++++---
lisp/org.el | 4 +++-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 2f96fdf..d8c0541 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -494,7 +494,10 @@ as `org-src-fontify-natively' is non-nil."
(when (fboundp lang-mode)
(let ((string (buffer-substring-no-properties start end))
(modified (buffer-modified-p))
- (org-buffer (current-buffer)))
+ (org-buffer (current-buffer))
+ (block-faces (let ((face-name (intern (format "org-block-%s" lang))))
+ (append (and (facep face-name) (list face-name))
+ '(org-block)))))
(remove-text-properties start end '(face nil))
(with-current-buffer
(get-buffer-create
@@ -510,12 +513,12 @@ as `org-src-fontify-natively' is non-nil."
(put-text-property
(+ start (1- pos)) (1- (+ start next)) 'face
(list :inherit (append (and new-face (list new-face))
- (list 'org-block)))
+ block-faces))
org-buffer))
(setq pos next))
;; Add the face to the remaining part of the text.
(put-text-property (1- (+ start pos)) end 'face
- '(:inherit org-block) org-buffer)))
+ (list :inherit block-faces) org-buffer)))
(add-text-properties
start end
'(font-lock-fontified t fontified t font-lock-multiline t))
diff --git a/lisp/org.el b/lisp/org.el
index 206ebad..d00de1e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5976,7 +5976,9 @@ by a #."
(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
+ (let ((face-name (intern (format "org-block-%s" lang))))
+ (append (and (facep face-name) (list face-name))
+ '(face org-block))))) ; end of source block
((not org-fontify-quote-and-verse-blocks))
((string= block-type "quote")
(add-text-properties beg1 (min (point-max) (1+ end1)) '(face org-quote)))
--
2.8.3
#+BEGIN_SRC emacs-lisp :eval never
;; setup
(set-face-attribute 'org-block nil :background
(color-darken-name
(face-attribute 'default :background) 3))
(defface org-block-R
`((t (:background ,(color-lighten-name "#455EB3" 50))))
"Face for R src blocks")
(defface org-block-emacs-lisp
`((t (:background ,(color-lighten-name "#7F5AB6" 30))))
"Face for elisp src blocks")
(defface org-block-python
`((t (:background ,(color-lighten-name "#00FF00" 30))))
"Face for python blocks")
#+END_SRC
#+BEGIN_SRC emacs-lisp :var x=1
(defun x () 1 )
#+END_SRC
#+BEGIN_SRC R
x <- function () 1
#+END_SRC
#+BEGIN_SRC python
def x:
return(1)
#+END_SRC
#+BEGIN_SRC shell
echo 1
#+END_SRC