|
@@ -543,25 +543,21 @@ match group 9. Other match groups are defined in
|
|
|
|
|
|
(defun org-babel--normalize-body (datum)
|
|
|
"Normalize body for element or object DATUM.
|
|
|
-In particular, remove spurious indentation, final newline
|
|
|
-character and coderef labels when appropriate."
|
|
|
+DATUM is a source block element or an inline source block object.
|
|
|
+Remove final newline character and spurious indentation."
|
|
|
(let* ((value (org-element-property :value datum))
|
|
|
- (body (if (and (> (length value) 1)
|
|
|
- (string-match-p "\n\\'" value))
|
|
|
+ (body (if (string-suffix-p "\n" value)
|
|
|
(substring value 0 -1)
|
|
|
value)))
|
|
|
- (if (eq (org-element-type datum) 'inline-src-block)
|
|
|
- ;; Newline characters and indentation in an inline src-block
|
|
|
- ;; are not meaningful, since they could come from some
|
|
|
- ;; paragraph filling. Treat them as a white space.
|
|
|
- (replace-regexp-in-string "\n[ \t]*" " " body)
|
|
|
- (let ((body (replace-regexp-in-string
|
|
|
- (org-src-coderef-regexp (org-src-coderef-format datum)) ""
|
|
|
- body nil nil 1)))
|
|
|
- (if (or org-src-preserve-indentation
|
|
|
- (org-element-property :preserve-indent datum))
|
|
|
- body
|
|
|
- (org-remove-indentation body))))))
|
|
|
+ (cond ((eq (org-element-type datum) 'inline-src-block)
|
|
|
+ ;; Newline characters and indentation in an inline
|
|
|
+ ;; src-block are not meaningful, since they could come from
|
|
|
+ ;; some paragraph filling. Treat them as a white space.
|
|
|
+ (replace-regexp-in-string "\n[ \t]*" " " body))
|
|
|
+ ((or org-src-preserve-indentation
|
|
|
+ (org-element-property :preserve-indent datum))
|
|
|
+ body)
|
|
|
+ (t (org-remove-indentation body)))))
|
|
|
|
|
|
;;; functions
|
|
|
(defvar org-babel-current-src-block-location nil
|
|
@@ -587,7 +583,7 @@ object instead.
|
|
|
Return nil if point is not on a source block. Otherwise, return
|
|
|
a list with the following pattern:
|
|
|
|
|
|
- (language body header-arguments-alist switches name block-head)"
|
|
|
+ (language body arguments switches name start coderef)"
|
|
|
(let* ((datum (or datum (org-element-context)))
|
|
|
(type (org-element-type datum))
|
|
|
(inline (eq type 'inline-src-block)))
|
|
@@ -616,7 +612,8 @@ a list with the following pattern:
|
|
|
(or (org-element-property :switches datum) "")
|
|
|
name
|
|
|
(org-element-property (if inline :begin :post-affiliated)
|
|
|
- datum))))
|
|
|
+ datum)
|
|
|
+ (and (not inline) (org-src-coderef-format datum)))))
|
|
|
(unless light
|
|
|
(setf (nth 2 info) (org-babel-process-params (nth 2 info))))
|
|
|
(setf (nth 2 info) (org-babel-generate-file-param name (nth 2 info)))
|
|
@@ -667,10 +664,17 @@ block."
|
|
|
((org-babel-confirm-evaluate info)
|
|
|
(let* ((lang (nth 0 info))
|
|
|
(result-params (cdr (assq :result-params params)))
|
|
|
- (body (setf (nth 1 info)
|
|
|
- (if (org-babel-noweb-p params :eval)
|
|
|
- (org-babel-expand-noweb-references info)
|
|
|
- (nth 1 info))))
|
|
|
+ ;; Expand noweb references in BODY and remove any
|
|
|
+ ;; coderef.
|
|
|
+ (body
|
|
|
+ (let ((coderef (nth 6 info))
|
|
|
+ (expand
|
|
|
+ (if (org-babel-noweb-p params :eval)
|
|
|
+ (org-babel-expand-noweb-references info)
|
|
|
+ (nth 1 info))))
|
|
|
+ (if (not coderef) expand
|
|
|
+ (replace-regexp-in-string
|
|
|
+ (org-src-coderef-regexp coderef) "" expand nil nil 1))))
|
|
|
(dir (cdr (assq :dir params)))
|
|
|
(default-directory
|
|
|
(or (and dir (file-name-as-directory (expand-file-name dir)))
|