From 295b28fece2f2125b40635118a5a705af4c8ce74 Mon Sep 17 00:00:00 2001 From: Liu Hui 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