all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Set Python shell in Org edit buffer
@ 2023-12-05 10:18 Liu Hui
  2023-12-05 11:51 ` Ihor Radchenko
  0 siblings, 1 reply; 62+ messages in thread
From: Liu Hui @ 2023-12-05 10:18 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

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.

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.


Best,
Liu Hui

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

From c8b9c174cf643bd625cedc311d2604e6fc3bb83a 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.
---
 lisp/ob-python.el | 7 +++++++
 1 file changed, 7 insertions(+)

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


[-- Attachment #3: 0001-Remove-org-src-babel-configure-edit-buffer-and-relat.patch --]
[-- Type: text/x-patch, Size: 2328 bytes --]

From f3c0d401de55d7ad8873c18658abd1d9f6b49d77 Mon Sep 17 00:00:00 2001
From: Liu Hui <liuhui1610@gmail.com>
Date: Tue, 5 Dec 2023 11:36:07 +0800
Subject: [PATCH] Remove 'org-src-babel-configure-edit-buffer' and related
 stuffs

The functionality has stopped working since 203bf5870.
org-babel-edit-prep:lang should be used instead.

* lisp/org-src.el (org-src-associate-babel-session):
(org-src-babel-configure-edit-buffer):
* lisp/ob-R.el (org-babel-R-associate-session): Remove.
---
 lisp/ob-R.el    |  8 --------
 lisp/org-src.el | 23 -----------------------
 2 files changed, 31 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index c48b2cdb7..f3cce20b7 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -294,14 +294,6 @@ (defun org-babel-R-initiate-session (session params)
 	       (buffer-name))))
 	  (current-buffer))))))
 
-(defun org-babel-R-associate-session (session)
-  "Associate R code buffer with an R session.
-Make SESSION be the inferior ESS process associated with the
-current code buffer."
-  (setq ess-local-process-name
-	(process-name (get-buffer-process session)))
-  (ess-make-buffer-current))
-
 (defvar org-babel-R-graphics-devices
   '((:bmp "bmp" "filename")
     (:jpg "jpeg" "filename")
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 866ff2dbf..6406b8d29 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -914,29 +914,6 @@ (defun org-src-mode-configure-edit-buffer ()
 
 (add-hook 'org-src-mode-hook #'org-src-mode-configure-edit-buffer)
 
-
-\f
-;;; Babel related functions
-
-(defun org-src-associate-babel-session (info)
-  "Associate edit buffer with comint session.
-INFO should be a list similar in format to the return value of
-`org-babel-get-src-block-info'."
-  (interactive)
-  (let ((session (cdr (assq :session (nth 2 info)))))
-    (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))))))
-
-(defun org-src-babel-configure-edit-buffer ()
-  "Configure src editing buffer."
-  (when org-src--babel-info
-    (org-src-associate-babel-session org-src--babel-info)))
-
-(add-hook 'org-src-mode-hook #'org-src-babel-configure-edit-buffer)
-
 \f
 ;;; Public API
 
-- 
2.25.1


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

end of thread, other threads:[~2024-01-30 13:36 UTC | newest]

Thread overview: 62+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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                                 ` [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

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.