浏览代码

babel: adding buffer-wide header arguments behind #+BABEL:

e.g. placing the following at the top of your buffer

will result in all source-code blocks in the buffer having their
:session header argument set to "example"

* contrib/babel/lisp/org-babel-lob.el (org-babel-lob-execute): now
  included buffer-wide header arguments in lob header arguments

* contrib/babel/lisp/org-babel.el (org-babel-params-from-buffer): new
  function for grabbing header arguments from the top of the buffer

  (org-babel-parse-src-block-match): now includes buffer-wide header
  arguments

  (org-babel-parse-inline-src-block-match): now includes buffer-wide
  header arguments

  (org-babel-current-buffer-properties): buffer-local variable to hold
  buffer-wide header arguments
Eric Schulte 15 年之前
父节点
当前提交
18be132545
共有 2 个文件被更改,包括 20 次插入0 次删除
  1. 1 0
      contrib/babel/lisp/org-babel-lob.el
  2. 19 0
      contrib/babel/lisp/org-babel.el

+ 1 - 0
contrib/babel/lisp/org-babel-lob.el

@@ -100,6 +100,7 @@ the word 'call'."
 (defun org-babel-lob-execute (info)
   (let ((params (org-babel-merge-params
 		 org-babel-default-header-args
+		 (org-babel-params-from-buffer)
                  (org-babel-params-from-properties)
 		 (org-babel-parse-header-arguments
 		  (org-babel-clean-text-properties

+ 19 - 0
contrib/babel/lisp/org-babel.el

@@ -108,6 +108,9 @@ header arguments as well.")
   '((:session . "none") (:results . "silent") (:exports . "results"))
   "Default arguments to use when evaluating an inline source block.")
 
+(defvar org-babel-current-buffer-properties)
+(make-variable-buffer-local 'org-babel-current-buffer-properties)
+
 (defvar org-babel-src-block-regexp nil
   "Regexp used to test when inside of a org-babel src-block")
 
@@ -610,6 +613,20 @@ may be specified in the properties of the current outline entry."
 		 (setq sym (intern (concat "org-babel-header-arg-names:" lang)))
 		 (and (boundp sym) (eval sym))))))))))
 
+(defun org-babel-params-from-buffer ()
+  "Return an association list of any source block params which
+may be specified at the top of the current buffer."
+  (or org-babel-current-buffer-properties
+      (setq org-babel-current-buffer-properties
+	    (save-excursion
+	      (save-restriction
+		(widen)
+		(goto-char (point-min))
+		(when (re-search-forward
+		       (org-make-options-regexp (list "BABEL")) nil t)
+		  (org-babel-parse-header-arguments
+		   (org-match-string-no-properties 2))))))))
+
 (defun org-babel-parse-src-block-match ()
   (let* ((block-indentation (length (match-string 1)))
 	 (lang (org-babel-clean-text-properties (match-string 2)))
@@ -627,6 +644,7 @@ may be specified in the properties of the current outline entry."
               (buffer-string)))
 	  (org-babel-merge-params
 	   org-babel-default-header-args
+	   (org-babel-params-from-buffer)
            (org-babel-params-from-properties lang)
 	   (if (boundp lang-headers) (eval lang-headers) nil)
 	   (org-babel-parse-header-arguments
@@ -642,6 +660,7 @@ may be specified in the properties of the current outline entry."
            (org-babel-clean-text-properties (match-string 5)))
           (org-babel-merge-params
            org-babel-default-inline-header-args
+	   (org-babel-params-from-buffer)
            (org-babel-params-from-properties lang)
            (if (boundp lang-headers) (eval lang-headers) nil)
            (org-babel-parse-header-arguments