Browse Source

ob-lob: now working with the new ob-get-src-block-info

  ob-get-src-block-info wasn't correctly returning the name of the
  code block

* lisp/ob-lob.el (org-babel-lob-ingest): now returns the count of
  ingested code blocks

* lisp/ob.el (org-babel-get-src-block-info): walks up possible
  additional header arg lines before checking for the code block name

  (org-babel-merge-params): can now handle empty variables gracefully
Eric Schulte 14 years ago
parent
commit
832dc71f31
3 changed files with 48 additions and 16 deletions
  1. 2 1
      lisp/ob-lob.el
  2. 15 15
      lisp/ob.el
  3. 31 0
      testing/lisp/test-ob-lob.el

+ 2 - 1
lisp/ob-lob.el

@@ -59,7 +59,8 @@ To add files to this list use the `org-babel-lob-ingest' command."
 		      (assq-delete-all source-name org-babel-library-of-babel))
 		      (assq-delete-all source-name org-babel-library-of-babel))
 		lob-ingest-count (1+ lob-ingest-count)))))
 		lob-ingest-count (1+ lob-ingest-count)))))
     (message "%d src block%s added to Library of Babel"
     (message "%d src block%s added to Library of Babel"
-	     lob-ingest-count (if (> lob-ingest-count 1) "s" ""))))
+	     lob-ingest-count (if (> lob-ingest-count 1) "s" ""))
+    lob-ingest-count))
 
 
 (defconst org-babel-lob-call-aliases '("lob" "call")
 (defconst org-babel-lob-call-aliases '("lob" "call")
   "Aliases to call a source block function.
   "Aliases to call a source block function.

+ 15 - 15
lisp/ob.el

@@ -175,22 +175,20 @@ Returns a list
 	  (setq info (org-babel-parse-src-block-match))
 	  (setq info (org-babel-parse-src-block-match))
 	  (setq indent (car (last info)))
 	  (setq indent (car (last info)))
 	  (setq info (butlast info))
 	  (setq info (butlast info))
-	  (forward-line -1)
+	  (while (and (forward-line -1)
+		      (looking-at org-babel-multi-line-header-regexp))
+	    (setf (nth 2 info)
+		  (org-babel-merge-params
+		   (org-babel-parse-header-arguments (match-string 1))
+		   (nth 2 info))))
 	  (when (looking-at org-babel-src-name-w-name-regexp)
 	  (when (looking-at org-babel-src-name-w-name-regexp)
-	    (setq name (org-babel-clean-text-properties (match-string 3)))
+	    (setq name (org-babel-clean-text-properties (match-string 4)))
 	    (when (match-string 5)
 	    (when (match-string 5)
 	      (setf (nth 2 info) ;; merge functional-syntax vars and header-args
 	      (setf (nth 2 info) ;; merge functional-syntax vars and header-args
 		    (org-babel-merge-params
 		    (org-babel-merge-params
 		     (mapcar (lambda (ref) (cons :var ref))
 		     (mapcar (lambda (ref) (cons :var ref))
 			     (org-babel-ref-split-args (match-string 5)))
 			     (org-babel-ref-split-args (match-string 5)))
-		     (nth 2 info)))))
-	  (goto-char head)
-	  (while (and (forward-line -1)
-		      (looking-at org-babel-multi-line-header-regexp))
-	    (setf (nth 2 info)
-		  (org-babel-merge-params
-		   (org-babel-parse-header-arguments (match-string 1))
-		   (nth 2 info)))))
+		     (nth 2 info))))))
       ;; inline source block
       ;; inline source block
       (when (save-excursion (re-search-backward "[ \f\t\n\r\v]" nil t)
       (when (save-excursion (re-search-backward "[ \f\t\n\r\v]" nil t)
 			    (looking-at org-babel-inline-src-block-regexp))
 			    (looking-at org-babel-inline-src-block-regexp))
@@ -1549,11 +1547,13 @@ parameters when merging lists."
                         (:var
                         (:var
 			 (let ((name (if (listp (cdr pair))
 			 (let ((name (if (listp (cdr pair))
 					 (cadr pair)
 					 (cadr pair)
-				       (string-match
-					"^\\([^= \f\t\n\r\v]+\\)[ \t]*="
-					(cdr pair))
-				       (intern (match-string 1 (cdr pair))))))
-			   (unless (member name (mapcar #'car vars))
+				       (and
+					(string-match
+					 "^\\([^= \f\t\n\r\v]+\\)[ \t]*="
+					 (cdr pair))
+					(intern (match-string 1 (cdr pair)))))))
+			   (when (and name
+				      (not (member name (mapcar #'car vars))))
 			     (setq vars (cons (cons name (cdr pair)) vars)))))
 			     (setq vars (cons (cons name (cdr pair)) vars)))))
                         (:results
                         (:results
                          (setq results
                          (setq results

+ 31 - 0
testing/lisp/test-ob-lob.el

@@ -0,0 +1,31 @@
+;;; test-ob-lob.el
+
+;; Copyright (c) 2010 Eric Schulte
+;; Authors: Eric Schulte
+
+;; Released under the GNU General Public License version 3
+;; see: http://www.gnu.org/licenses/gpl-3.0.html
+
+;;;; Comments:
+
+;; Template test file for Org-mode tests
+
+
+;;; Code:
+(let ((load-path (cons (expand-file-name
+			".." (file-name-directory
+			      (or load-file-name buffer-file-name)))
+		       load-path)))
+  (require 'org-test)
+  (require 'org-test-ob-consts))
+
+
+;;; Tests
+(ert-deftest test-ob-lob/ingest ()
+  "Test the ingestion of an org-mode file."
+  (should (< 0 (org-babel-lob-ingest
+		(expand-file-name "babel.org" org-test-example-dir)))))
+
+(provide 'test-ob-lob)
+
+;;; test-ob-lob.el ends here