emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* interesting dilemma with ob-ipython
@ 2016-06-09 21:33 John Kitchin
  2016-06-09 21:42 ` Ken Mankoff
  2016-06-09 21:47 ` Anthony Cowley
  0 siblings, 2 replies; 5+ messages in thread
From: John Kitchin @ 2016-06-09 21:33 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

I was looking into ob-ipython as a replacement for regular
org-babel-python because it seems to be better at sessions. Also, you
can use other kernels with it!

For example:

#+BEGIN_SRC ipython :session hy :results output :kernel hy
(print "hello world")
(import time)
(print (time.asctime))
#+END_SRC

#+RESULTS:
: hello world
: Thu Jun  9 17:26:56 2016

Here is the dilemma:
If I special edit this, it is in python-mode, not hy-mode. And similarly
on export, it is highlighted as ipython, not hy-lang.

Any thoughts on how to address these?


-- 
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: interesting dilemma with ob-ipython
  2016-06-09 21:33 interesting dilemma with ob-ipython John Kitchin
@ 2016-06-09 21:42 ` Ken Mankoff
  2016-06-09 21:47 ` Anthony Cowley
  1 sibling, 0 replies; 5+ messages in thread
From: Ken Mankoff @ 2016-06-09 21:42 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode@gnu.org

Hi John,


On 2016-06-09 at 23:33, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
> I was looking into ob-ipython as a replacement for regular
> org-babel-python [...]
>
> Here is the dilemma:
> If I special edit this, it is in python-mode, not hy-mode. And similarly
> on export, it is highlighted as ipython, not hy-lang.
>
> Any thoughts on how to address these?

I'm not lispy enough to implement this, but I have an idea where you might start. See:

https://lists.gnu.org/archive/html/emacs-orgmode/2015-08/msg00594.html

Which is a thread which discussed (and provided an implementation for) named python sessions. Specifically, it uses the ":session foo" variable to modify the name of the special-edit buffer. Genercially, it uses something from the Babel header to modify something about special edit buffer, which is what I think you want to do.

Good luck,

  -k.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: interesting dilemma with ob-ipython
  2016-06-09 21:33 interesting dilemma with ob-ipython John Kitchin
  2016-06-09 21:42 ` Ken Mankoff
@ 2016-06-09 21:47 ` Anthony Cowley
  2016-06-10 14:19   ` John Kitchin
  1 sibling, 1 reply; 5+ messages in thread
From: Anthony Cowley @ 2016-06-09 21:47 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode@gnu.org


John Kitchin writes:

> I was looking into ob-ipython as a replacement for regular
> org-babel-python because it seems to be better at sessions. Also, you
> can use other kernels with it!
>
> For example:
>
> #+BEGIN_SRC ipython :session hy :results output :kernel hy
> (print "hello world")
> (import time)
> (print (time.asctime))
> #+END_SRC
>
> #+RESULTS:
> : hello world
> : Thu Jun  9 17:26:56 2016
>
> Here is the dilemma:
> If I special edit this, it is in python-mode, not hy-mode. And similarly
> on export, it is highlighted as ipython, not hy-lang.
>
> Any thoughts on how to address these?

I've had success using something like this,

(add-to-list 'org-src-lang-modes '("ipython" . haskell))

in a :noexport: setup section.

Anthony

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: interesting dilemma with ob-ipython
  2016-06-09 21:47 ` Anthony Cowley
@ 2016-06-10 14:19   ` John Kitchin
  2016-06-29  2:25     ` Ista Zahn
  0 siblings, 1 reply; 5+ messages in thread
From: John Kitchin @ 2016-06-10 14:19 UTC (permalink / raw)
  To: Anthony Cowley; +Cc: emacs-orgmode@gnu.org

Thanks for this tip. It was a great start! I turned it into this:

#+BEGIN_SRC emacs-lisp
;; make src blocks open in the right mode
(add-to-list 'org-src-lang-modes '("jupyter-hy" . hy))
(add-to-list 'org-latex-minted-langs '(jupyter-hy  "hylang"))

;; set default headers for convenience
(setq org-babel-default-header-args:jupyter-hy
      '((:results . "output replace")
	(:session . "hy")
	(:kernel . "hy")
	(:exports . "code")
	(:cache .   "no")
	(:noweb . "no")
	(:hlines . "no")
	(:tangle . "no")))

(defalias 'org-babel-execute:jupyter-hy 'org-babel-execute:ipython)

