Browse Source

Started again with lob implementation.

 I'm now proposing to implement it, at least temporarily, as a
degenerate source block (has no body), with interpreter name
'babel'. These 'babel' blocks will use a :srcname header arg to refer
to the source code block that they will use for their body. This
source code block might be in the 'library of babel'. If so it will
use a conventional variable name for its 'main data argument' such as
__data__. Then the babel block (not to be confused with a code block
in the lob) would use :var __data__=ref, where ref is a resource
reference resolved as usual.
Dan Davison 16 years ago
parent
commit
90094f9b7c
2 changed files with 39 additions and 54 deletions
  1. 36 53
      lisp/org-babel-lob.el
  2. 3 1
      lisp/org-babel.el

+ 36 - 53
lisp/org-babel-lob.el

@@ -31,58 +31,41 @@
 ;;; Code:
 (require 'org)
 
-(defvar org-babel-lob-regexp
-  (concat "#\\+babel[ \t]*"
-	  "\\([ \t]+\\([^\n]+\\)\\)?\n") ;; match header arguments
-  "Regexp used to test when on a babel library call line")
-
-(defvar org-babel-lob-inline-regexp nil
-  "Regexp used to test whether at an inline babel library call")
-
-(defun org-babel-lob-execute-maybe ()
-  "Detect if this is a babel library line and if so
-then run `org-babel-lob-execute'."
-  (interactive)
-  (let ((info (org-babel-get-src-block-info)))
-    (if info (progn (org-babel-execute-src-block current-prefix-arg info) t) nil)))
-
-(add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-lob-call)
-
-(defun org-babel-lob-execute ()
-  "Execute an org-babel library function."
-  (interactive))
-  
-(defun org-babel-lob-get-src-block-info ()
-  "This is taken from `org-babel-get-src-block-info'. Maybe we could abstract and unify.
-
-Return the information of the current source block as a list
-of the following form.  (language body header-arguments-alist)"
-  (let ((case-fold-search t) head)
-    (if (setq head (org-babel-lob-where-is-block-head))
-        (save-excursion (goto-char head) (org-babel-lob-parse-lob-line-match))
-      (if (save-excursion ;; inline source block
-            (re-search-backward "[ \f\t\n\r\v]" nil t)
-            (forward-char 1)
-            (looking-at org-babel-lob-inline-regexp))
-          (org-babel-parse-inline-src-block-match)
-        nil)))) ;; indicate that no source block was found
-
-(defun org-babel-lob-parse-lob-line-match ()
-  (list nil ;; no language
-        nil ;; no head
-        (org-combine-plists
-	 org-babel-default-header-args
-	 (org-babel-parse-header-arguments
-	  (org-babel-clean-text-properties
-	   (or (match-string 3) ""))))))
-
-(defun org-babel-lob-where-is-block-head ()
-  "Return point at beginning of #+babel line."
-  (save-excursion
-    (beginning-of-line 1)
-    (and (looking-at org-babel-lob-regexp)
-	 (point))))
-
-
+(defun org-babel-execute:babel (body params)
+  "Execute a library-of-babel block.
+
+  These blocks do not have their own body. Instead they use a :srcname
+  header argument to reference a different source block, whose body
+  they use. Source blocks in the library of babel should use a
+  standard naming scheme for the variable containing the input data
+  for analysis / plotting. E.g. if that variable is always called
+  __data__ then one of these bodyless babel blocks will call a library
+  of babel block using :var __data__=<some reference>
+
+  This function is called by `org-babel-execute-src-block'."
+  (message "executing babel source code block...")
+  (save-window-excursion
+    (let ((srcname (cdr (assoc :srcname params))))
+      
+      ;; now locate the source block specified by srcname (it might be
+      ;; in the library of babel), and construct a new source block
+      ;; as follows:
+      ;;
+      ;; 1. The lang is the lang of the referenced source block
+      ;; 2. The header args are those from the current #+begin_src babel block
+      ;; 3. The body is from the reference source block
+
+      ;; If using a library of babel function, then the
+      ;; resposnsibility id on the caller to name the :var arg(s)
+      ;; correctly. We could adopt a standard name such as __data__
+      ;; for the input data for plotting / analysis. Thus in lob
+      ;; source blocks the data variable would be referred to as
+      ;; __data__ in the code, and the babel block would use :var
+      ;; __data__=<some reference>
+
+      ;; Now execute the constructed source block, ensuring that this
+      ;; buffer receives the appropriate output, and only receives a
+      ;; copy of the referenced source block if requested
+)))
 
 (provide 'org-babel-lob)

+ 3 - 1
lisp/org-babel.el

@@ -86,6 +86,7 @@ sh         Pass command to the shell and display the result
 perl       The perl interpreter
 python     The python interpreter
 ruby       The ruby interpreter
+babel      A degenerate source block (no body) to implement library-of-babel calls
 
 The source block regexp `org-babel-src-block-regexp' is updated
 when a new interpreter is added to this list through the
@@ -99,7 +100,8 @@ lisp code use the `org-babel-add-interpreter' function."
               (const "sh")
 	      (const "perl")
 	      (const "python")
-	      (const "ruby")))
+	      (const "ruby")
+  	      (const "babel")))
 
 ;;; functions
 (defun org-babel-execute-src-block (&optional arg info params)