emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Coding systems in Babel
@ 2010-12-06 17:13 Vincent Beffara
  2010-12-07 13:24 ` Vincent Beffara
  2010-12-13 20:00 ` Eric Schulte
  0 siblings, 2 replies; 3+ messages in thread
From: Vincent Beffara @ 2010-12-06 17:13 UTC (permalink / raw)
  To: emacs-orgmode


Hi, it's me again, still trying to make sense of the interaction between
Org, Babel and coding systems. I have, in a UTF8-encoded .org file, this
code block:

--8<---------------cut here---------------start------------->8---
#+tblname: toto
| é |

#+begin_src python :var t=toto :preamble # -*- coding: latin1 -*-
babel = unicode (t[0][0],"latin1")
local = unicode ("é","latin1")
return [len(babel), len(local)]
#+end_src
--8<---------------cut here---------------end--------------->8---

Evaluating the block with C-c C-c leads to this:

--8<---------------cut here---------------start------------->8---
#+results:
| 1 | 1 |
--8<---------------cut here---------------end--------------->8---

So, the instance of python spawned by C-c C-c receives the text as
latin-1 encoded. Somewhere a conversion from UTF8 to latin-1
happens. But I don't want that, I want everything to stay in UTF8 from
the beginning to the end. I guess I have two questions:

At what point in the process is the convertion performed ?

How do I prevent it / how do I specify UTF8 as the exchange format
between Org-Babel and outside processes spawned by C-c C-c ?

The whole point is to make executed code-blocks and tangled source code
behave the same way - in that particular case, tangling leads to a
UTF8-encoded file, which is what I expected to happen.

Thanks for your help!

       /vincent

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

* Re: Coding systems in Babel
  2010-12-06 17:13 Coding systems in Babel Vincent Beffara
@ 2010-12-07 13:24 ` Vincent Beffara
  2010-12-13 20:00 ` Eric Schulte
  1 sibling, 0 replies; 3+ messages in thread
From: Vincent Beffara @ 2010-12-07 13:24 UTC (permalink / raw)
  To: emacs-orgmode


Hello,

> So, the instance of python spawned by C-c C-c receives the text as
> latin-1 encoded. Somewhere a conversion from UTF8 to latin-1
> happens. But I don't want that, I want everything to stay in UTF8 from
> the beginning to the end. I guess I have two questions:
>
> At what point in the process is the convertion performed ?
>
> How do I prevent it / how do I specify UTF8 as the exchange format
> between Org-Babel and outside processes spawned by C-c C-c ?

Mmmmkay, answering to myself (you never know, maybe it will be useful to
someone else later ...): the answer to that is in the general
interprocess comunication in Emacs. I ended up doing this:

--8<---------------cut here---------------start------------->8---
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))
--8<---------------cut here---------------end--------------->8---

and everything works fine now.

Having to set this by hand is a bit counter-intuitive though - would it
make sense to have babel set =coding-system-for-read= and
=coding-system-for-write= when running a subprocess ? From what I
understand, =shell-command-on-region= does that automatically but
=org-babel-eval= uses a temporary buffer which loses the encoding choice
for the .org file buffer.

Sorry for the noise, and thanks to all for this excellent tool ! I am
getting addicted to org and babel by the minute ...

Cheers,

        /v

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

* Re: Coding systems in Babel
  2010-12-06 17:13 Coding systems in Babel Vincent Beffara
  2010-12-07 13:24 ` Vincent Beffara
@ 2010-12-13 20:00 ` Eric Schulte
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2010-12-13 20:00 UTC (permalink / raw)
  To: Vincent Beffara; +Cc: emacs-orgmode

Hi Vincent,

This may be a by product of your local Emacs settings.  I say this only
because when I execute the same code block I get a different result,
e.g.

** utf8 and latin-1 encodings
#+tblname: toto
| é |

#+begin_src python :var t=toto :preamble # -*- coding: latin1 -*- :return [len(babel), len(local)]
  babel = unicode (t[0][0],"latin1")
  local = unicode ("é","latin1")
#+end_src

#+results:
| 2 | 2 |

I must profess I don't know what the python commands in your example
code block are doing, and I'm not sure what the desired result is.

Hope this is of some help-- Eric

Vincent Beffara <vbeffara@ens-lyon.fr> writes:

> Hi, it's me again, still trying to make sense of the interaction between
> Org, Babel and coding systems. I have, in a UTF8-encoded .org file, this
> code block:
>
> #+tblname: toto
> | é |
>
> #+begin_src python :var t=toto :preamble # -*- coding: latin1 -*-
> babel = unicode (t[0][0],"latin1")
> local = unicode ("é","latin1")
> return [len(babel), len(local)]
> #+end_src
>
> Evaluating the block with C-c C-c leads to this:
>
> #+results:
> | 1 | 1 |
>
> So, the instance of python spawned by C-c C-c receives the text as
> latin-1 encoded. Somewhere a conversion from UTF8 to latin-1
> happens. But I don't want that, I want everything to stay in UTF8 from
> the beginning to the end. I guess I have two questions:
>
> At what point in the process is the convertion performed ?
>
> How do I prevent it / how do I specify UTF8 as the exchange format
> between Org-Babel and outside processes spawned by C-c C-c ?
>
> The whole point is to make executed code-blocks and tangled source code
> behave the same way - in that particular case, tangling leads to a
> UTF8-encoded file, which is what I expected to happen.
>
> Thanks for your help!
>
>        /vincent
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

end of thread, other threads:[~2010-12-13 20:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-06 17:13 Coding systems in Babel Vincent Beffara
2010-12-07 13:24 ` Vincent Beffara
2010-12-13 20:00 ` Eric Schulte

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).