emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org 319563cef7 1/2: ob-R, ob-julia: Do not force-start


From: ELPA Syncer
Subject: [elpa] externals/org 319563cef7 1/2: ob-R, ob-julia: Do not force-start session in Org Src buffers
Date: Sun, 28 Jan 2024 15:58:29 -0500 (EST)

branch: externals/org
commit 319563cef7a7117d105d834484ccf2b786e85497
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    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.
    * lisp/org-src.el (org-src-associate-babel-session): Run
    org-babel-<lang>-associate-session even when session is not yet
    initiated.
    
    Link: https://orgmode.org/list/87r0ir2ln8.fsf@gmail.com
---
 etc/ORG-NEWS     | 11 +++++++++++
 lisp/ob-R.el     | 20 ++++++--------------
 lisp/ob-julia.el | 16 +++++++++-------
 lisp/org-src.el  |  1 -
 4 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 1bf7eb5b42..f9c916a9dd 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 (requires ESS 24.01.0 or newer).
+The same session will remain available in the context of Org babel.
+
 *** It is no longer allowed to tangle into the same file as Org source
 
 Previously, =file.org= with the following contents
diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 3d13c55a79..f0d762deca 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -91,17 +91,6 @@ this variable.")
   :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.
@@ -264,6 +253,8 @@ Retrieve variables from PARAMS."
          (t                (format "%s <- %S" name (prin1-to-string value))))))
 
 
+(defvar ess-current-process-name) ; dynamically scoped
+(defvar ess-local-process-name)   ; dynamically scoped
 (defvar ess-ask-for-ess-directory) ; dynamically scoped
 (defvar ess-gen-proc-buffer-name-function) ; defined in ess-inf.el
 (defun org-babel-R-initiate-session (session params)
@@ -296,9 +287,10 @@ Use PARAMS to set default directory when creating a new 
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 cddd25e799..10a331e54d 100644
--- a/lisp/ob-julia.el
+++ b/lisp/ob-julia.el
@@ -70,12 +70,15 @@
 (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 @@ end"
     (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")
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 7a4d2e4cea..14480c8366 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -925,7 +925,6 @@ INFO should be a list similar in format to the return value 
of
   (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))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]