From: Ihor Radchenko <yantar92@posteo.net>
To: Jack Kamm <jackkamm@gmail.com>
Cc: Liu Hui <liuhui1610@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: [PATCH] Set Python shell in Org edit buffer
Date: Tue, 09 Jan 2024 18:16:49 +0000 [thread overview]
Message-ID: <87zfxewewe.fsf@localhost> (raw)
In-Reply-To: <87r0ir2ln8.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 204 bytes --]
Jack Kamm <jackkamm@gmail.com> writes:
>> IMHO, it might be enough to adjust org-babel-R-associate-session as the
>> following
>...
> Otherwise, this looks good to me.
See the attached tentative patch.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-R-ob-julia-Do-not-force-start-session-in-Org-Src-.patch --]
[-- Type: text/x-patch, Size: 5451 bytes --]
From f6fd65f8e80b6efa0a5db084a9c9f94d46e67515 Mon Sep 17 00:00:00 2001
Message-ID: <f6fd65f8e80b6efa0a5db084a9c9f94d46e67515.1704824159.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Tue, 9 Jan 2024 19:08:44 +0100
Subject: [PATCH] ob-R, ob-julia: Do not force-start session in Org Src buffers
* lisp/ob-R.el (org-babel-R-associate-session): Set
`ess-gen-proc-buffer-name-function' to associate the right session
buffer if user requests session interaction from inside Org Src edit
buffer.
(org-babel-edit-prep:R): Remove in favor of
`org-babel-R-associate-session'.
* lisp/ob-julia.el (org-babel-julia-associate-session): Implement
analogous functionality.
(org-babel-edit-prep:julia): Remove in favor of
`org-babel-julia-associate-session'.
* etc/ORG-NEWS (~org-edit-special~ no longer force-starts session in R
and Julia source blocks): Document the change.
Link: https://orgmode.org/list/87r0ir2ln8.fsf@gmail.com
---
etc/ORG-NEWS | 11 +++++++++++
lisp/ob-R.el | 20 ++++++--------------
lisp/ob-julia.el | 16 +++++++++-------
3 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index b808357d8..245e595ff 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -13,6 +13,17 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
* Version 9.7 (not released yet)
** Important announcements and breaking changes
+*** ~org-edit-special~ no longer force-starts session in R and Julia source blocks
+
+Previously, when R/Julia source block had =:session= header argument
+set to a session name with "earmuffs" (like =*session-name*=),
+~org-edit-special~ always started a session, if it does not exist.
+
+Now, ~org-edit-special~ arranges that a new session with correct name
+is initiated only when user explicitly executes R/Julia-mode commands
+that trigger session interactions. The same session will remain
+available in the context of Org babel.
+
*** ~org-agenda-search-headline-for-time~ now ignores all the timestamp in headings
Previously, ~org-agenda-search-headline-for-time~ made Org agenda
diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 3d13c55a7..4b5cbf7c9 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -91,17 +91,6 @@ (defcustom org-babel-R-command "R --slave --no-save"
:version "24.1"
:type 'string)
-(defvar ess-current-process-name) ; dynamically scoped
-(defvar ess-local-process-name) ; dynamically scoped
-(defun org-babel-edit-prep:R (info)
- "Initiate R session for Org edit buffer, as needed.
-The session name is taken from INFO."
- (let ((session (cdr (assq :session (nth 2 info)))))
- (when (and session
- (string-prefix-p "*" session)
- (string-suffix-p "*" session))
- (org-babel-R-initiate-session session nil))))
-
;; The usage of utils::read.table() ensures that the command
;; read.table() can be found even in circumstances when the utils
;; package is not in the search path from R.
@@ -292,13 +281,16 @@ (defun org-babel-R-initiate-session (session params)
(ess-wait-for-process R-proc)))
(current-buffer))))))
+(defvar ess-current-process-name) ; dynamically scoped
+(defvar ess-local-process-name) ; dynamically scoped
(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))
+ (when-let ((process (get-buffer-process session)))
+ (setq ess-local-process-name (process-name process))
+ (ess-make-buffer-current))
+ (setq-local ess-gen-proc-buffer-name-function (lambda (_) session)))
(defvar org-babel-R-graphics-devices
'((:bmp "bmp" "filename")
diff --git a/lisp/ob-julia.el b/lisp/ob-julia.el
index cddd25e79..10a331e54 100644
--- a/lisp/ob-julia.el
+++ b/lisp/ob-julia.el
@@ -70,12 +70,15 @@ (defvar ess-current-process-name) ; dynamically scoped
(defvar ess-local-process-name) ; dynamically scoped
(defvar ess-eval-visibly-p) ; dynamically scoped
(defvar ess-local-customize-alist); dynamically scoped
-(defun org-babel-edit-prep:julia (info)
- (let ((session (cdr (assq :session (nth 2 info)))))
- (when (and session
- (string-prefix-p "*" session)
- (string-suffix-p "*" session))
- (org-babel-julia-initiate-session session nil))))
+(defvar ess-gen-proc-buffer-name-function) ; defined in ess-inf.el
+(defun org-babel-julia-associate-session (session)
+ "Associate R code buffer with an R session.
+Make SESSION be the inferior ESS process associated with the
+current code buffer."
+ (when-let ((process (get-buffer-process session)))
+ (setq ess-local-process-name (process-name process))
+ (ess-make-buffer-current))
+ (setq-local ess-gen-proc-buffer-name-function (lambda (_) session)))
(defun org-babel-expand-body:julia (body params &optional _graphics-file)
"Expand BODY according to PARAMS, return the expanded body."
@@ -178,7 +181,6 @@ (defun org-babel-julia-assign-elisp (name value)
(format "%s = %s" name (org-babel-julia-quote-csv-field value))))
(defvar ess-ask-for-ess-directory) ; dynamically scoped
-(defvar ess-gen-proc-buffer-name-function) ; defined in ess-inf.el
(defun org-babel-julia-initiate-session (session params)
"If there is not a current julia process then create one."
(unless (string= session "none")
--
2.43.0
[-- Attachment #3: Type: text/plain, Size: 225 bytes --]
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
next prev parent reply other threads:[~2024-01-09 18:49 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 ` [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 [this message]
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=87zfxewewe.fsf@localhost \
--to=yantar92@posteo.net \
--cc=emacs-orgmode@gnu.org \
--cc=jackkamm@gmail.com \
--cc=liuhui1610@gmail.com \
/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).