emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Liu Hui <liuhui1610@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] Set Python shell in Org edit buffer
Date: Wed, 6 Dec 2023 12:41:43 +0800	[thread overview]
Message-ID: <CAOQTW-PbaboFxVuRpco-_3hQtn4ASmrts-8mNQdfkU8j5dVSqg@mail.gmail.com> (raw)
In-Reply-To: <87zfyosw8n.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 1394 bytes --]

Ihor Radchenko <yantar92@posteo.net> 于2023年12月5日周二 19:48写道:
>
> Liu Hui <liuhui1610@gmail.com> writes:
>
> > When editing python src block using C-c ', the python shell is not set
> > in Org edit buffer according to the :session header argument of the
> > block. Consequently, commands such as python-shell-send-region cannot
> > send python code to the correct python process. To address this, the
> > attached patch defines org-babel-edit-prep:python in ob-python.el.
>
> Makes sense.
> I think we may drop a note about this new feature in ORG-NEWS.

Thanks, I have added it in the attached patch.

> > In addition, I tried to use org-src-associate-babel-session at first,
> > but found it doesn't work because it is called when enabling
> > org-src-mode, where org-src--babel-info is still nil. It seems it has
> > stopped working since 203bf5870, and I think it is safe to remove it
> > and related stuffs to avoid confusion.
>
> I do not see it being used much, except
> https://github.com/frederic-santos/ob-ess-julia and
> https://github.com/alphapapa/outshine
> Although, ob-ess-julia is deprecated and outshine only mentions this in
> "TODO" comment.
>
> To be safe, I'd prefer to mark `org-src-associate-babel-session'
> obsolete and mention the removal in ORG-NEWS, pointing users to
> `org-babel-edit-prep:..' instead.

Fine by me.

[-- Attachment #2: 0001-Set-Python-shell-in-Org-edit-buffer.patch --]
[-- Type: text/x-patch, Size: 1857 bytes --]

From 295b28fece2f2125b40635118a5a705af4c8ce74 Mon Sep 17 00:00:00 2001
From: Liu Hui <liuhui1610@gmail.com>
Date: Tue, 5 Dec 2023 11:40:38 +0800
Subject: [PATCH] Set Python shell in Org edit buffer

* lisp/ob-python.el (org-babel-edit-prep:python): New function.
* etc/ORG-NEWS (ob-python now sets ~python-shell-buffer-name~ in Org
edit buffers): Announce the change.
---
 etc/ORG-NEWS      | 6 ++++++
 lisp/ob-python.el | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index aef7e1184..826ea3526 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -640,6 +640,12 @@ return a matplotlib Figure object to plot. For output results, the
 current figure (as returned by =pyplot.gcf()=) is cleared before
 evaluation, and then plotted afterwards.
 
+*** ob-python now sets ~python-shell-buffer-name~ in Org edit buffers
+
+When editing a Python src block, the editing buffer is now associated
+with the Python shell specified by the src block's ~:session~ header
+argument.
+
 *** =ob-maxima.el=: Support for ~batch~ and ~draw~
 
 =ob-maxima= has two new header arguments: ~:batch~ and
diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index 6c568a36d..8ff2c7a1d 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -67,6 +67,13 @@ (defcustom org-babel-python-None-to 'hline
   :package-version '(Org . "8.0")
   :type 'symbol)
 
+(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)))))
+
 (defun org-babel-execute:python (body params)
   "Execute Python BODY according to PARAMS.
 This function is called by `org-babel-execute-src-block'."
-- 
2.25.1


  reply	other threads:[~2023-12-06  4:43 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 [this message]
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                                 ` [PATCH] Set Python shell in Org edit buffer Jack Kamm
2024-01-07 12:54                                   ` 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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOQTW-PbaboFxVuRpco-_3hQtn4ASmrts-8mNQdfkU8j5dVSqg@mail.gmail.com \
    --to=liuhui1610@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --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 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).