Hello, all. I would like to contribute this tweak that I have been using in my personal config (though in the form of advice). As with Python, in Ruby there is significant need to be able to specify the Ruby command invoked. For instance when managing dependencies with Bundler (which is very common), in order to resolve imports you need to run `bundle exec ruby` instead of just `ruby`. This patch allows specifying the Ruby command in the same vein as ob-python's :python header arg. This is my first contribution to org-mode, so please let me know if I have missed anything. Thanks, Aaron
Using the :ruby header arg. * lisp/ob-ruby.el (org-babel-execute:ruby): Locally set `org-babel-ruby-command' using a header argument. TINYCHANGE --- lisp/ob-ruby.el | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lisp/ob-ruby.el b/lisp/ob-ruby.el index 669c2eabf..80870c6c0 100644 --- a/lisp/ob-ruby.el +++ b/lisp/ob-ruby.el @@ -74,6 +74,9 @@ This function is called by `org-babel-execute-src-block'." (cdr (assq :session params)))) (result-params (cdr (assq :result-params params))) (result-type (cdr (assq :result-type params))) + (org-babel-ruby-command + (or (cdr (assq :ruby params)) + org-babel-ruby-command)) (full-body (org-babel-expand-body:generic body params (org-babel-variable-assignments:ruby params))) (result (if (member "xmp" result-params) -- 2.28.0
Hi Aaron,
Aaron Madlon-Kay <aaron@madlon-kay.com> writes:
> Using the :ruby header arg.
Applied, thanks!
--
Bastien
[-- Attachment #1: Type: text/plain, Size: 264 bytes --] Brilliant! Thanks very much! -Aaron On Sat, Oct 24, 2020 at 20:39 Bastien <bzg@gnu.org> wrote: > Hi Aaron, > > Aaron Madlon-Kay <aaron@madlon -kay.com <aaron@madlon-kay.com>> writes: > > > Using the :ruby header arg. > > Applied, thanks! > > -- > Bastien > [-- Attachment #2: Type: text/html, Size: 690 bytes --]
[-- Attachment #1: Type: text/plain, Size: 1253 bytes --] > Using the :ruby header arg. > > * lisp/ob-ruby.el (org-babel-execute:ruby): Locally set > `org-babel-ruby-command' using a header argument. > > TINYCHANGE > --- > lisp/ob-ruby.el | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/lisp/ob-ruby.el b/lisp/ob-ruby.el > index 669c2eabf..80870c6c0 100644 > --- a/lisp/ob-ruby.el > +++ b/lisp/ob-ruby.el > @@ -74,6 +74,9 @@ This function is called by `org-babel-execute-src-block'." > (cdr (assq :session params)))) > (result-params (cdr (assq :result-params params))) > (result-type (cdr (assq :result-type params))) > + (org-babel-ruby-command > + (or (cdr (assq :ruby params)) > + org-babel-ruby-command)) > (full-body (org-babel-expand-body:generic > body params (org-babel-variable-assignments:ruby params))) > (result (if (member "xmp" result-params) Thanks, this is a much needed change. But currently it is limited only to non-session code execution. Here is an additional patch that also supports the same feature for session code execution as well: ob-ruby.el: allow specification of session ruby command w/header arg * lisp/ob-ruby.el (org-babel-ruby-initiate-session): Use a header argument to get ruby command. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: ob-ruby-session-command.patch --] [-- Type: text/x-diff, Size: 1805 bytes --] diff --git a/lisp/org/ob-ruby.el b/lisp/org/ob-ruby.el index 1b8088eaee..aa28bf1899 100644 --- a/lisp/org/ob-ruby.el +++ b/lisp/org/ob-ruby.el @@ -51,7 +51,8 @@ org-babel-tangle-lang-exts (defvar org-babel-default-header-args:ruby '()) (defvar org-babel-ruby-command "ruby" - "Name of command to use for executing ruby code.") + "Name of command to use for executing ruby code. +It's possible to override it by using a header argument `:ruby'") (defcustom org-babel-ruby-hline-to "nil" "Replace hlines in incoming tables with this when translating to ruby." @@ -71,7 +72,7 @@ org-babel-execute:ruby "Execute a block of Ruby code with Babel. This function is called by `org-babel-execute-src-block'." (let* ((session (org-babel-ruby-initiate-session - (cdr (assq :session params)))) + (cdr (assq :session params)) params)) (result-params (cdr (assq :result-params params))) (result-type (cdr (assq :result-type params))) (full-body (org-babel-expand-body:generic @@ -147,14 +148,15 @@ org-babel-ruby-table-or-string res) res))) -(defun org-babel-ruby-initiate-session (&optional session _params) +(defun org-babel-ruby-initiate-session (&optional session params) "Initiate a ruby session. If there is not a current inferior-process-buffer in SESSION then create one. Return the initialized session." (unless (string= session "none") (require 'inf-ruby) - (let* ((cmd (cdr (assoc inf-ruby-default-implementation - inf-ruby-implementations))) + (let* ((cmd (cdr (or (assq :ruby params) + (assoc inf-ruby-default-implementation + inf-ruby-implementations)))) (buffer (get-buffer (format "*%s*" session))) (session-buffer (or buffer (save-window-excursion (run-ruby cmd session)
Juri Linkov writes:
> Thanks, this is a much needed change. But currently it is limited only
> to non-session code execution. Here is an additional patch that also
> supports the same feature for session code execution as well:
>
> ob-ruby.el: allow specification of session ruby command w/header arg
>
> * lisp/ob-ruby.el (org-babel-ruby-initiate-session): Use a header argument
> to get ruby command.
Thanks.
I see you applied this today in the Emacs repo (844e82f5a8). I've
ported it to the Org repo, but please avoid doing this in the future.
The preferred method is for development to happen through Org's list and
repo.
I apologize because my word choice in bug#32676 may have caused confusion:
Kyle Meyer writes:
> Kévin Le Gouguec writes:
>
> That said...
>
>> IIUC, Org maintainers prefer for changes to be submitted to
>> emacs-orgmode@gnu.org; they only occasionally dive into
>> bug-gnu-emacs@gnu.org to look for open Org issues.
>
> ...submitting patches on the Org list is of course appreciated,
> particularly for things that target Org rather than being part of a
> tree-wide cleanup.
I think "appreciated" understates how strong the preference is on Org's
side.
[-- Attachment #1: Type: text/plain, Size: 830 bytes --] >> ob-ruby.el: allow specification of session ruby command w/header arg >> >> * lisp/ob-ruby.el (org-babel-ruby-initiate-session): Use a header argument >> to get ruby command. > > I've ported it to the Org repo, but please avoid doing this in the > future. The preferred method is for development to happen through > Org's list and repo. Thanks, point taken. Now in https://github.com/nonsequitur/inf-ruby/issues/121 we came to the conclusion that another patch is needed for ob-ruby.el. This patch should allow sharing the same :session among code blocks for the same root dir only when :session is nil. But in case of a named :session, its commands always should be encapsulated within the buffer with the same name as :session. Therefore I'm submitting the patch here for inclusion to the Org repo. Thanks in advance. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-ob-ruby.el-Don-t-reuse-the-same-buffer-among-differe.patch --] [-- Type: text/x-diff, Size: 1646 bytes --] From a20049fc53f4474b3c6d50da08369dbb67af9c38 Mon Sep 17 00:00:00 2001 From: Juri Linkov <juri@linkov.net> Date: Wed, 25 Nov 2020 21:35:01 +0200 Subject: [PATCH] ob-ruby.el: Don't reuse the same buffer among different named sessions * lisp/ob-ruby.el (org-babel-ruby-initiate-session): Instead of run-ruby that always insists on using the existing buffer, use run-ruby-or-pop-to-buffer that allows using the buffer with the same name as :session header arg. Use the existing buffer returned by inf-ruby-buffer only when :session header arg is nil. https://github.com/nonsequitur/inf-ruby/issues/121 --- lisp/ob-ruby.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lisp/ob-ruby.el b/lisp/ob-ruby.el index 5ad006429..47548ff7b 100644 --- a/lisp/ob-ruby.el +++ b/lisp/ob-ruby.el @@ -40,6 +40,8 @@ (require 'org-macs) (declare-function run-ruby "ext:inf-ruby" (&optional command name)) +(declare-function run-ruby-or-pop-to-buffer "ext:inf-ruby" (command &optional name buffer)) +(declare-function inf-ruby-buffer "ext:inf-ruby" ()) (declare-function xmp "ext:rcodetools" (&optional option)) (defvar inf-ruby-default-implementation) @@ -163,7 +165,10 @@ org-babel-ruby-initiate-session inf-ruby-implementations)))) (buffer (get-buffer (format "*%s*" session))) (session-buffer (or buffer (save-window-excursion - (run-ruby cmd session) + (run-ruby-or-pop-to-buffer + cmd (or session "ruby") + (unless session + (inf-ruby-buffer))) (current-buffer))))) (if (org-babel-comint-buffer-livep session-buffer) (progn (sit-for .25) session-buffer) -- 2.25.1
Juri Linkov writes: > Subject: [PATCH] ob-ruby.el: Don't reuse the same buffer among different named > sessions > > * lisp/ob-ruby.el (org-babel-ruby-initiate-session): Instead of > run-ruby that always insists on using the existing buffer, use > run-ruby-or-pop-to-buffer that allows using the buffer with the > same name as :session header arg. Use the existing buffer > returned by inf-ruby-buffer only when :session header arg is nil. > https://github.com/nonsequitur/inf-ruby/issues/121 Thank you. Sounds good to me. > --- > lisp/ob-ruby.el | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/lisp/ob-ruby.el b/lisp/ob-ruby.el > index 5ad006429..47548ff7b 100644 > --- a/lisp/ob-ruby.el > +++ b/lisp/ob-ruby.el > @@ -40,6 +40,8 @@ > (require 'org-macs) > > (declare-function run-ruby "ext:inf-ruby" (&optional command name)) I think the above line can now be dropped. (No need to resend.) > +(declare-function run-ruby-or-pop-to-buffer "ext:inf-ruby" (command &optional name buffer)) > +(declare-function inf-ruby-buffer "ext:inf-ruby" ()) > (declare-function xmp "ext:rcodetools" (&optional option)) > > (defvar inf-ruby-default-implementation) > @@ -163,7 +165,10 @@ org-babel-ruby-initiate-session > inf-ruby-implementations)))) > (buffer (get-buffer (format "*%s*" session))) > (session-buffer (or buffer (save-window-excursion > - (run-ruby cmd session) > + (run-ruby-or-pop-to-buffer > + cmd (or session "ruby") > + (unless session > + (inf-ruby-buffer))) > (current-buffer))))) Untested on my end, but makes sense as far as I can tell. I'll leave another day or so for any ob-ruby users to give feedback and then apply. Thanks.
Kyle Meyer writes: > Juri Linkov writes: > >> Subject: [PATCH] ob-ruby.el: Don't reuse the same buffer among different named >> sessions [...] > Untested on my end, but makes sense as far as I can tell. I'll leave > another day or so for any ob-ruby users to give feedback and then apply. Pushed (f7e286ab9). Thanks again.
> + (run-ruby-or-pop-to-buffer
> + cmd (or session "ruby")
> + (unless session
> + (inf-ruby-buffer)))
I have just run into an issue with this: If you don't specify :ruby
then `cmd' for me is calculated by
(cdr (assoc inf-ruby-default-implementation inf-ruby-implementations))
which gives the function `inf-ruby--irb-command' as a result.
However `run-ruby-or-pop-to-buffer' expects to get a string only.
I'm not sure if it should be org-mode's responsibility to resolve the
actual command string, or if it should be done by
`run-ruby-or-pop-to-buffer'. (It kind of seems like the latter?)
Any thoughts?
-Aaron
Aaron Madlon-Kay writes: >> + (run-ruby-or-pop-to-buffer >> + cmd (or session "ruby") >> + (unless session >> + (inf-ruby-buffer))) > > I have just run into an issue with this: If you don't specify :ruby > then `cmd' for me is calculated by > > (cdr (assoc inf-ruby-default-implementation inf-ruby-implementations)) > > which gives the function `inf-ruby--irb-command' as a result. > > However `run-ruby-or-pop-to-buffer' expects to get a string only. Thanks for noting this. Indeed it looks like the old call through run-ruby handled this (run-ruby-or-pop-to-buffer (let ((command (or command (cdr (assoc inf-ruby-default-implementation inf-ruby-implementations))))) (if (functionp command) (funcall command) command)) ...) and that's lost with this switch to run-ruby-or-pop-to-buffer. > I'm not sure if it should be org-mode's responsibility to resolve the > actual command string, or if it should be done by > `run-ruby-or-pop-to-buffer'. (It kind of seems like the latter?) > > Any thoughts? Given the current situation, I don't see a good option aside from doing the functionp dance in org-babel-ruby-initiate-session as well. Even if inf-ruby's check was moved downstream of run-ruby-or-pop-to-buffer, I think it'd be good to fix on ob-ruby's end to work with the current inf-ruby. Juri, what do you think?
[-- Attachment #1: Type: text/plain, Size: 742 bytes --] >> I'm not sure if it should be org-mode's responsibility to resolve the >> actual command string, or if it should be done by >> `run-ruby-or-pop-to-buffer'. (It kind of seems like the latter?) >> >> Any thoughts? > > Given the current situation, I don't see a good option aside from doing > the functionp dance in org-babel-ruby-initiate-session as well. Even if > inf-ruby's check was moved downstream of run-ruby-or-pop-to-buffer, I > think it'd be good to fix on ob-ruby's end to work with the current > inf-ruby. > > Juri, what do you think? Thanks for notifying me. I completely agree that the most suitable place to fix would be in org-babel-ruby-initiate-session. So here is a patch that I tested with different org header args: [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-ob-ruby.el-Funcall-command-if-it-s-a-function-from-i.patch --] [-- Type: text/x-diff, Size: 1485 bytes --] From 41218eafa9285844ea4e84c52e265b2c0232c1ba Mon Sep 17 00:00:00 2001 From: Juri Linkov <juri@linkov.net> Date: Sun, 13 Dec 2020 21:21:37 +0200 Subject: [PATCH] ob-ruby.el: Funcall command if it's a function from inf-ruby-implementations * lisp/ob-ruby.el (org-babel-ruby-initiate-session): When 'command' is a function from 'inf-ruby-implementations', use 'funcall' to get a command string for the first arg of 'run-ruby-or-pop-to-buffer'. This is like what 'run-ruby' does. --- lisp/ob-ruby.el | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lisp/ob-ruby.el b/lisp/ob-ruby.el index 5ed29f889..2e33bfa29 100644 --- a/lisp/ob-ruby.el +++ b/lisp/ob-ruby.el @@ -159,13 +159,16 @@ org-babel-ruby-initiate-session then create one. Return the initialized session." (unless (string= session "none") (require 'inf-ruby) - (let* ((cmd (cdr (or (assq :ruby params) - (assoc inf-ruby-default-implementation - inf-ruby-implementations)))) + (let* ((command (cdr (or (assq :ruby params) + (assoc inf-ruby-default-implementation + inf-ruby-implementations)))) (buffer (get-buffer (format "*%s*" session))) (session-buffer (or buffer (save-window-excursion (run-ruby-or-pop-to-buffer - cmd (or session "ruby") + (if (functionp command) + (funcall command) + command) + (or session "ruby") (unless session (inf-ruby-buffer))) (current-buffer))))) -- 2.25.1
Juri Linkov writes: > Thanks for notifying me. I completely agree that the most suitable > place to fix would be in org-babel-ruby-initiate-session. So here > is a patch that I tested with different org header args: [...] > Subject: [PATCH] ob-ruby.el: Funcall command if it's a function from > inf-ruby-implementations > > * lisp/ob-ruby.el (org-babel-ruby-initiate-session): When 'command' > is a function from 'inf-ruby-implementations', use 'funcall' to get > a command string for the first arg of 'run-ruby-or-pop-to-buffer'. > This is like what 'run-ruby' does. Thanks. Pushed (57a70d505), tacking on a Reported-by trailer to the commit message.
On Mon, Dec 14, 2020 at 5:00 AM Kyle Meyer <kyle@kyleam.com> wrote:
> Thanks. Pushed (57a70d505), tacking on a Reported-by trailer to the
> commit message.
Thanks very much! The fix is working for me.
-Aaron