Browse Source

babel: small change in API.

* lisp/ob-core.el (org-babel--get-vars): New function.
(org-babel-get-header): Delete.
* lisp/ob-C.el (org-babel-C-expand-C):
(org-babel-C-expand-D):
* lisp/ob-R.el (org-babel-variable-assignments:R):
* lisp/ob-abc.el (org-babel-expand-body:abc):
* lisp/ob-asymptote.el (org-babel-variable-assignments:asymptote):
* lisp/ob-awk.el (org-babel-execute:awk):
* lisp/ob-calc.el (org-babel-execute:calc):
* lisp/ob-clojure.el (org-babel-expand-body:clojure):
* lisp/ob-dot.el (org-babel-expand-body:dot):
* lisp/ob-emacs-lisp.el (org-babel-expand-body:emacs-lisp):
* lisp/ob-fortran.el (org-babel-expand-body:fortran):
(org-babel-fortran-ensure-main-wrap):
* lisp/ob-gnuplot.el (org-babel-gnuplot-process-vars):
* lisp/ob-haskell.el (org-babel-variable-assignments:haskell):
* lisp/ob-js.el (org-babel-variable-assignments:js):
* lisp/ob-latex.el (org-babel-expand-body:latex):
* lisp/ob-lilypond.el (org-babel-expand-body:lilypond):
* lisp/ob-lisp.el (org-babel-expand-body:lisp):
* lisp/ob-maxima.el (org-babel-maxima-expand):
* lisp/ob-ocaml.el (org-babel-variable-assignments:ocaml):
* lisp/ob-octave.el (org-babel-variable-assignments:octave):
* lisp/ob-org.el (org-babel-expand-body:org):
* lisp/ob-perl.el (org-babel-variable-assignments:perl):
* lisp/ob-picolisp.el (org-babel-expand-body:picolisp):
* lisp/ob-processing.el (org-babel-variable-assignments:processing):
* lisp/ob-python.el (org-babel-variable-assignments:python):
* lisp/ob-ruby.el (org-babel-variable-assignments:ruby):
* lisp/ob-scheme.el (org-babel-expand-body:scheme):
* lisp/ob-shell.el (org-babel-variable-assignments:shell):
* lisp/ob-shen.el (org-babel-expand-body:shen):
* lisp/ob-sql.el (org-babel-expand-body:sql):
* lisp/ob-sqlite.el (org-babel-expand-body:sqlite): Adapt to change.
* etc/ORG-NEWS: Document change.
Aaron Ecay 3 years ago
parent
commit
0d000f5680

+ 2 - 0
etc/ORG-NEWS

@@ -54,6 +54,8 @@ for upcoming anniversaries (default: 7 days).
 Use ~org-agenda-today-p~ instead.
 *** ~org-element-remove-indentation~ is deprecated.
 Use ~org-remove-indentation~ instead.
+*** ~org-babel-get-header~ is removed.
+Use ~org-babel--get-vars~ or ~assq~ instead.
 ** Removed options
 *** Remove ~org-list-empty-line-terminates-plain-lists~
 Two consecutive blank lines always terminate all levels of current

+ 4 - 4
lisp/ob-C.el

