From b6643884cba4c62cd2e62647830e9324a35dfebf Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Fri, 5 Jan 2024 14:56:21 +0100 Subject: [PATCH] ob-R, ob-julia: Use `ess-gen-proc-buffer-name-function' to control session buffer name * lisp/ob-R.el (org-babel-R-initiate-session): * lisp/ob-julia.el (org-babel-julia-initiate-session): Do not use the hack with renaming ESS buffer and instead indicate the session buffer name to ESS appropriately through `ess-gen-proc-buffer-name-function'. Link: https://orgmode.org/list/871qb21bp7.fsf@gmail.com --- lisp/ob-R.el | 20 +++++++++----------- lisp/ob-julia.el | 18 ++++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index c48b2cdb7..13a0db7cc 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -265,15 +265,19 @@ Retrieve variables from PARAMS." (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) "Create or return the current R SESSION buffer. Use PARAMS to set default directory when creating a new session." (unless (string= session "none") - (let ((session (or session "*R*")) - (ess-ask-for-ess-directory - (and (boundp 'ess-ask-for-ess-directory) - ess-ask-for-ess-directory - (not (cdr (assq :dir params)))))) + (let* ((session (or session "*R*")) + (ess-ask-for-ess-directory + (and (boundp 'ess-ask-for-ess-directory) + ess-ask-for-ess-directory + (not (cdr (assq :dir params))))) + ;; Make ESS name the process buffer as SESSION. + (ess-gen-proc-buffer-name-function + (lambda (_) session))) (if (org-babel-comint-buffer-livep session) session (save-window-excursion @@ -286,12 +290,6 @@ Use PARAMS to set default directory when creating a new session." ess-current-process-name)))) (while (process-get R-proc 'callbacks) (ess-wait-for-process R-proc))) - (rename-buffer - (if (bufferp session) - (buffer-name session) - (if (stringp session) - session - (buffer-name)))) (current-buffer)))))) (defun org-babel-R-associate-session (session) diff --git a/lisp/ob-julia.el b/lisp/ob-julia.el index 495169da1..1b0d93358 100644 --- a/lisp/ob-julia.el +++ b/lisp/ob-julia.el @@ -178,13 +178,17 @@ 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") - (let ((session (or session "*Julia*")) - (ess-ask-for-ess-directory - (and (bound-and-true-p ess-ask-for-ess-directory) - (not (cdr (assq :dir params)))))) + (let* ((session (or session "*Julia*")) + (ess-ask-for-ess-directory + (and (bound-and-true-p ess-ask-for-ess-directory) + (not (cdr (assq :dir params))))) + ;; Make ESS name the process buffer as SESSION. + (ess-gen-proc-buffer-name-function + (lambda (_) session))) (if (org-babel-comint-buffer-livep session) session ;; FIXME: Depending on `display-buffer-alist', (julia) may end up @@ -198,12 +202,6 @@ end" (set-buffer session)) (org-require-package 'ess "ESS") (set-buffer (julia)) - (rename-buffer - (if (bufferp session) - (buffer-name session) - (if (stringp session) - session - (buffer-name)))) (current-buffer)))))) (defun org-babel-julia-graphical-output-file (params)