emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [PATCH] Set Python shell in Org edit buffer


From: Liu Hui
Subject: Re: [PATCH] Set Python shell in Org edit buffer
Date: Fri, 8 Dec 2023 18:19:28 +0800

Ihor Radchenko <yantar92@posteo.net> 于2023年12月7日周四 23:16写道:
>
> Liu Hui <liuhui1610@gmail.com> writes:
>
> > Ihor Radchenko <yantar92@posteo.net> 于2023年12月7日周四 18:33写道:
> >
> >> > +(defun org-babel-edit-prep:python (info)
> >> > +  "Set Python shell in Org edit buffer according to INFO."
> >> > +  (let ((session (cdr (assq :session (nth 2 info)))))
> >> > +    (when (and session (not (string= session "none")))
> >> > +      (setq-local python-shell-buffer-name
> >> > +                  (org-babel-python-without-earmuffs session)))))
> >>
> >> Will this work if Python session does not exist yet?
> >
> > If the specified session does not exist, users have to start the
> > session manually if they want to evaluate code directly in the edit
> > buffer. In fact, python-shell-send-* commands will clearly suggest
> > users using 'run-python' or C-c C-p to create the session in this
> > case.
>
> I am afraid that manually starting a python session with `run-python'
> will be misleading. Look at how much
> `org-babel-python-initiate-session-by-key' does. If users instead start
> the session with `run-python' they may get inconsistent results

ob-python has good support for using the existing session that created
by 'run-python', which contributes to a large part of
org-babel-python-initiate-session-by-key. It is common for users to
start a ob-python session with `run-python', even in the edit buffer.

But it is indeed possible that two sessions are inconsistent, if users
intend to have different org-babel-python-command and
python-shell-interpreter, which are used by
`org-babel-python-initiate-session' and `run-python', respectively.

> > Another choice is to use '(org-babel-python-initiate-session session)'
> > in org-babel-edit-prep:python, like ob-R, to create the session when
> > the specified session does not exist, but I feel it is invasive as
> > users may just want to edit the code.
>
> What about displaying a yes/no query about starting a new session when
> there is none?

I think it is OK. I can add an option to allow users to disable the
query. WDYT?



reply via email to

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