* [org-src, patch] colored source blocks
@ 2016-09-21 10:27 Rasmus
2016-09-21 14:22 ` Aaron Ecay
0 siblings, 1 reply; 3+ messages in thread
From: Rasmus @ 2016-09-21 10:27 UTC (permalink / raw
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 268 bytes --]
Hi,
As discussed earlier (though I can't find the thread right now) it would
be nice to have colored source blocks not depend on new faces but on a
variable.
This patch does that.
Is that OK to push?
Thanks,
Rasmus
--
The right to be left alone is a human right
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-src.el-New-syntax-for-source-blocks-faces.patch --]
[-- Type: text/x-diff, Size: 5481 bytes --]
From cbac4cfa0655b70c6e1b825a8ba6d538722596b4 Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
Date: Wed, 21 Sep 2016 11:02:49 +0200
Subject: [PATCH] org-src.el: New syntax for source blocks faces
* doc/org.texi (Editing source code): Document changes.
* lisp/org-faces.el (org-block): Update docstring.
(org-src-block-faces): New defcustom for source-block faces.
* lisp/org-src.el (org-src-font-lock-fontify-block): Use
org-src-block-faces.
* etc/ORG-NEWS: Update NEWS entry.
---
doc/org.texi | 17 ++++++++---------
etc/ORG-NEWS | 3 ++-
lisp/org-faces.el | 31 +++++++++++++++++++++++++++----
lisp/org-src.el | 10 +++++++---
4 files changed, 44 insertions(+), 17 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index 56779e8..8ab6c21 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -14900,21 +14900,20 @@ By default, Org will ask before returning to an open edit buffer. Set this
variable to @code{nil} to switch without asking.
@end table
-To turn on native code fontification in the @emph{Org} buffer, configure the
-variable @code{org-src-fontify-natively}. You can also change the appearance
-of source blocks by customizing the @code{org-block} face or for specific
-languages, by defining @code{org-block-LANGUAGE} faces. The following
-example shades the background of ``ordinary'' blocks while allowing Emacs
-Lisp source blocks to have a special color.
+To turn on native code fontification in the @emph{Org} buffer, set the
+variable @code{org-src-fontify-natively} to non-@code{nil}. You can also
+change the appearance of source blocks in general by customizing the
+@code{org-block} face or @code{org-src-block-faces} for specific languages.
+The following example shades the background of ``ordinary'' blocks while
+allowing Emacs Lisp and Python source blocks to have a separate colors.
@lisp
(require 'color)
(set-face-attribute 'org-block nil :background
(color-darken-name
(face-attribute 'default :background) 3))
-(defface org-block-emacs-lisp
- '((t (:background "#EEE2FF")))
- "Face for Emacs Lisp src blocks")
+(setq org-src-block-faces '(("emacs-lisp" (:background "#EEE2FF"))
+ ("python" "#e5ffb8")))
@end lisp
@node Exporting code blocks
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 9342cb2..eda018f 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -374,7 +374,8 @@ Repeated footnotes are now numbered by referring to a label in the
first footnote.
*** The ~org-block~ face is inherited by ~src-blocks~
This works also when =org-src-fontify-natively= is non-nil. It is also
-possible to specify per-languages faces. See the manual for details.
+possible to specify per-languages faces. See =org-src-block-faces= and
+the manual for details.
*** Links are now customizable
Links can now have custom colors, tooltips, keymaps, display behavior,
etc... Links are now centralized in ~org-link-parameters~.
diff --git a/lisp/org-faces.el b/lisp/org-faces.el
index 18eae1b..9ff3b2d 100644
--- a/lisp/org-faces.el
+++ b/lisp/org-faces.el
@@ -395,11 +395,34 @@ follows a #+DATE:, #+AUTHOR: or #+EMAIL: keyword."
(defface org-block '((t :inherit shadow))
"Face text in #+begin ... #+end blocks.
-In addition to this face that take precedence for particular
-languages. For instance, to change the block face for Emacs-Lisp
-blocks define a `org-block-emacs-lisp' face."
+For source-blocks `org-src-block-faces' takes precedence.
+See also `org-fontify-quote-and-verse-blocks'."
:group 'org-faces
- :version "22.1")
+ :version "25.2")
+
+(defcustom org-src-block-faces nil
+ "Alist of faces to be used for source-block.
+Each element is a cell of the format
+
+ (\"language\" FACE-OR-BACKGROUND)
+
+Where FACE-OR-BACKGROUND is either a face, an anonymous face, or
+a string corresponding to a background color.
+
+For instance, the following value would color the background of
+emacs-lisp source blocks and python source blocks in purple and
+green, respectability.
+
+ '((\"emacs-lisp\" (:background \"#EEE2FF\"))
+ (\"python\" (:background \"#e5ffb8\"))) "
+ :group 'org-faces
+ :type '(repeat (list (string :tag "language")
+ (choice
+ (color :tag "Background color")
+ (face :tag "Face")
+ (sexp :tag "Anonymous face"))))
+ :version "25.2"
+ :package-version '(Org . "9.0"))
(defface org-block-begin-line '((t (:inherit org-meta-line)))
"Face used for the line delimiting the begin of source blocks."
diff --git a/lisp/org-src.el b/lisp/org-src.el
index ab23b4a..f3b092e 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -513,9 +513,13 @@ as `org-src-fontify-natively' is non-nil."
org-buffer)))
(setq pos next))))
;; Add Org faces.
- (let ((face-name (intern (format "org-block-%s" lang))))
- (when (facep face-name)
- (font-lock-append-text-property start end 'face face-name))
+ (let ((src-face (cadr (assoc-ignore-case lang org-src-block-faces))))
+ (cond
+ ((or (facep src-face) (listp src-face))
+ (font-lock-append-text-property start end 'face src-face))
+ ((stringp src-face)
+ (font-lock-append-text-property start end 'face
+ (list :background src-face))))
(font-lock-append-text-property start end 'face 'org-block))
(add-text-properties
start end
--
2.10.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [org-src, patch] colored source blocks
2016-09-21 10:27 [org-src, patch] colored source blocks Rasmus
@ 2016-09-21 14:22 ` Aaron Ecay
2016-09-22 7:21 ` Rasmus
0 siblings, 1 reply; 3+ messages in thread
From: Aaron Ecay @ 2016-09-21 14:22 UTC (permalink / raw
To: Rasmus, emacs-orgmode
Hi Rasmus,
The patch in general LGTM. One comment/question, though:
2016ko irailak 21an, Rasmus-ek idatzi zuen:
[...]
> +(defcustom org-src-block-faces nil
> + "Alist of faces to be used for source-block.
> +Each element is a cell of the format
> +
> + (\"language\" FACE-OR-BACKGROUND)
> +
> +Where FACE-OR-BACKGROUND is either a face, an anonymous face, or
> +a string corresponding to a background color.
Why do you support a background color string here? I think that it’s
easy to specify faces which consist of a background color only both in
lisp [(:background "XXX") vs. "XXX"] and via the customize interface.
So this flexibility seems to just introduce additional complications for
virtually no benefit in usability. But maybe I’m missing something...?
--
Aaron Ecay
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [org-src, patch] colored source blocks
2016-09-21 14:22 ` Aaron Ecay
@ 2016-09-22 7:21 ` Rasmus
0 siblings, 0 replies; 3+ messages in thread
From: Rasmus @ 2016-09-22 7:21 UTC (permalink / raw
To: emacs-orgmode
Hi Aaron,
Thanks for the feedback.
Aaron Ecay <aaronecay@gmail.com> writes:
> The patch in general LGTM. One comment/question, though:
>
> 2016ko irailak 21an, Rasmus-ek idatzi zuen:
>
> [...]
>
>
>> +(defcustom org-src-block-faces nil
>> + "Alist of faces to be used for source-block.
>> +Each element is a cell of the format
>> +
>> + (\"language\" FACE-OR-BACKGROUND)
>> +
>> +Where FACE-OR-BACKGROUND is either a face, an anonymous face, or
>> +a string corresponding to a background color.
>
> Why do you support a background color string here?
Over-engineering?
> I think that it’s easy to specify faces which consist of a background
> color only both in lisp [(:background "XXX") vs. "XXX"] and via the
> customize interface. So this flexibility seems to just introduce
> additional complications for virtually no benefit in usability. But
> maybe I’m missing something...?
The "only" reason was that I imagine that some might prefer not to get
into anonymous faces. But then, there’s an example right there in the
docstring so maybe it’s assuming too little of our friends...
I’ll remove -OR-BACKGROUND and push.
Thanks,
Rasmus
--
This is the kind of tedious nonsense up with which I will not put
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-09-22 7:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-21 10:27 [org-src, patch] colored source blocks Rasmus
2016-09-21 14:22 ` Aaron Ecay
2016-09-22 7:21 ` Rasmus
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.