Explorar el Código

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 hace 11 años
padre
commit
6b3aa71061
Se han modificado 2 ficheros con 21 adiciones y 6 borrados
  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
 	  ;; As a special case, if point is at the end of a footnote
 	  ;; definition or an item, indent like the very last element
 	  ;; definition or an item, indent like the very last element
 	  ;; within.
 	  ;; 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))
 	   (if (memq type '(footnote-definition item plain-list))
 	       (org--get-expected-indentation (org-element-at-point) nil)
 	       (org--get-expected-indentation (org-element-at-point) nil)
 	     (goto-char start)
 	     (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
     2. If element has a parent, indent like its contents.  More
        precisely, if parent is an item, indent after the
        precisely, if parent is an item, indent after the
        description part, if any, or the bullet (see
        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.
        parent's first line.
 
 
     3. Otherwise, indent relatively to current level, if
     3. Otherwise, indent relatively to current level, if
        `org-adapt-indentation' is non-nil, or to left margin.
        `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
   - In the code part of a source block, use language major mode
     to indent current line if `org-src-tab-acts-natively' is
     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)
 	(forward-line 2)
 	(org-indent-line)
 	(org-indent-line)
 	(org-get-indentation))))
 	(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
   ;; At the first line of an element, indent like previous element's
   ;; first line, ignoring footnotes definitions and inline tasks, or
   ;; first line, ignoring footnotes definitions and inline tasks, or
   ;; according to parent.
   ;; according to parent.