all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Arun Persaud <apersaud@lbl.gov>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: babel: using empty lines in python code while using session
Date: Mon, 10 Mar 2014 17:35:27 -0700	[thread overview]
Message-ID: <531E5A4F.701@lbl.gov> (raw)

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

             reply	other threads:[~2014-03-11  0:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-11  0:35 Arun Persaud [this message]
2015-01-23 15:11 ` babel: using empty lines in python code while using session Puneeth Chaganti

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=531E5A4F.701@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 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.