From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arun Persaud Subject: babel: using empty lines in python code while using session Date: Mon, 10 Mar 2014 17:35:27 -0700 Message-ID: <531E5A4F.701@lbl.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNAfT-0003Ia-W7 for emacs-orgmode@gnu.org; Mon, 10 Mar 2014 20:35:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNAfM-0005Bu-8d for emacs-orgmode@gnu.org; Mon, 10 Mar 2014 20:35:39 -0400 Received: from fe2.lbl.gov ([128.3.41.134]:32718) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNAfM-0005Bm-2P for emacs-orgmode@gnu.org; Mon, 10 Mar 2014 20:35:32 -0400 Received: by mail-pd0-f169.google.com with SMTP id fp1so7816923pdb.0 for ; Mon, 10 Mar 2014 17:35:30 -0700 (PDT) Received: from [128.3.5.223] (apersaud.dhcp.lbl.gov. [128.3.5.223]) by mx.google.com with ESMTPSA id oz7sm69545651pbc.41.2014.03.10.17.35.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Mar 2014 17:35:29 -0700 (PDT) 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 Hi I started using python in org babel. The manual, for example [1], points to the fact that in session mode you can't have empty lines, since they will be interpreted differently. However, if you use ipython you can get around this, by using the following in your .emacs: ---------------------------- ; use ipython in org mode (setq org-babel-python-command "ipython3 --no-banner --classic --no-confirm-exit") ; 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 (if (stringp ad-return-value) (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 found it much easier, if I don't have to worry about the empty lines when writing python code. Might be useful for someone else, so I thought I post it here. Also, in ipython 2.0 you will be able to use %cpaste -q to suppress cpaste output, which will simplify the above a bit. thanks again for org-mode, it's getting more useful all the time ;) Arun [1] http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-python.html