Browse Source

Fix indentation in source blocks

* lisp/org.el (org-indent-line): Indent source block contents
  according to line above when `org-src-tab-acts-natively' is nil.

* testing/lisp/test-org.el (test-org/indent-line): Update test.
Nicolas Goaziou 11 years ago
parent
commit
f58201b1e1
2 changed files with 12 additions and 11 deletions
  1. 3 3
      lisp/org.el
  2. 9 8
      testing/lisp/test-org.el

+ 3 - 3
lisp/org.el

@@ -22371,6 +22371,7 @@ Also align node properties according to `org-property-format'."
 			 (org-element-property :begin element))))
 	     'noindent)
 	    ((and (eq type 'src-block)
+		  org-src-tab-acts-natively
 		  (> (line-beginning-position)
 		     (org-element-property :post-affiliated element))
 		  (< (line-beginning-position)
@@ -22378,9 +22379,8 @@ Also align node properties according to `org-property-format'."
 		      (goto-char (org-element-property :end element))
 		      (skip-chars-backward " \r\t\n")
 		      (line-beginning-position))))
-	     (if (not org-src-tab-acts-natively) 'noindent
-	       (let ((org-src-strip-leading-and-trailing-blank-lines nil))
-		 (org-babel-do-key-sequence-in-edit-buffer (kbd "TAB")))))
+	     (let ((org-src-strip-leading-and-trailing-blank-lines nil))
+	       (org-babel-do-key-sequence-in-edit-buffer (kbd "TAB"))))
 	    (t
 	     (let ((column (org--get-expected-indentation element nil)))
 	       ;; Preserve current column.

+ 9 - 8
testing/lisp/test-org.el

@@ -556,7 +556,8 @@
 	(org-indent-line)
 	(org-get-indentation))))
   ;; Within code part of a source block, use language major mode if
-  ;; `org-src-tab-acts-natively' is non-nil.  Do nothing otherwise.
+  ;; `org-src-tab-acts-natively' is non-nil.  Otherwise, indent
+  ;; according to line above.
   (should
    (= 6
       (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
@@ -566,13 +567,13 @@
 	  (org-indent-line))
 	(org-get-indentation))))
   (should
-   (zerop
-    (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
-      (forward-line 2)
-      (let ((org-src-tab-acts-natively nil)
-	    (org-edit-src-content-indentation 0))
-	(org-indent-line))
-      (org-get-indentation))))
+   (= 1
+      (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
+	(forward-line 2)
+	(let ((org-src-tab-acts-natively nil)
+	      (org-edit-src-content-indentation 0))
+	  (org-indent-line))
+	(org-get-indentation))))
   ;; Otherwise, indent like the first non-blank line above.
   (should
    (zerop