emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Arun Persaud <apersaud@lbl.gov>
To: emacs-orgmode@gnu.org
Subject: Re: Babel python question: use of ipython and %cpaste
Date: Tue, 03 Dec 2013 12:35:53 -0800	[thread overview]
Message-ID: <529E40A9.6040303@lbl.gov> (raw)
In-Reply-To: <878uw2upjp.fsf@gmx.us>

Hi

On 12/03/2013 03:44 AM, Rasmus wrote:
>> [ipython in org mode]
> 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
>[...]

nice ;) that works well for me. Thanks!

Since I now have ipython as an interpreter, is there a way to have org
mode use %cpaste to copy the code into the python buffer?

That way empty lines would be handled correctly, e.g.

#+BEGIN_SRC python :results output :session
  for i in range(2):
     print(i)

     print("next")

  print("done")
#+END_SRC

would work. I got it to work using something like this

; use %cpaste to paste code into ipython in org mode
(defadvice org-babel-python-evaluate-session
  (around org-python-use-cpaste
	  (session body &optional result-type result-params) activate)
  "add a %cpaste and '--' to the body, so that ipython does the right
thing."
  (setq body (concat "%cpaste\n" body "\n--"))
  ad-do-it
  (setq ad-return-value (replace-regexp-in-string "\\(^Pasting code;
enter '--' alone on the line to stop or use Ctrl-D\.[\r\n]:*\\)" ""
ad-return-value)))

I also put a request in to have a %cpaste -q option to suppress output.
But I'm wondering if there is a better way of doing this...

thanks again

Arun

  reply	other threads:[~2013-12-03 20:36 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
2013-12-03 20:35   ` Arun Persaud [this message]
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=529E40A9.6040303@lbl.gov \
    --to=apersaud@lbl.gov \
    --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).