emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] babel: using empty lines in python code while using session


From: Arun Persaud
Subject: [O] babel: using empty lines in python code while using session
Date: Mon, 10 Mar 2014 17:35:27 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

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 via email to

[Prev in Thread] Current Thread [Next in Thread]