emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* colored code background in org 8.3
@ 2016-06-01 11:18 John Kitchin
  2016-06-03 22:12 ` Rasmus
  0 siblings, 1 reply; 8+ messages in thread
From: John Kitchin @ 2016-06-01 11:18 UTC (permalink / raw)
  To: org mode

Hi all,

I am finally getting around to switching over to org 8.3... One thing I
miss already is the colored background in the code blocks. I recall that
was removed. Has anyone looked into a way to put it back?


-- 
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: colored code background in org 8.3
  2016-06-01 11:18 colored code background in org 8.3 John Kitchin
@ 2016-06-03 22:12 ` Rasmus
  2016-06-05 12:46   ` John Kitchin
                     ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Rasmus @ 2016-06-03 22:12 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 702 bytes --]

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> I am finally getting around to switching over to org 8.3... One thing I
> miss already is the colored background in the code blocks. I recall that
> was removed. Has anyone looked into a way to put it back?

I use the attached patch for some "interactive slides" with babel.

(require 'color)
(set-face-attribute 'org-block nil :inherit 'fixed-pitch
                    :background (color-darken-name
                                 (face-attribute 'default :background) 3))

You might also set :inherit of org-block-{begin,end}-line.

Rasmus

PS: My apology if I sent this twice now. 

-- 
Not everything that goes around comes back around, you know

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-src-src-blocks-also-inherit-org-block-face.patch --]
[-- Type: text/x-diff, Size: 2078 bytes --]

From 86244d84f8846489b893039749d724287c2c5dcd Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
Date: Fri, 3 Jun 2016 15:31:58 +0200
Subject: [PATCH] org-src: src-blocks also inherit org-block face

* lisp/org-src.el (org-src-font-lock-fontify-block): Inherit org-block
  face.
---
 lisp/org-src.el | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index f3a0960..9668096 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -494,21 +494,27 @@ 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)) pos next)
+	    (org-buffer (current-buffer)))
 	(remove-text-properties start end '(face nil))
 	(with-current-buffer
 	    (get-buffer-create
-	     (concat " org-src-fontification:" (symbol-name lang-mode)))
-	  (delete-region (point-min) (point-max))
+	     (format " *org-src-fontification:%s*" lang-mode))
+	  (erase-buffer)
 	  (insert string " ") ;; so there's a final property change
 	  (unless (eq major-mode lang-mode) (funcall lang-mode))
 	  (org-font-lock-ensure)
-	  (setq pos (point-min))
-	  (while (setq next (next-single-property-change pos 'face))
-	    (put-text-property
-	     (+ start (1- pos)) (1- (+ start next)) 'face
-	     (get-text-property pos 'face) org-buffer)
-	    (setq pos next)))
+	  (let ((pos (point-min)) next)
+	    (while (setq next (next-single-property-change pos 'face))
+	      (let ((new-face (get-text-property pos 'face)))
+		(put-text-property
+		 (+ start (1- pos)) (1- (+ start next)) 'face
+		 (list :inherit (append (and new-face (list new-face))
+					(list 'org-block)))
+		 org-buffer))
+	      (setq pos next))
+	    ;; Add the face to the remaining part of the font.
+	    (put-text-property (1- (+ start pos)) end 'face
+			       '(:inherit org-block) org-buffer)))
 	(add-text-properties
 	 start end
 	 '(font-lock-fontified t fontified t font-lock-multiline t))
-- 
2.8.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: colored code background in org 8.3
  2016-06-03 22:12 ` Rasmus
@ 2016-06-05 12:46   ` John Kitchin
  2016-06-07 11:33   ` Sebastien Vauban
  2016-06-09 11:43   ` Nicolas Goaziou
  2 siblings, 0 replies; 8+ messages in thread
From: John Kitchin @ 2016-06-05 12:46 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Thanks, this worked perfectly!

Rasmus writes:

> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> I am finally getting around to switching over to org 8.3... One thing I
>> miss already is the colored background in the code blocks. I recall that
>> was removed. Has anyone looked into a way to put it back?
>
> I use the attached patch for some "interactive slides" with babel.
>
> (require 'color)
> (set-face-attribute 'org-block nil :inherit 'fixed-pitch
>                     :background (color-darken-name
>                                  (face-attribute 'default :background) 3))
>
> You might also set :inherit of org-block-{begin,end}-line.
>
> Rasmus
>
> PS: My apology if I sent this twice now. 


-- 
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: colored code background in org 8.3
  2016-06-03 22:12 ` Rasmus
  2016-06-05 12:46   ` John Kitchin
@ 2016-06-07 11:33   ` Sebastien Vauban
  2016-06-07 15:07     ` Rasmus
  2016-06-09 11:43   ` Nicolas Goaziou
  2 siblings, 1 reply; 8+ messages in thread
From: Sebastien Vauban @ 2016-06-07 11:33 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello all,

Rasmus <rasmus-0UDz38MK/Mo@public.gmane.org> writes:
> John Kitchin <jkitchin-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org> writes:
>
>> I am finally getting around to switching over to org 8.3... One thing
>> I miss already is the colored background in the code blocks. I recall
>> that was removed. Has anyone looked into a way to put it back?
>
> I use the attached patch for some "interactive slides" with babel.

