Browse Source

DONE take default values for header args from properties

Eric Schulte 16 years ago
parent
commit
9936814ffc
3 changed files with 43 additions and 7 deletions
  1. 18 3
      lisp/org-babel.el
  2. 15 4
      org-babel.org
  3. 10 0
      test-tangle.org

+ 18 - 3
lisp/org-babel.el

@@ -159,7 +159,7 @@ Optionally supply a value for INFO in the form returned by
 Optionally supply a value for PARAMS which will be merged with
 the header arguments specified at the source code block."
   (interactive)
-  (message "supplied params=%S" params)
+  ;; (message "supplied params=%S" params) ;; debugging
   (let* ((info (or info (org-babel-get-src-block-info)))
          (lang (first info))
          (body (second info))
@@ -170,7 +170,7 @@ the header arguments specified at the source code block."
 	 (result-type (fourth processed-params))
          (cmd (intern (concat "org-babel-execute:" lang)))
          result)
-    (message "params=%S" params) ;; debugging statement
+    ;; (message "params=%S" params) ;; debugging statement
     (unless (member lang org-babel-interpreters)
       (error "Language is not in `org-babel-interpreters': %s" lang))
     (when arg (setq result-params (cons "silent" result-params)))
@@ -197,7 +197,7 @@ concerned with creating elisp versions of results. "
 
   (if (and (member "vector" result-params) (not (listp result)))
       (list (list result))
-         result))
+    result))
 
 (defun org-babel-execute-buffer (&optional arg)
   "Replace EVAL snippets in the entire buffer."
@@ -265,6 +265,19 @@ of the following form.  (language body header-arguments-alist)"
        (save-match-data ,@body)
        (goto-char (match-end 0)))))
 
+(defun org-babel-params-from-properties ()
+  "Return an association list of any source block params which
+may be specified in the properties of the current outline entry."
+  (let ((org-babel-header-args '("results" "exports" "tangle")))
+    (delq nil
+          (mapcar
+           (lambda (header-arg)
+             (let ((val (org-entry-get (point) header-arg)))
+               (when val
+                 ;; (message "param-from-property %s=%s" header-arg val) ;; debugging statement
+                 (cons (intern (concat ":" header-arg)) val))))
+           org-babel-header-args))))
+
 (defun org-babel-parse-src-block-match ()
   (let* ((lang (org-babel-clean-text-properties (match-string 1)))
          (lang-headers (intern (concat "org-babel-default-header-args:" lang))))
@@ -272,6 +285,7 @@ of the following form.  (language body header-arguments-alist)"
 	  (org-babel-strip-protective-commas (org-babel-clean-text-properties (match-string 4)))
 	  (org-babel-merge-params
 	   org-babel-default-header-args
+           (org-babel-params-from-properties)
 	   (if (boundp lang-headers) (eval lang-headers) nil)
 	   (org-babel-parse-header-arguments (org-babel-clean-text-properties (or (match-string 3) "")))))))
 
@@ -282,6 +296,7 @@ of the following form.  (language body header-arguments-alist)"
           (org-babel-strip-protective-commas (org-babel-clean-text-properties (match-string 4)))
           (org-babel-merge-params
            org-babel-default-inline-header-args
+           (org-babel-params-from-properties)
            (if (boundp lang-headers) (eval lang-headers) nil)
            (org-babel-parse-header-arguments (org-babel-clean-text-properties (or (match-string 3) "")))))))
 

+ 15 - 4
org-babel.org

@@ -207,7 +207,7 @@ would then be [[#sandbox][the sandbox]].
 #+end_src
 
 
-* Tasks [37/58]
+* Tasks [38/58]
 ** PROPOSED raise elisp error when source-blocks return errors
 Not sure how/if this would work, but it may be desirable.
 
@@ -257,9 +257,6 @@ but with preference given to
    With a file-local variable setting, yea that makes sense.  Maybe
    the header should reference the related org-mode file.
 
-** TODO take default values for header args from properties
-   Use file-wide and subtree wide properties to set default values for
-   header args.
 ** TODO support for working with =*Org Edit Src Example*= buffers [2/4]
 *** TODO optionally evaluate header references when we switch to =*Org Edit Src*= buffer
 That seems to imply that the header references need to be evaluated
@@ -931,6 +928,20 @@ to the command if BUFF is not given.)
     2) The function is called inside of a =write.table= function call
        writing the results to a table
     3) The table is read using =org-table-import=
+
+** DONE take default values for header args from properties
+   Use file-wide and subtree wide properties to set default values for
+   header args.
+
+*** I have non-standard properties
+    :PROPERTIES:
+    :results:  silent
+    :END:
+
+#+srcname: test-implement-silent
+#+begin_src emacs-lisp 
+(+ 1 3)
+#+end_src
 ** DONE add =:tangle= family of header arguments
 values are
 - no :: don't include source-code block when tangling

+ 10 - 0
test-tangle.org

@@ -90,3 +90,13 @@ plus_two(holder)
 #+begin_src emacs-lisp :tangle no
   (setq test-tangle-i-should-not-exist "hopefully I'm not included")
 #+end_src
+
+*** Emacs Lisp (not to be tangled)
+    :PROPERTIES:
+    :tangle:   no
+    :END:
+
+#+srcname: i-also-shouldnt-be-tangled
+#+begin_src emacs-lisp 
+  (setq test-tangle-me-either "i also shouldn't be tangled")
+#+end_src