From: "Eric Schulte" <schulte.eric@gmail.com>
To: Vincent Beffara <vbeffara@ens-lyon.fr>
Cc: emacs-orgmode@gnu.org
Subject: Re: Re: Babel, Python and UTF-8
Date: Fri, 03 Dec 2010 07:30:51 -0700 [thread overview]
Message-ID: <8739qf2ade.fsf@gmail.com> (raw)
In-Reply-To: m2y687xibu.fsf@ens-lyon.fr
Hi,
Vincent Beffara <vbeffara@ens-lyon.fr> writes:
> Hi,
>
> "preamble" sounds fine
As this seems to be the general consensus I've replaced "prefix" with
"preamble" as the header argument name
> (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. e.g.
** Python requires a utf-8 coding prefix
#+source: my-preamble
#+begin_src python :return preamble
preamble = "# -*- coding: utf-8 -*-"
#+end_src
#+begin_src python :preamble (sbe my-preamble) :return s
s = "é"
#+end_src
#+results:
: é
#+begin_src python :preamble # -*- coding: utf-8 -*- :results output
s = "é"
print(s)
#+end_src
#+results:
: é
>
>>> The :shebang header argument is only used for tangling, not during
>>> evaluation, however if you ever needed to tangle python code blocks with
>>> non-ASCII encodings this would be the appropriate solution.
>>
>> Sorry, reading this after the other post...
>>
>> But, does it still make sense to make that distinction:
>>
>> - some sort of preamble only for tangling?
>> - a preamble for evaluation (and tangling)?
>
> 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.
Evaluation requires language specific support for both performing the
evaluation and collecting the result. Evaluation can (for example) be
performed using an external file or using a persistent session. Even
when using an external file the contents of the file are often very
different when tangling and exporting, e.g.
#+source: my-preamble
#+begin_src python :return preamble
preamble = "# -*- coding: utf-8 -*-"
#+end_src
tangles to the following (possibly with comments)
--8<---------------cut here---------------start------------->8---
preamble = "# -*- coding: utf-8 -*-"
--8<---------------cut here---------------end--------------->8---
and is evaluated as the following
--8<---------------cut here---------------start------------->8---
def main():
preamble = "# -*- coding: utf-8 -*-"
return preamble
open('temporary-result-collection-file', 'w').write( pprint.pformat(main()) )
--8<---------------cut here---------------end--------------->8---
Best -- Eric
>
> /v
>
>
> _______________________________________________
> 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
next prev parent reply other threads:[~2010-12-03 14:34 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-01 23:50 Babel, Python and UTF-8 Vincent Beffara
2010-12-02 1:18 ` Eric Schulte
2010-12-02 1:36 ` Vincent Beffara
2010-12-02 9:11 ` Sébastien Vauban
2010-12-02 19:34 ` Eric Schulte
2010-12-02 20:10 ` Sébastien Vauban
2010-12-03 10:27 ` Vincent Beffara
2010-12-03 11:27 ` Sébastien Vauban
2010-12-03 14:30 ` Eric Schulte [this message]
2010-12-03 15:43 ` Vincent Beffara
2010-12-05 15:30 ` Eric Schulte
2010-12-06 9:42 ` Dan Davison
2010-12-06 11:53 ` Eric S Fraga
2010-12-06 16:42 ` Thomas S. Dye
2010-12-06 18:07 ` Achim Gratz
2010-12-06 18:40 ` Thomas S. Dye
2010-12-06 18:23 ` Dan Davison
2010-12-02 14:29 ` Eric Schulte
2010-12-02 16:12 ` Vincent Beffara
2010-12-02 18:23 ` Dan Davison
2010-12-02 19:36 ` Eric Schulte
2010-12-02 20:05 ` Sébastien Vauban
2010-12-02 16:09 ` Sébastien Vauban
2010-12-02 16:44 ` Vincent Beffara
2010-12-03 14:56 ` Christopher Allan Webber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8739qf2ade.fsf@gmail.com \
--to=schulte.eric@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=vbeffara@ens-lyon.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.