Could it be put into the official code base, for all users to enjoy
colored backgrounds without having to patch their Org by hand?

Best regards,
Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: colored code background in org 8.3
  2016-06-07 11:33   ` Sebastien Vauban
@ 2016-06-07 15:07     ` Rasmus
  2016-06-07 16:02       ` Samuel W. Flint
  0 siblings, 1 reply; 8+ messages in thread
From: Rasmus @ 2016-06-07 15:07 UTC (permalink / raw)
  To: emacs-orgmode

Sebastien Vauban <sva-news@mygooglest.com>
writes:

> Hello all,
>
> Rasmus <rasmus@gmx.us> writes:
>> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>>
>>> I am finally getting around to switching over to org 8.3... One thing
>>> I miss already is the colored background in the code blocks. I recall
>>> that was removed. Has anyone looked into a way to put it back?
>>
>> I use the attached patch for some "interactive slides" with babel.
>
> Could it be put into the official code base, for all users to enjoy
> colored backgrounds without having to patch their Org by hand?

Sure, eventually.  Let me know if you have tested the patch and it works
for you.

I don’t know much about faces, but it should work across all relevant
versions of Emacs.

Aside: Speaking of prettifying src blocks, with prettify-symbols-mode I
managed to make src-blocks look like this when the cursor is somewhere else

    λ LANGUAGE ☰

and like this otherwise

     #+begin_src LANGUAGE :keyword₁ value₁ ⋯ :keywordₙ valueₙ

Rasmus

-- 
Vote for proprietary math!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: colored code background in org 8.3
  2016-06-07 15:07     ` Rasmus
@ 2016-06-07 16:02       ` Samuel W. Flint
  0 siblings, 0 replies; 8+ messages in thread
From: Samuel W. Flint @ 2016-06-07 16:02 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1345 bytes --]

:: Rasmus  writes:

Rasmus> Sebastien Vauban <sva-news@mygooglest.com> writes:

>> Hello all,
>> 
>> Rasmus <rasmus@gmx.us> writes:
>>> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>>> 
>>>> I am finally getting around to switching over to org 8.3... One
>>>> thing I miss already is the colored background in the code
>>>> blocks. I recall that was removed. Has anyone looked into a way to
>>>> put it back?
>>> 
>>> I use the attached patch for some "interactive slides" with babel.
>> 
>> Could it be put into the official code base, for all users to enjoy
>> colored backgrounds without having to patch their Org by hand?

Rasmus> Sure, eventually.  Let me know if you have tested the patch and
Rasmus> it works for you.

Rasmus> I don’t know much about faces, but it should work across all
Rasmus> relevant versions of Emacs.

Rasmus> Aside: Speaking of prettifying src blocks, with
Rasmus> prettify-symbols-mode I managed to make src-blocks look like
Rasmus> this when the cursor is somewhere else

Rasmus>     λ LANGUAGE ☰

Rasmus> and like this otherwise

Rasmus>      #+begin_src LANGUAGE :keyword₁ value₁ ⋯ :keywordₙ valueₙ

How do you do this?

Thanks,

Sam

-- 
Samuel W. Flint
4096R/266596F4
      (9477 D23E 389E 40C5 2F10  DE19 68E5 318E 2665 96F4)
(λs.s s) λs.s s

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: colored code background in org 8.3
  2016-06-03 22:12 ` Rasmus
  2016-06-05 12:46   ` John Kitchin
  2016-06-07 11:33   ` Sebastien Vauban
@ 2016-06-09 11:43   ` Nicolas Goaziou
  2016-06-09 13:45     ` Rasmus
  2 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2016-06-09 11:43 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

> I use the attached patch for some "interactive slides" with babel.

It looks good, thank you.

> +	    ;; Add the face to the remaining part of the font.

Don't you mean "the remaining part of the text."?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: colored code background in org 8.3
  2016-06-09 11:43   ` Nicolas Goaziou
@ 2016-06-09 13:45     ` Rasmus
  0 siblings, 0 replies; 8+ messages in thread
From: Rasmus @ 2016-06-09 13:45 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

>> I use the attached patch for some "interactive slides" with babel.
>
> It looks good, thank you.

No worries, I needed it for my "slides", as I was told that src-blocks
needed to stand more out.

>> +	    ;; Add the face to the remaining part of the font.
>
> Don't you mean "the remaining part of the text."?

Yeah, most likely...

Rasmus

-- 
When in doubt, do it!

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-06-09 13:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-01 11:18 colored code background in org 8.3 John Kitchin
2016-06-03 22:12 ` Rasmus
2016-06-05 12:46   ` John Kitchin
2016-06-07 11:33   ` Sebastien Vauban
2016-06-07 15:07     ` Rasmus
2016-06-07 16:02       ` Samuel W. Flint
2016-06-09 11:43   ` Nicolas Goaziou
2016-06-09 13:45     ` Rasmus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).