all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jack Kamm <jackkamm@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: Liu Hui <liuhui1610@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: [PATCH] Set Python shell in Org edit buffer
Date: Sat, 06 Jan 2024 22:07:38 -0800	[thread overview]
Message-ID: <87o7dxu15h.fsf@gmail.com> (raw)
In-Reply-To: <87wmsn6ghw.fsf@localhost>

Ihor Radchenko <yantar92@posteo.net> writes:

> Now, the question is what to do with the existing implementation of
> `org-src-associate-babel-session'. It only runs
> org-babel-<lang>-associate-session when
>
> (and session (not (string= session "none"))
> 	 (org-babel-comint-buffer-livep session)
> 	 (let ((f (intern (format "org-babel-%s-associate-session"
>                                   (nth 0 info)))))
>            (and (fboundp f) (funcall f session))))
>
> The questionable check here is (org-babel-comint-buffer-livep session) -
> it only triggers when session is already initiated, while ob-python and
> some other backends do not necessarily need to start a new session to
> "associate" it with Org Src buffer.
>
> I am tentatively inclined to change this check to
>
> (or (org-babel-comint-buffer-livep session)
>     (eq org-src-auto-initiate-session t)
>     (alist-get (nth 0 info) org-src-auto-initiate-session)
>     (alist-get 'default org-src-auto-initiate-session))
>
> With `org-src-auto-initiate-session' being a customization that controls
> whether to associate session for a given babel backend.
>
> We may set the default value to something like
>
> ((default . t) ("R" . nil))

I think there are 2 aspects of the session+editing behavior that I'd
like to disentangle:

