From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vincent Beffara Subject: Re: Babel, Python and UTF-8 Date: Fri, 03 Dec 2010 16:43:23 +0100 Message-ID: References: <87fwuhas6t.fsf@gmail.com> <80bp54a693.fsf@missioncriticalit.com> <87hbew7yvi.fsf@gmail.com> <80k4jsszq4.fsf@missioncriticalit.com> <8739qf2ade.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from [140.186.70.92] (port=49404 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POXnV-0004Yu-BY for emacs-orgmode@gnu.org; Fri, 03 Dec 2010 10:43:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POXnU-00057H-CX for emacs-orgmode@gnu.org; Fri, 03 Dec 2010 10:43:45 -0500 Received: from lo.gmane.org ([80.91.229.12]:60721) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POXnU-00056d-1V for emacs-orgmode@gnu.org; Fri, 03 Dec 2010 10:43:44 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1POXnM-0006ac-VQ for emacs-orgmode@gnu.org; Fri, 03 Dec 2010 16:43:36 +0100 Received: from edgewall1.unige.ch ([129.194.3.6]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 03 Dec 2010 16:43:36 +0100 Received: from vbeffara by edgewall1.unige.ch with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 03 Dec 2010 16:43:36 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi, >> (and it would be excellent to allow for a code block as a preamble, >> instead of a string in the header or as an alternative, because >> preambles once they are allowed tend to grow uncontrollably ;->) > > This is currently possible using the `sbe' function. Arbitrary emacs > lisp can be placed inside of header arguments, and the `sbe' take the > name of a code block and returns its result. Very cool ! That does all I want, thanks for the info. For multi-line it is a bit heavy to write, with lots of \n and preamble .= "lskjd", but I can live with that. Unless there is a way already to write something like this ? --8<---------------cut here---------------start------------->8--- #+source: my-preamble #+begin_src python :return preamble # -*- coding: utf-8 -*-" import os,sys,whatever #+end_src #+begin_src python :preamble (org-babel-get-and-expand-source-code-body my-preamble) :return s s = "é" #+end_src --8<---------------cut here---------------end--------------->8--- There is org-babel-get-src-block-info but it looks at the block around (point), not by name ... so I guess it would not be too hard to write the extraction method, but it might be somewhere in the code already. >> One naive question : why is the code path different for tangling and >> evaluation ? One would think that a natural way for evaluation would be >> to tangle the current block (plus included noweb stuff etc) into a >> temporary file and eval that file ... and that would enable shebang for >> evaluation as well. There must be something I am missing here. > > Tangling works for *any* programming language, even those which have yet > to be created and have no explicit Emacs or Org-mode support, this is > because on tangling the code block is simply treated as text. As far as I understood from testing, tangling does adapt to the language (at least to implement :var in a suitable way), so I was under the impression that evaluating could be implemented as some kind of wrapping around the tangled output - and obviously the wrapping would have to be language-specific even if for the most part the tanglong is not. I am just discovering all of this, sorry if I have horrible misconceptions about the thing ... Regards, /v