Browse Source

ob-core: Do not always evaluate Lisp code in parameters

* lisp/ob-core.el (org-babel-get-src-block-info):
(org-babel-params-from-properties):
(org-babel-parse-header-arguments): Add optional argument disabling
Lisp evaluation in parameters.
Nicolas Goaziou 7 years ago
parent
commit
38be851245
1 changed files with 32 additions and 19 deletions
  1. 32 19
      lisp/ob-core.el

+ 32 - 19
lisp/ob-core.el

@@ -577,9 +577,10 @@ the outer-most code block.")
 (defun org-babel-get-src-block-info (&optional light datum)
 (defun org-babel-get-src-block-info (&optional light datum)
   "Extract information from a source block or inline source block.
   "Extract information from a source block or inline source block.
 
 
-Optional argument LIGHT does not resolve remote variable
-references; a process which could likely result in the execution
-of other code blocks.
+When optional argument LIGHT is non-nil, Babel does not resolve
+remote variable references; a process which could likely result
+in the execution of other code blocks, and do not evaluate Lisp
+values in parameters.
 
 
 By default, consider the block at point.  However, when optional
 By default, consider the block at point.  However, when optional
 argument DATUM is provided, extract information from that parsed
 argument DATUM is provided, extract information from that parsed
@@ -610,8 +611,9 @@ a list with the following pattern:
 		       ;; properties applicable to its location within
 		       ;; properties applicable to its location within
 		       ;; the document.
 		       ;; the document.
 		       (org-with-point-at (org-element-property :begin datum)
 		       (org-with-point-at (org-element-property :begin datum)
-			 (org-babel-params-from-properties lang))
-		       (mapcar #'org-babel-parse-header-arguments
+			 (org-babel-params-from-properties lang light))
+		       (mapcar (lambda (h)
+				 (org-babel-parse-header-arguments h light))
 			       (cons (org-element-property :parameters datum)
 			       (cons (org-element-property :parameters datum)
 				     (org-element-property :header datum)))))
 				     (org-element-property :header datum)))))
 	       (or (org-element-property :switches datum) "")
 	       (or (org-element-property :switches datum) "")
@@ -1415,24 +1417,31 @@ portions of results lines."
 	  (lambda () (add-hook 'change-major-mode-hook
 	  (lambda () (add-hook 'change-major-mode-hook
 			  'org-babel-show-result-all 'append 'local)))
 			  'org-babel-show-result-all 'append 'local)))
 
 
-(defvar org-file-properties)
-(defun org-babel-params-from-properties (&optional lang)
-  "Retrieve parameters specified as properties.
-Return a list of association lists of source block params
+(defun org-babel-params-from-properties (&optional lang no-eval)
+  "Retrieve source block parameters specified as properties.
+
+LANG is the language of the source block, as a string.  When
+optional argument NO-EVAL is non-nil, do not evaluate Lisp values
+in parameters.
+
+Return a list of association lists of source block parameters
 specified in the properties of the current outline entry."
 specified in the properties of the current outline entry."
   (save-match-data
   (save-match-data
     (list
     (list
-     ;; header arguments specified with the header-args property at
+     ;; Header arguments specified with the header-args property at
      ;; point of call.
      ;; point of call.
      (org-babel-parse-header-arguments
      (org-babel-parse-header-arguments
       (org-entry-get org-babel-current-src-block-location
       (org-entry-get org-babel-current-src-block-location
 		     "header-args"
 		     "header-args"
-		     'inherit))
-     (and lang	 ; language-specific header arguments at point of call
+		     'inherit)
+      no-eval)
+     ;; Language-specific header arguments at point of call.
+     (and lang
 	  (org-babel-parse-header-arguments
 	  (org-babel-parse-header-arguments
 	   (org-entry-get org-babel-current-src-block-location
 	   (org-entry-get org-babel-current-src-block-location
 			  (concat "header-args:" lang)
 			  (concat "header-args:" lang)
-			  'inherit))))))
+			  'inherit)
+	   no-eval)))))
 
 
 (defun org-babel-balanced-split (string alts)
 (defun org-babel-balanced-split (string alts)
   "Split STRING on instances of ALTS.
   "Split STRING on instances of ALTS.
@@ -1520,9 +1529,11 @@ balanced instances of \"[ \t]:\", set ALTS to ((32 9) . 58)."
 		       (cons el acc))))
 		       (cons el acc))))
 		 list :initial-value nil))))
 		 list :initial-value nil))))
 
 
-(defun org-babel-parse-header-arguments (arg-string)
-  "Parse a string of header arguments returning an alist."
-  (when (> (length arg-string) 0)
+(defun org-babel-parse-header-arguments (string &optional no-eval)
+  "Parse header arguments in STRING.
+When optional argument NO-EVAL is non-nil, do not evaluate Lisp
+in parameters.  Return an alist."
+  (when (org-string-nw-p string)
     (org-babel-parse-multiple-vars
     (org-babel-parse-multiple-vars
      (delq nil
      (delq nil
 	   (mapcar
 	   (mapcar
@@ -1531,10 +1542,12 @@ balanced instances of \"[ \t]:\", set ALTS to ((32 9) . 58)."
 		   "\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]+\\([^ \f\t\n\r\v]+.*\\)"
 		   "\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]+\\([^ \f\t\n\r\v]+.*\\)"
 		   arg)
 		   arg)
 		  (cons (intern (match-string 1 arg))
 		  (cons (intern (match-string 1 arg))
-			(org-babel-read (org-babel-chomp (match-string 2 arg))))
+			(org-babel-read (org-babel-chomp (match-string 2 arg))
+					no-eval))
 		(cons (intern (org-babel-chomp arg)) nil)))
 		(cons (intern (org-babel-chomp arg)) nil)))
-	    (let ((raw (org-babel-balanced-split arg-string '((32 9) . 58))))
-              (cons (car raw) (mapcar (lambda (r) (concat ":" r)) (cdr raw)))))))))
+	    (let ((raw (org-babel-balanced-split string '((32 9) . 58))))
+              (cons (car raw)
+		    (mapcar (lambda (r) (concat ":" r)) (cdr raw)))))))))
 
 
 (defun org-babel-parse-multiple-vars (header-arguments)
 (defun org-babel-parse-multiple-vars (header-arguments)
   "Expand multiple variable assignments behind a single :var keyword.
   "Expand multiple variable assignments behind a single :var keyword.