emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: Babel python question: use of ipython and %cpaste
Date: Tue, 03 Dec 2013 12:44:42 +0100	[thread overview]
Message-ID: <878uw2upjp.fsf@gmx.us> (raw)
In-Reply-To: 529D7546.3080500@lbl.gov

Arun Persaud <apersaud@lbl.gov> writes:

> Hi
>
> being able to use python as a source block is great, but I often stumble
> over the fact that when using sessions you have to treat empty lines in
> a special way (i.e. as the end of an indentation block).
>
> I was wondering if it would be easy to create an ipython mode, something
> like
>
> #+BEGIN_SRC ipython ...

You can get some of the way already.  Personally, I don't see the need
of a ipython block as I see IPython as an interpreter.


> where the content for a session is copied over to an ipython buffer
> using the ipython magic %cpaste. This way empty lines should be treated
> correctly.
>
> It would also have the nice side effect of giving access to other magic
> commands within org-babel, such as %timeit or profiling.

You could still use python source blocks for this.

For python.el I use :

  (setq python-shell-interpreter "ipython"
        ;; org mode seems to work better with classic mode. . .
        python-shell-interpreter-args "--classic --no-banner"
        python-shell-completion-setup-code
        "from IPython.core.completerlib import module_completion"
        python-shell-completion-module-string-code
        "';'.join(module_completion('''%s'''))\n"
        python-shell-completion-string-code
        "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")


For Org you could do: 

  (setq org-babel-python-command "ipython --no-banner --classic --no-confirm-exit")

You should now be able to do

#+BEGIN_SRC python :results output
%timeit 1+1
#+END_SRC

#+RESULTS:
: >>> 10000000 loops, best of 3: 31.5 ns per loop
: >>> 

–Rasmus

-- 
Hooray!

  reply	other threads:[~2013-12-03 11:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-03  6:08 Babel python question: use of ipython and %cpaste Arun Persaud
2013-12-03 11:44 ` Rasmus [this message]
2013-12-03 20:35   ` Arun Persaud
2013-12-03 12:48 ` Andreas Röhler

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878uw2upjp.fsf@gmx.us \
    --to=rasmus@gmx.us \
    --cc=emacs-orgmode@gnu.org \
    /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 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).