Просмотр исходного кода

org-babel: splitting `org-babel-pick-name' into it's own function

  also renaming org-babel-manicure-tables to org-babel-disassemble-tables
Eric Schulte 15 лет назад
Родитель
Сommit
b9aa92ba21

+ 2 - 1
contrib/babel/lisp/langs/org-babel-C.el

@@ -125,7 +125,8 @@ called by `org-babel-execute-src-block'."
               (concat tmp-bin-file (if cmdline (concat " " cmdline) ""))
               (current-buffer) 'replace)
              (buffer-string))))
-         (nth 4 processed-params) (nth 5 processed-params))
+         (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+         (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))
       (progn
         (with-current-buffer error-buf
           (goto-char (point-max))

+ 2 - 1
contrib/babel/lisp/langs/org-babel-clojure.el

@@ -271,6 +271,7 @@ last statement in BODY, as elisp."
          (session (org-babel-clojure-initiate-session (first processed-params))))
     (org-babel-reassemble-table
      (org-babel-clojure-evaluate session body (fourth processed-params))
-     (nth 4 processed-params) (nth 5 processed-params))))
+     (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+     (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))))
 
 (provide 'org-babel-clojure)

+ 2 - 1
contrib/babel/lisp/langs/org-babel-emacs-lisp.el

@@ -55,7 +55,8 @@
                                        (member "pp" result-params))
                                    (concat "(pp " body ")") body)
                                ")"))))