1. Whether to create session when editing (if it doesn't exist yet)
2. If session exists, whether to "associate" it so that evaluation
   commands (e.g. python-shell-send-region, ess-eval-region) and
   autocompletion use it.

Personally, I prefer to disable #1 while enabling #2. For ob-R, it
seems like #1 happens in `org-babel-edit-prep:R' while #2 happens in
`org-babel-R-associate-session', so adding an option to disable the
latter isn't useful for me, and it's not clear to me whether it'd be
useful generally for others either.

(I realize #2 hasn't worked properly for some time now until you fixed
it in this thread. I wasn't too badly affected because I usually only
use one session at a time, and ess-eval-region is able to figure out
the session in this case. But I did sometimes have to manually call
`ess-force-buffer-current' to get completion working, which it seems I
no longer have to do now that you've fixed this).

As an aside, I just noticed some inconsistent behavior in ob-R. It seems
it only auto-creates the session when ":session *foo*" (i.e. the session
name has "earmuffs"). But when ":session foo" (no earmuffs), ob-R
doesn't autostart the session. While this is probably accidental, it
doesn't seem to cause any problems, which makes me question whether it's
really needful for ob-R to initiate a session on edit.  In particular,
if ":session foo" already exists, then ess-eval-region still works fine
in the src block. Which is exactly my desired behavior -- don't create
the session if it doesn't exist yet, but if it already exists then play
nicely with it.

Another thing to note is that ob-R works fine with sessions externally
created with "M-x R".  (similar to how ob-python works fine with "M-x
run-python"). In fact, I sometimes use ob-R with manual "M-x R" sessions
when I need to use a different R binary/environment than my usual
one. So, it is not necessary for the R session to be started through ob-R.

As for ob-python; I think it's best to set `python-shell-buffer-name'
in `org-babel-edit-prep:python' rather than
`org-babel-python-associate-session'. While both work for
`python-shell-send-region' if the session already exists,
`org-babel-edit-prep:python' has the advantage that it will run even
if the session doesn't exist yet, so then "M-x run-python" in the src
block will create a session with the correct name.


  parent reply	other threads:[~2024-01-07  6:08 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05 10:18 [PATCH] Set Python shell in Org edit buffer Liu Hui
2023-12-05 11:51 ` Ihor Radchenko
2023-12-06  4:41   ` Liu Hui
2023-12-06 13:23     ` Ihor Radchenko
2023-12-07  4:45       ` Liu Hui
2023-12-07 10:36         ` Ihor Radchenko
2023-12-07 14:17           ` Liu Hui
2023-12-07 15:19             ` Ihor Radchenko
2023-12-08 10:19               ` Liu Hui
2023-12-08 13:09                 ` Ihor Radchenko
2023-12-09  2:33                   ` Liu Hui
2023-12-09 10:32                     ` Ihor Radchenko
2023-12-09 13:36                       ` Liu Hui
2023-12-27  6:04                         ` Jack Kamm
2023-12-28 11:48                           ` Ihor Radchenko
2023-12-31 18:31                             ` Jack Kamm
2024-01-05 13:45                               ` Ihor Radchenko
2024-01-05 23:29                                 ` Christopher M. Miles
2024-01-12 11:58                                   ` [ob-clojure] Clojure sessions in Org Src buffers (was: [PATCH] Set Python shell in Org edit buffer) Ihor Radchenko
2024-01-07  6:07                                 ` Jack Kamm [this message]
2024-01-07 12:54                                   ` [PATCH] Set Python shell in Org edit buffer Ihor Radchenko
2024-01-07 19:06                                     ` Jack Kamm
2024-01-07 23:14                                       ` William Denton
2024-01-08 12:26                                       ` Ihor Radchenko
2024-01-09  4:09                                         ` Jack Kamm
2024-01-09  4:25                                           ` Jack Kamm
2024-01-09 18:16                                           ` Ihor Radchenko
2024-01-10  6:21                                             ` Jack Kamm
2024-01-10 12:18                                               ` [FR] Add buffer-local setting to request specific ESS process/session name (was: [PATCH] Set Python shell in Org edit buffer) Ihor Radchenko
2024-01-10 19:14                                                 ` Sparapani, Rodney
2024-01-10 19:15                                                   ` Sparapani, Rodney
2024-01-10 19:31                                                     ` Ihor Radchenko
2024-01-10 19:39                                                       ` Sparapani, Rodney
2024-01-10 20:15                                                         ` Ihor Radchenko
2024-01-10 21:44                                                           ` [External] " Richard M. Heiberger
2024-01-10 21:53                                                             ` Ihor Radchenko
2024-01-21 11:48                                                           ` [PATCH] " Ihor Radchenko
2024-01-21 18:21                                                             ` Sparapani, Rodney
2024-01-22 12:13                                                               ` Ihor Radchenko
2024-01-22 13:46                                                                 ` Martin Maechler
2024-01-25 13:09                                                                   ` Ihor Radchenko
2024-01-25 15:23                                                                     ` Sparapani, Rodney
2024-01-25 15:33                                                                       ` Ihor Radchenko
2024-01-25 15:42                                                                         ` Sparapani, Rodney
2024-01-25 22:47                                                                           ` Ihor Radchenko
2024-01-10 12:19                                               ` [PATCH] Set Python shell in Org edit buffer Ihor Radchenko
2024-01-14 17:23                                                 ` Jack Kamm
2024-01-16 13:49                                                   ` Ihor Radchenko
2024-01-16 16:05                                                     ` Jack Kamm
2024-01-28 19:12                                                       ` Ihor Radchenko
2024-01-29  4:23                                                         ` Jack Kamm
2023-12-27  6:07                       ` Jack Kamm
2023-12-28 11:51                         ` Ihor Radchenko
2023-12-29 16:04                           ` Jack Kamm
2023-12-31 13:05                             ` Ihor Radchenko
2023-12-31 18:14                               ` Jack Kamm
2024-01-05 14:00                                 ` Ihor Radchenko
2023-12-29 22:20                 ` Jack Kamm
2023-12-30  7:08                   ` Liu Hui
2024-01-28 20:35         ` Ihor Radchenko
2024-01-29  4:21           ` Jack Kamm
2024-01-29 13:31             ` Ihor Radchenko

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=87o7dxu15h.fsf@gmail.com \
    --to=jackkamm@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=liuhui1610@gmail.com \
    --cc=yantar92@posteo.net \
    /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.