Browse Source

ob-exp: Do not ignore `org-src-preserve-indentation'

* lisp/ob-exp.el (org-babel-exp-process-buffer): Also check
  `org-src-preserve-indentation' to know when to preserve indentation.
* testing/lisp/test-ob-exp.el (ob-export/export-and-indentation): New
  test.

Thanks to John Hendy for reporting it.
Nicolas Goaziou 5 years ago
parent
commit
ac2f516edf
2 changed files with 36 additions and 1 deletions
  1. 3 1
      lisp/ob-exp.el
  2. 33 0
      testing/lisp/test-ob-exp.el

+ 3 - 1
lisp/ob-exp.el

@@ -269,7 +269,9 @@ this template."
 					 (save-excursion (goto-char end)
 							 (line-end-position)))
 			  (insert replacement)
-			  (if (org-element-property :preserve-indent element)
+			  (if (or org-src-preserve-indentation
+				  (org-element-property :preserve-indent
+							element))
 			      ;; Indent only the code block markers.
 			      (save-excursion (skip-chars-backward " \r\t\n")
 					      (indent-line-to ind)

+ 33 - 0
testing/lisp/test-ob-exp.el

@@ -323,6 +323,39 @@ Here is one at the end of a line. =2=
       (org-export-execute-babel-code)
       (buffer-string)))))
 
+(ert-deftest ob-export/export-and-indentation ()
+  "Test indentation of evaluated source blocks during export."
+  ;; No indentation.
+  (should
+   (string-match
+    "^t"
+    (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n t\n#+END_SRC"
+      (let ((indent-tabs-mode t)
+	    (tab-width 1)
+	    (org-src-preserve-indentation nil))
+	(org-export-execute-babel-code)
+	(buffer-string)))))
+  ;; Preserve indentation with "-i" flag.
+  (should
+   (string-match
+    "^ t"
+    (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp -i\n t\n#+END_SRC"
+      (let ((indent-tabs-mode t)
+	    (tab-width 1))
+	(org-export-execute-babel-code)
+	(buffer-string)))))
+  ;; Preserve indentation with a non-nil
+  ;; `org-src-preserve-indentation'.
+  (should
+   (string-match
+    "^ t"
+    (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n t\n#+END_SRC"
+      (let ((indent-tabs-mode t)
+	    (tab-width 1)
+	    (org-src-preserve-indentation t))
+	(org-export-execute-babel-code)
+	(buffer-string))))))
+
 (provide 'test-ob-exp)
 
 ;;; test-ob-exp.el ends here