-       (nth 4 processed-params) (nth 5 processed-params)))))
+     (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+     (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params)))))))
 
 (provide 'org-babel-emacs-lisp)
 ;;; org-babel-emacs-lisp.el ends here

+ 2 - 1
contrib/babel/lisp/langs/org-babel-haskell.el

@@ -79,7 +79,8 @@
      (case result-type
        (output (mapconcat #'identity (reverse (cdr results)) "\n"))
        (value (org-babel-haskell-table-or-string (car results))))
-     (nth 4 processed-params) (nth 5 processed-params))))
+     (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+     (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))))
 
 (defun org-babel-haskell-read-string (string)
   "Strip \\\"s from around haskell string"

+ 2 - 1
contrib/babel/lisp/langs/org-babel-ocaml.el

@@ -65,7 +65,8 @@
                 (comint-send-input nil t))))
     (org-babel-reassemble-table
      (org-babel-ocaml-parse-output (org-babel-trim (car raw)))
-     (nth 4 processed-params) (nth 5 processed-params))))
+     (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+     (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))))
 
 (defun org-babel-prep-session:ocaml (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."

+ 3 - 1
contrib/babel/lisp/langs/org-babel-octave.el

@@ -64,7 +64,9 @@
 	 (result (org-babel-octave-evaluate session augmented-body result-type matlabp)))
     (or out-file
         (org-babel-reassemble-table
-         result (nth 4 processed-params) (nth 5 processed-params)))))
+         result
+         (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+         (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params)))))))
 
 (defun org-babel-octave-var-to-octave (var)
   "Convert an emacs-lisp variable into an octave variable.

+ 2 - 1
contrib/babel/lisp/langs/org-babel-oz.el

@@ -246,7 +246,8 @@ called by `org-babel-execute-src-block' via multiple-value-bind."
 	  (oz-send-string-expression full-body (if wait-time
 						   wait-time
 						 1)))))
-     (nth 4 processed-params) (nth 5 processed-params))))
+     (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+     (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))))
 
 ;; This function should be used to assign any variables in params in
 ;; the context of the session environment.

+ 2 - 1
contrib/babel/lisp/langs/org-babel-perl.el

@@ -54,7 +54,8 @@ called by `org-babel-execute-src-block'."
 	(session (org-babel-perl-initiate-session session)))
     (org-babel-reassemble-table
      (org-babel-perl-evaluate session full-body result-type)
-     (nth 4 processed-params) (nth 5 processed-params))))
+     (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+     (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))))
 
 (defun org-babel-prep-session:perl (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."

+ 3 - 1
contrib/babel/lisp/langs/org-babel-python.el

@@ -56,7 +56,9 @@ called by `org-babel-execute-src-block'."
          (result (org-babel-python-evaluate session full-body result-type)))
     (or (cdr (assoc :file params))
         (org-babel-reassemble-table
-         result (nth 4 processed-params) (nth 5 processed-params)))))
+         result
+         (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+         (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params)))))))
 
 (defun org-babel-prep-session:python (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."

+ 3 - 1
contrib/babel/lisp/langs/org-babel-ruby.el

@@ -65,7 +65,9 @@ called by `org-babel-execute-src-block'."
          (result (org-babel-ruby-evaluate session full-body result-type)))
     (or (cdr (assoc :file params))
         (org-babel-reassemble-table
-         result (nth 4 processed-params) (nth 5 processed-params)))))
+         result
+         (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+         (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params)))))))
 
 (defun org-babel-prep-session:ruby (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."

+ 2 - 1
contrib/babel/lisp/langs/org-babel-sh.el

@@ -58,7 +58,8 @@ function is called by `org-babel-execute-src-block'."
                       vars "\n") "\n" body "\n\n"))) ;; then the source block body
     (org-babel-reassemble-table
      (org-babel-sh-evaluate session full-body result-type)
-     (nth 4 processed-params) (nth 5 processed-params))))
+     (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+     (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))))
 
 (defun org-babel-prep-session:sh (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."

+ 2 - 1
contrib/babel/lisp/langs/org-babel-sql.el

@@ -72,7 +72,8 @@ called by `org-babel-execute-src-block'."
       (org-table-import out-file nil)
       (org-babel-reassemble-table
        (org-table-to-lisp)
-       (nth 4 processed-params) (nth 5 processed-params)))))
+       (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
+       (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params)))))))
 
 
 (defun org-babel-prep-session:sql (session params)

+ 33 - 31
contrib/babel/lisp/org-babel.el

@@ -607,7 +607,7 @@ may be specified in the properties of the current outline entry."
 
 Return a list (session vars result-params result-type colnames rownames)."
   (let* ((session (cdr (assoc :session params)))
-         (vars-and-names (org-babel-manicure-tables
+         (vars-and-names (org-babel-disassemble-tables
                           (org-babel-ref-variables params)
                           (cdr (assoc :hlines params))
                           (cdr (assoc :colnames params))
@@ -664,39 +664,41 @@ Return a list (session vars result-params result-type colnames rownames)."
                   row)) table)
     table))
 
-(defun org-babel-manicure-tables (vars hlines colnames rownames)
+(defun org-babel-pick-name (names selector)
+  "Select one out of an alist of row or column names."
+  (when names
+    (if (and selector (symbolp selector) (not (equal t selector)))
+        (cdr (assoc selector names))
+      (if (integerp selector)
+          (nth (- selector 1) names)
+        (cdr (car (last names)))))))
+
+(defun org-babel-disassemble-tables (vars hlines colnames rownames)
   "Process the variables in VARS according to the HLINES,
 ROWNAMES and COLNAMES header arguments.  Return a list consisting
 of the vars, cnames and rnames."
-  (flet ((pick (names sel)
-           (when names
-             (if (and sel (symbolp sel) (not (equal t sel)))
-                 (cdr (assoc sel names))
-               (if (integerp sel)
-                   (nth (- sel 1) names)
-                 (cdr (car (last names))))))))
-    (let (cnames rnames)
-      (list
-       (mapcar
-        (lambda (var)
-          (when (listp (cdr var))
-            (when (and (not (equal colnames "no"))
-                       (or colnames (and (equal (second (cdr var)) 'hline)
-                                         (not (member 'hline (cddr (cdr var)))))))
-              (let ((both (org-babel-get-colnames (cdr var))))
-                (setq cnames (cons (cons (car var) (cdr both))
-                                   cnames))
-                (setq var (cons (car var) (car both)))))
-            (when (and rownames (not (equal rownames "no")))
-              (let ((both (org-babel-get-rownames (cdr var))))
-                (setq rnames (cons (cons (car var) (cdr both))
-                                   rnames))
-                (setq var (cons (car var) (car both)))))
-            (when (and hlines (not (equal hlines "yes")))
-              (setq var (cons (car var) (org-babel-del-hlines (cdr var))))))
-          var)
-        vars)
-       (pick cnames colnames) (pick rnames rownames)))))
+  (let (cnames rnames)
+    (list
+     (mapcar
+      (lambda (var)
+        (when (listp (cdr var))
+          (when (and (not (equal colnames "no"))
+                     (or colnames (and (equal (second (cdr var)) 'hline)
+                                       (not (member 'hline (cddr (cdr var)))))))
+            (let ((both (org-babel-get-colnames (cdr var))))
+              (setq cnames (cons (cons (car var) (cdr both))
+                                 cnames))
+              (setq var (cons (car var) (car both)))))
+          (when (and rownames (not (equal rownames "no")))
+            (let ((both (org-babel-get-rownames (cdr var))))
+              (setq rnames (cons (cons (car var) (cdr both))
+                                 rnames))
+              (setq var (cons (car var) (car both)))))
+          (when (and hlines (not (equal hlines "yes")))
+            (setq var (cons (car var) (org-babel-del-hlines (cdr var))))))
+        var)
+      vars)
+     cnames rnames)))
 
 (defun org-babel-reassemble-table (table colnames rownames)
   "Given a TABLE and set of COLNAMES and ROWNAMES add the names