@@ -181,8 +181,8 @@ it's header arguments."
 (defun org-babel-C-expand-C (body params)
   "Expand a block of C or C++ code with org-babel according to
 it's header arguments."
-  (let ((vars (mapcar #'cdr (org-babel-get-header params :var)))
-	(colnames (cdar (org-babel-get-header params :colname-names)))
+  (let ((vars (org-babel--get-vars params))
+	(colnames (cdr (assq :colname-names params)))
 	(main-p (not (string= (cdr (assoc :main params)) "no")))
 	(includes (org-babel-read
 		   (or (cdr (assoc :includes params))
@@ -230,8 +230,8 @@ it's header arguments."
 (defun org-babel-C-expand-D (body params)
   "Expand a block of D code with org-babel according to
 it's header arguments."
-  (let ((vars (mapcar #'cdr (org-babel-get-header params :var)))
-	(colnames (cdar (org-babel-get-header params :colname-names)))
+  (let ((vars (org-babel--get-vars params))
+	(colnames (cdr (assq :colname-names params)))
 	(main-p (not (string= (cdr (assoc :main params)) "no")))
 	(imports (or (cdr (assoc :imports params))
 		     (org-babel-read (org-entry-get nil "imports" t)))))

+ 1 - 1
lisp/ob-R.el

@@ -209,7 +209,7 @@ This function is called by `org-babel-execute-src-block'."
 
 (defun org-babel-variable-assignments:R (params)
   "Return list of R statements assigning the block's variables."
-  (let ((vars (mapcar 'cdr (org-babel-get-header params :var))))
+  (let ((vars (org-babel--get-vars params)))
     (mapcar
      (lambda (pair)
        (org-babel-R-assign-elisp

+ 1 - 1
lisp/ob-abc.el

@@ -42,7 +42,7 @@
 
 (defun org-babel-expand-body:abc (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
+  (let ((vars (org-babel--get-vars params)))
     (mapc
      (lambda (pair)
        (let ((name (symbol-name (car pair)))

+ 1 - 1
lisp/ob-asymptote.el

@@ -86,7 +86,7 @@ Asymptote does not support sessions"
 (defun org-babel-variable-assignments:asymptote (params)
   "Return list of asymptote statements assigning the block's variables."
   (mapcar #'org-babel-asymptote-var-to-asymptote
-	  (mapcar #'cdr (org-babel-get-header params :var))))
+	  (org-babel--get-vars params)))
 
 (defun org-babel-asymptote-var-to-asymptote (pair)
   "Convert an elisp value into an Asymptote variable.

+ 1 - 1
lisp/ob-awk.el

@@ -74,7 +74,7 @@ called by `org-babel-execute-src-block'"
 					    (cadr pair)
 					    (org-babel-awk-var-to-awk
 					     (cddr pair))))
-				  (org-babel-get-header params :var))
+				  (org-babel--get-vars params))
 			  (list in-file))
 			 " ")))
     (org-babel-reassemble-table

+ 1 - 1
lisp/ob-calc.el

@@ -48,7 +48,7 @@
   "Execute a block of calc code with Babel."
   (unless (get-buffer "*Calculator*")
     (save-window-excursion (calc) (calc-quit)))
-  (let* ((vars (mapcar #'cdr (org-babel-get-header params :var)))
+  (let* ((vars (org-babel--get-vars params))
 	 (org--var-syms (mapcar #'car vars))
 	 (var-names (mapcar #'symbol-name org--var-syms)))
     (mapc

+ 1 - 1
lisp/ob-clojure.el

@@ -67,7 +67,7 @@
 
 (defun org-babel-expand-body:clojure (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let* ((vars (mapcar #'cdr (org-babel-get-header params :var)))
+  (let* ((vars (org-babel--get-vars params))
 	 (result-params (cdr (assoc :result-params params)))
 	 (print-level nil) (print-length nil)
 	 (body (org-babel-trim

+ 9 - 9
lisp/ob-core.el

@@ -212,14 +212,14 @@ This string must include a \"%s\" which will be replaced by the results."
    "{\\([^\f\n\r\v]+?\\)}\\)")
   "Regexp used to identify inline src-blocks.")
 
-(defun org-babel-get-header (params key &optional others)
-  "Select only header argument of type KEY from a list.
-Optional argument OTHERS indicates that only the header that do
-not match KEY should be returned."
-  (delq nil
-	(mapcar
-	 (lambda (p) (when (funcall (if others #'not #'identity) (eq (car p) key)) p))
-	 params)))
+(defun org-babel--get-vars (params)
+  "Return the babel variable assignments in PARAMS.
+
+PARAMS is a quasi-alist of header args, whcih may contain
+multiple entries for the key `:var'.  This function returns a
+list of the cdr of all the `:var' entries."
+  (mapcar #'cdr
+	  (org-remove-if (lambda (x) (not (eq (car x) :var))) params)))
 
 (defun org-babel-get-inline-src-block-matches ()
   "Set match data if within body of an inline source block.
@@ -1571,7 +1571,7 @@ shown below.
 				   (if (consp (cdr el))
 				       (cdr el)
 				     (org-babel-ref-parse (cdr el))))
-				 (org-babel-get-header params :var)))
+				 (org-babel--get-vars params)))
 	 (vars-and-names (if (and (assoc :colname-names params)
 				  (assoc :rowname-names params))
 			     (list processed-vars)

+ 1 - 1
lisp/ob-dot.el

@@ -46,7 +46,7 @@
 
 (defun org-babel-expand-body:dot (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
+  (let ((vars (org-babel--get-vars params)))
     (mapc
      (lambda (pair)
        (let ((name (symbol-name (car pair)))

+ 1 - 1
lisp/ob-emacs-lisp.el

@@ -33,7 +33,7 @@
 
 (defun org-babel-expand-body:emacs-lisp (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let* ((vars (mapcar #'cdr (org-babel-get-header params :var)))
+  (let* ((vars (org-babel--get-vars params))
          (result-params (cdr (assoc :result-params params)))
          (print-level nil) (print-length nil)
          (body (if (> (length vars) 0)

+ 2 - 2
lisp/ob-fortran.el

@@ -78,7 +78,7 @@
 (defun org-babel-expand-body:fortran (body params)
   "Expand a block of fortran or fortran code with org-babel according to
 it's header arguments."
-  (let ((vars (mapcar #'cdr (org-babel-get-header params :var)))
+  (let ((vars (org-babel--get-vars params))
         (main-p (not (string= (cdr (assoc :main params)) "no")))
         (includes (or (cdr (assoc :includes params))
                       (org-babel-read (org-entry-get nil "includes" t))))
@@ -107,7 +107,7 @@ it's header arguments."
 (defun org-babel-fortran-ensure-main-wrap (body params)
   "Wrap body in a \"program ... end program\" block if none exists."
   (if (string-match "^[ \t]*program[ \t]*.*" (capitalize body))
-      (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
+      (let ((vars (org-babel--get-vars params)))
 	(if vars (error "Cannot use :vars if `program' statement is present"))
 	body)
     (format "program main\n%s\nend program main\n" body)))

+ 1 - 1
lisp/ob-gnuplot.el

@@ -94,7 +94,7 @@ code."
 		 (if tablep val (mapcar 'list val)))
 	       (org-babel-temp-file "gnuplot-") params)
 	  val))))
-     (mapcar #'cdr (org-babel-get-header params :var)))))
+     (org-babel--get-vars params))))
 
 (defun org-babel-expand-body:gnuplot (body params)
   "Expand BODY according to PARAMS, return the expanded body."

+ 1 - 1
lisp/ob-haskell.el

@@ -130,7 +130,7 @@ then create one.  Return the initialized session."
 	    (format "let %s = %s"
 		    (car pair)
 		    (org-babel-haskell-var-to-haskell (cdr pair))))
-	  (mapcar #'cdr (org-babel-get-header params :var))))
+	  (org-babel--get-vars params)))
 
 (defun org-babel-haskell-var-to-haskell (var)
   "Convert an elisp value VAR into a haskell variable.

+ 1 - 1
lisp/ob-js.el

@@ -134,7 +134,7 @@ specifying a variable of the same value."
   (mapcar
    (lambda (pair) (format "var %s=%s;"
 			  (car pair) (org-babel-js-var-to-js (cdr pair))))
-   (mapcar #'cdr (org-babel-get-header params :var))))
+   (org-babel--get-vars params)))
 
 (defun org-babel-js-initiate-session (&optional session)
   "If there is not a current inferior-process-buffer in SESSION

+ 1 - 1
lisp/ob-latex.el

@@ -80,7 +80,7 @@
                  (regexp-quote (format "%S" (car pair)))
                  (if (stringp (cdr pair))
                      (cdr pair) (format "%S" (cdr pair)))
-                 body))) (mapcar #'cdr (org-babel-get-header params :var)))
+                 body))) (org-babel--get-vars params))
   (org-babel-trim body))
 
 (defun org-babel-execute:latex (body params)

+ 1 - 1
lisp/ob-lilypond.el

@@ -123,7 +123,7 @@ blocks.")
 
 (defun org-babel-expand-body:lilypond (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
+  (let ((vars (org-babel--get-vars params)))
     (mapc
      (lambda (pair)
        (let ((name (symbol-name (car pair)))

+ 1 - 1
lisp/ob-lisp.el

@@ -54,7 +54,7 @@ current directory string."
 
 (defun org-babel-expand-body:lisp (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let* ((vars (mapcar #'cdr (org-babel-get-header params :var)))
+  (let* ((vars (org-babel--get-vars params))
 	 (result-params (cdr (assoc :result-params params)))
 	 (print-level nil) (print-length nil)
 	 (body (org-babel-trim

+ 1 - 1
lisp/ob-maxima.el

@@ -48,7 +48,7 @@
 
 (defun org-babel-maxima-expand (body params)
   "Expand a block of Maxima code according to its header arguments."
-  (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
+  (let ((vars (org-babel--get-vars params)))
     (mapconcat 'identity
 	       (list
 		;; graphic output

+ 1 - 1
lisp/ob-ocaml.el

@@ -121,7 +121,7 @@
   (mapcar
    (lambda (pair) (format "let %s = %s;;" (car pair)
 			  (org-babel-ocaml-elisp-to-ocaml (cdr pair))))
-   (mapcar #'cdr (org-babel-get-header params :var))))
+   (org-babel--get-vars params)))
 
 (defun org-babel-ocaml-elisp-to-ocaml (val)
   "Return a string of ocaml code which evaluates to VAL."

+ 1 - 1
lisp/ob-octave.el

@@ -111,7 +111,7 @@ end")
      (format "%s=%s;"
 	     (car pair)
 	     (org-babel-octave-var-to-octave (cdr pair))))
-   (mapcar #'cdr (org-babel-get-header params :var))))
+   (org-babel--get-vars params)))
 
 (defalias 'org-babel-variable-assignments:matlab
   'org-babel-variable-assignments:octave)

+ 1 - 1
lisp/ob-org.el

@@ -41,7 +41,7 @@
   "Default header inserted during export of org blocks.")
 
 (defun org-babel-expand-body:org (body params)
-  (dolist (var (mapcar #'cdr (org-babel-get-header params :var)))
+  (dolist (var (org-babel--get-vars params))
     (setq body (replace-regexp-in-string
 		(regexp-quote (format "$%s" (car var)))
 		(format "%s" (cdr var))

+ 1 - 1
lisp/ob-perl.el

@@ -63,7 +63,7 @@ This function is called by `org-babel-execute-src-block'."
   (mapcar
    (lambda (pair)
      (org-babel-perl--var-to-perl (cdr pair) (car pair)))
-   (mapcar #'cdr (org-babel-get-header params :var))))
+   (org-babel--get-vars params)))
 
 ;; helper functions
 

+ 1 - 1
lisp/ob-picolisp.el

@@ -80,7 +80,7 @@
 
 (defun org-babel-expand-body:picolisp (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let ((vars (mapcar #'cdr (org-babel-get-header params :var)))
+  (let ((vars (org-babel--get-vars params))
         (print-level nil)
 	(print-length nil))
     (if (> (length vars) 0)

+ 1 - 1
lisp/ob-processing.el

@@ -142,7 +142,7 @@ Processing does not support sessions"
 (defun org-babel-variable-assignments:processing (params)
   "Return list of processing statements assigning the block's variables."
   (mapcar #'org-babel-processing-var-to-processing
-	  (mapcar #'cdr (org-babel-get-header params :var))))
+	  (org-babel--get-vars params)))
 
 (defun org-babel-processing-var-to-processing (pair)
   "Convert an elisp value into a Processing variable.

+ 1 - 1
lisp/ob-python.el

@@ -125,7 +125,7 @@ VARS contains resolved variable references"
      (format "%s=%s"
 	     (car pair)
 	     (org-babel-python-var-to-python (cdr pair))))
-   (mapcar #'cdr (org-babel-get-header params :var))))
+   (org-babel--get-vars params)))
 
 (defun org-babel-python-var-to-python (var)
   "Convert an elisp value to a python variable.

+ 1 - 1
lisp/ob-ruby.el

@@ -121,7 +121,7 @@ This function is called by `org-babel-execute-src-block'."
      (format "%s=%s"
 	     (car pair)
 	     (org-babel-ruby-var-to-ruby (cdr pair))))
-   (mapcar #'cdr (org-babel-get-header params :var))))
+   (org-babel--get-vars params)))
 
 (defun org-babel-ruby-var-to-ruby (var)
   "Convert VAR into a ruby variable.

+ 1 - 1
lisp/ob-scheme.el

@@ -55,7 +55,7 @@
 
 (defun org-babel-expand-body:scheme (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
+  (let ((vars (org-babel--get-vars params)))
     (if (> (length vars) 0)
         (concat "(let ("
                 (mapconcat

+ 1 - 1
lisp/ob-shell.el

@@ -142,7 +142,7 @@ This function is called by `org-babel-execute-src-block'."
             (car pair) (cdr pair) sep hline)
          (org-babel-variable-assignments:sh-generic
 	  (car pair) (cdr pair) sep hline)))
-     (mapcar #'cdr (org-babel-get-header params :var)))))
+     (org-babel--get-vars params))))
 
 (defun org-babel-sh-var-to-sh (var &optional sep hline)
   "Convert an elisp value to a shell variable.

+ 1 - 1
lisp/ob-shen.el

@@ -43,7 +43,7 @@
 
 (defun org-babel-expand-body:shen (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
+  (let ((vars (org-babel--get-vars params)))
     (if (> (length vars) 0)
         (concat "(let "
                 (mapconcat (lambda (var)

+ 1 - 1
lisp/ob-sql.el

@@ -78,7 +78,7 @@
 (defun org-babel-expand-body:sql (body params)
   "Expand BODY according to the values of PARAMS."
   (org-babel-sql-expand-vars
-   body (mapcar #'cdr (org-babel-get-header params :var))))
+   body (org-babel--get-vars params)))
 
 (defun org-babel-sql-dbstring-mysql (host port user password database)
   "Make MySQL cmd line args for database connection.  Pass nil to omit that arg."

+ 1 - 1
lisp/ob-sqlite.el

@@ -53,7 +53,7 @@
 (defun org-babel-expand-body:sqlite (body params)
   "Expand BODY according to the values of PARAMS."
   (org-babel-sqlite-expand-vars
-   body (mapcar #'cdr (org-babel-get-header params :var))))
+   body (org-babel--get-vars params)))
 
 (defvar org-babel-sqlite3-command "sqlite3")