(add-to-list 'org-structure-template-alist
	     '("hy" "#+BEGIN_SRC jupyter-hy\n?\n#+END_SRC"
	       "<src lang=\"hy\">\n?\n</src>"))
#+END_SRC

Which solves all the problems!
1. src-blocks open in hy-mode and export as hylang in minted.
2. <hy expands nicely to the jupyter block with default settings.
3. C-c C-c runs the block using the hy jupyter kernel.

Fantastic. Thanks!


Anthony Cowley writes:

> John Kitchin writes:
>
>> I was looking into ob-ipython as a replacement for regular
>> org-babel-python because it seems to be better at sessions. Also, you
>> can use other kernels with it!
>>
>> For example:
>>
>> #+BEGIN_SRC ipython :session hy :results output :kernel hy
>> (print "hello world")
>> (import time)
>> (print (time.asctime))
>> #+END_SRC
>>
>> #+RESULTS:
>> : hello world
>> : Thu Jun  9 17:26:56 2016
>>
>> Here is the dilemma:
>> If I special edit this, it is in python-mode, not hy-mode. And similarly
>> on export, it is highlighted as ipython, not hy-lang.
>>
>> Any thoughts on how to address these?
>
> I've had success using something like this,
>
> (add-to-list 'org-src-lang-modes '("ipython" . haskell))
>
> in a :noexport: setup section.
>
> Anthony


-- 
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: interesting dilemma with ob-ipython
  2016-06-10 14:19   ` John Kitchin
@ 2016-06-29  2:25     ` Ista Zahn
  0 siblings, 0 replies; 5+ messages in thread
From: Ista Zahn @ 2016-06-29  2:25 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

On Fri, Jun 10, 2016 at 10:19 AM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
> Thanks for this tip. It was a great start! I turned it into this:
>
> #+BEGIN_SRC emacs-lisp
> ;; make src blocks open in the right mode
> (add-to-list 'org-src-lang-modes '("jupyter-hy" . hy))
> (add-to-list 'org-latex-minted-langs '(jupyter-hy  "hylang"))
>
> ;; set default headers for convenience
> (setq org-babel-default-header-args:jupyter-hy
>       '((:results . "output replace")
>         (:session . "hy")
>         (:kernel . "hy")
>         (:exports . "code")
>         (:cache .   "no")
>         (:noweb . "no")
>         (:hlines . "no")
>         (:tangle . "no")))
>
> (defalias 'org-babel-execute:jupyter-hy 'org-babel-execute:ipython)
>
> (add-to-list 'org-structure-template-alist
>              '("hy" "#+BEGIN_SRC jupyter-hy\n?\n#+END_SRC"
>                "<src lang=\"hy\">\n?\n</src>"))
> #+END_SRC
>
> Which solves all the problems!
> 1. src-blocks open in hy-mode and export as hylang in minted.
> 2. <hy expands nicely to the jupyter block with default settings.
> 3. C-c C-c runs the block using the hy jupyter kernel.

I worked up some code to do this for all installed jupyter kernels.
It's kind of rough (my elisp is not so good) by I submitted it as a
pull request at https://github.com/gregsexton/ob-ipython/pull/74. I
would appreciate any feedback or suggestions for improvement.

--Ista

>
> Fantastic. Thanks!
>
>
> Anthony Cowley writes:
>
>> John Kitchin writes:
>>
>>> I was looking into ob-ipython as a replacement for regular
>>> org-babel-python because it seems to be better at sessions. Also, you
>>> can use other kernels with it!
>>>
>>> For example:
>>>
>>> #+BEGIN_SRC ipython :session hy :results output :kernel hy
>>> (print "hello world")
>>> (import time)
>>> (print (time.asctime))
>>> #+END_SRC
>>>
>>> #+RESULTS:
>>> : hello world
>>> : Thu Jun  9 17:26:56 2016
>>>
>>> Here is the dilemma:
>>> If I special edit this, it is in python-mode, not hy-mode. And similarly
>>> on export, it is highlighted as ipython, not hy-lang.
>>>
>>> Any thoughts on how to address these?
>>
>> I've had success using something like this,
>>
>> (add-to-list 'org-src-lang-modes '("ipython" . haskell))
>>
>> in a :noexport: setup section.
>>
>> Anthony
>
>
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-06-29  2:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-09 21:33 interesting dilemma with ob-ipython John Kitchin
2016-06-09 21:42 ` Ken Mankoff
2016-06-09 21:47 ` Anthony Cowley
2016-06-10 14:19   ` John Kitchin
2016-06-29  2:25     ` Ista Zahn

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).