From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arun Persaud Subject: Re: Babel python question: use of ipython and %cpaste Date: Tue, 03 Dec 2013 12:35:53 -0800 Message-ID: <529E40A9.6040303@lbl.gov> References: <529D7546.3080500@lbl.gov> <878uw2upjp.fsf@gmx.us> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnwhT-0001cV-O9 for emacs-orgmode@gnu.org; Tue, 03 Dec 2013 15:36:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VnwhK-0008NO-US for emacs-orgmode@gnu.org; Tue, 03 Dec 2013 15:36:07 -0500 Received: from fe2.lbl.gov ([128.3.41.134]:38458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VnwhK-0008ND-Nv for emacs-orgmode@gnu.org; Tue, 03 Dec 2013 15:35:58 -0500 Received: by mail-pd0-f169.google.com with SMTP id v10so20943868pde.0 for ; Tue, 03 Dec 2013 12:35:56 -0800 (PST) Received: from [128.3.5.231] (ape.dhcp.lbl.gov. [128.3.5.231]) by mx.google.com with ESMTPSA id hu10sm132158661pbc.11.2013.12.03.12.35.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 03 Dec 2013 12:35:55 -0800 (PST) In-Reply-To: <878uw2upjp.fsf@gmx.us> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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