emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bjarte Johansen <bjarte.johansen@infomedia.uib.no>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Make ob-shell conform to the org-babel interface
Date: Wed, 27 May 2015 17:30:27 +0200	[thread overview]
Message-ID: <3651FC40-E9B3-4027-91D7-DD03147591C4@infomedia.uib.no> (raw)

[-- Attachment #1: Type: text/plain, Size: 448 bytes --]

Hi,

I found that ob-shell’s org-babel-variable-assignments:bash function does not respect the interface for org-babel. It takes multiple arguments when it should only take 1. This is a problem when f.ex. org-babel-sha1-hash tries to expand the body of a bash source block and tries to call that function with only 1 argument.

I am not sure if the following patch follows best practices in the project, but it solves the problem for me. 


[-- Attachment #2: 0001-ob-shell-Conform-to-variable-assignment-interface.patch --]
[-- Type: application/octet-stream, Size: 3220 bytes --]

From 04f00e4f69c5352d51b7de1ba8783ddd96124c1f Mon Sep 17 00:00:00 2001
From: Bjarte Johansen <bjarte.johansen@gmail.com>
Date: Wed, 27 May 2015 17:20:41 +0200
Subject: [PATCH] ob-shell: Conform to variable assignment interface

Change org-babel-variable-assignments functions in ob-shell to use the
same function so conform to the interface used for variable assignment
in org-babel.
---
 lisp/ob-shell.el              | 16 ++++++++++------
 testing/lisp/test-ob-shell.el | 11 +++++++++++
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 5b74821..c8db512 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -48,10 +48,14 @@
     (set-default symbol (second value))
     (mapc
      (lambda (name)
-       (eval `(defun ,(intern (concat "org-babel-execute:" name)) (body params)
-		,(format "Execute a block of %s commands with Babel." name)
-		(let ((shell-file-name ,name))
-		  (org-babel-execute:shell body params)))))
+       (eval
+	`(progn
+	   (defun ,(intern (concat "org-babel-execute:" name)) (body params)
+	     ,(format "Execute a block of %s commands with Babel." name)
+	     (let ((shell-file-name ,name))
+	       (org-babel-execute:shell body params)))
+	   (defvar ,(intern (concat "org-babel-variable-assignments:" name))
+	     'org-babel-variable-assignments:sh))))
      (second value))))
 
 (defun org-babel-execute:shell (body params)
@@ -121,7 +125,7 @@ This function is called by `org-babel-execute-src-block'."
      values
      "\n")))
 
-(defun org-babel-variable-assignments:bash (varname values &optional sep hline)
+(defun org-babel--variable-assignments-bash (varname values &optional sep hline)
   "Represents the parameters as useful Bash shell variables."
   (if (listp values)
       (if (and (listp (car values)) (= 1 (length (car values))))
@@ -138,7 +142,7 @@ This function is called by `org-babel-execute-src-block'."
     (mapcar
      (lambda (pair)
        (if (string-match "bash$" shell-file-name)
-	   (org-babel-variable-assignments:bash
+	   (org-babel--variable-assignments-bash
             (car pair) (cdr pair) sep hline)
          (org-babel-variable-assignments:sh-generic
 	  (car pair) (cdr pair) sep hline)))
diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 58a7859..5a050fe 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -27,6 +27,17 @@
 (unless (featurep 'ob-shell)
   (signal 'missing-test-dependency "Support for Shell code blocks"))
 
+(ert-deftest test-ob-shell/should-respect-ob-interface-naming-convention ()
+  "Functions used to interface with the different org-babel
+  should have the correct signature."
+  (dolist (shell org-babel-shell-names)
+    (org-test-with-temp-text
+	(format "#+BEGIN_SRC<point> %s :cache yes
+  echo test
+#+END_SRC" shell)
+      (let ((info (org-babel-get-src-block-info)))
+	(org-babel-sha1-hash info)))))
+
 (ert-deftest test-ob-shell/dont-insert-spaces-on-expanded-bodies ()
   "Expanded shell bodies should not start with a blank line
 unless the body of the tangled block does."
-- 
2.3.2 (Apple Git-55)


             reply	other threads:[~2015-05-27 15:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27 15:30 Bjarte Johansen [this message]
2015-06-01 17:18 ` Make ob-shell conform to the org-babel interface Nicolas Goaziou
2015-06-03 10:58   ` Bjarte Johansen

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=3651FC40-E9B3-4027-91D7-DD03147591C4@infomedia.uib.no \
    --to=bjarte.johansen@infomedia.uib.no \
    --cc=emacs-orgmode@gnu.org \
    /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).