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
This commit is contained in:
Eric Schulte 2010-06-14 11:55:37 -07:00
parent e9b132d8ba
commit 18be132545
2 changed files with 20 additions and 0 deletions

View File

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

View File

@ -108,6 +108,9 @@ header arguments as well.")
'((:session . "none") (:results . "silent") (:exports . "results")) '((:session . "none") (:results . "silent") (:exports . "results"))
"Default arguments to use when evaluating an inline source block.") "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 (defvar org-babel-src-block-regexp nil
"Regexp used to test when inside of a org-babel src-block") "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))) (setq sym (intern (concat "org-babel-header-arg-names:" lang)))
(and (boundp sym) (eval sym)))))))))) (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 () (defun org-babel-parse-src-block-match ()
(let* ((block-indentation (length (match-string 1))) (let* ((block-indentation (length (match-string 1)))
(lang (org-babel-clean-text-properties (match-string 2))) (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))) (buffer-string)))
(org-babel-merge-params (org-babel-merge-params
org-babel-default-header-args org-babel-default-header-args
(org-babel-params-from-buffer)
(org-babel-params-from-properties lang) (org-babel-params-from-properties lang)
(if (boundp lang-headers) (eval lang-headers) nil) (if (boundp lang-headers) (eval lang-headers) nil)
(org-babel-parse-header-arguments (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-clean-text-properties (match-string 5)))
(org-babel-merge-params (org-babel-merge-params
org-babel-default-inline-header-args org-babel-default-inline-header-args
(org-babel-params-from-buffer)
(org-babel-params-from-properties lang) (org-babel-params-from-properties lang)
(if (boundp lang-headers) (eval lang-headers) nil) (if (boundp lang-headers) (eval lang-headers) nil)
(org-babel-parse-header-arguments (org-babel-parse-header-arguments