浏览代码

Fix `org-indent-line' on blank lines after a paragraph

* lisp/org.el (org--get-expected-indentation): Properly compute
  expected indentation on blank lines after a paragraph.
(org-indent-line): Update docstring.

* testing/lisp/test-org.el (test-org/indent-line): Add test.
Nicolas Goaziou 10 年之前
父节点
当前提交
6b3aa71061
共有 2 个文件被更改,包括 21 次插入6 次删除
  1. 14 6
      lisp/org.el
  2. 7 0
      testing/lisp/test-org.el

+ 14 - 6
lisp/org.el

@@ -22653,8 +22653,9 @@ ELEMENT."
 	  ;; As a special case, if point is at the end of a footnote
 	  ;; definition or an item, indent like the very last element
 	  ;; within.
-	  ((let ((cend (org-element-property :contents-end element)))
-	     (and cend (<= cend pos)))
+	  ((and (not (eq type 'paragraph))
+		(let ((cend (org-element-property :contents-end element)))
+		  (and cend (<= cend pos))))
 	   (if (memq type '(footnote-definition item plain-list))
 	       (org--get-expected-indentation (org-element-at-point) nil)
 	     (goto-char start)
@@ -22691,15 +22692,22 @@ Indentation is done according to the following rules:
     2. If element has a parent, indent like its contents.  More
        precisely, if parent is an item, indent after the
        description part, if any, or the bullet (see
-       ``org-list-description-max-indent').  Else, indent like
+       `org-list-description-max-indent').  Else, indent like
        parent's first line.
 
     3. Otherwise, indent relatively to current level, if
        `org-adapt-indentation' is non-nil, or to left margin.
 
-  - On a blank line at the end of a plain list, an item, or
-    a footnote definition, indent like the very last element
-    within.
+  - On a blank line at the end of an element, indent according to
+    the type of the element.  More precisely
+
+    1. If element is a plain list, an item, or a footnote
+       definition, indent like the very last element within.
+
+    2. If element is a paragraph, indent like its last non blank
+       line.
+
+    3. Otherwise, indent like its very first line.
 
   - In the code part of a source block, use language major mode
     to indent current line if `org-src-tab-acts-natively' is

+ 7 - 0
testing/lisp/test-org.el

@@ -587,6 +587,13 @@
 	(forward-line 2)
 	(org-indent-line)
 	(org-get-indentation))))
+  ;; On blank lines after a paragraph, indent like its last non-empty
+  ;; line.
+  (should
+   (= 1
+      (org-test-with-temp-text " Paragraph\n\n<point>"
+	(org-indent-line)
+	(org-get-indentation))))
   ;; At the first line of an element, indent like previous element's
   ;; first line, ignoring footnotes definitions and inline tasks, or
   ;; according to parent.