Explorar o código

Fix indentation bug

* lisp/org.el (org--get-expected-indentation): Correctly indent line
  when last element in an item is not a greater element.
* testing/lisp/test-org.el (test-org/indent-line): Add test.
Nicolas Goaziou %!s(int64=7) %!d(string=hai) anos
pai
achega
3502e6fa7c
Modificáronse 2 ficheiros con 28 adicións e 25 borrados
  1. 6 6
      lisp/org.el
  2. 22 19
      testing/lisp/test-org.el

+ 6 - 6
lisp/org.el

@@ -22876,16 +22876,16 @@ ELEMENT."
 	   (org--get-expected-indentation element t))
 	  ;; POS is after contents in a greater element.  Indent like
 	  ;; the beginning of the 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.  If that last element is an item, indent like its
-	  ;; contents.
-	  ((and (not (eq type 'paragraph))
+	  ((and (memq type org-element-greater-elements)
 		(let ((cend (org-element-property :contents-end element)))
 		  (and cend (<= cend pos))))
+	   ;; As a special case, if point is at the end of a footnote
+	   ;; definition or an item, indent like the very last element
+	   ;; within.  If that last element is an item, indent like
+	   ;; its contents.
 	   (if (memq type '(footnote-definition item plain-list))
 	       (let ((last (org-element-at-point)))
+		 (goto-char pos)
 		 (org--get-expected-indentation
 		  last (eq (org-element-type last) 'item)))
 	     (goto-char start)

+ 22 - 19
testing/lisp/test-org.el

@@ -785,27 +785,31 @@
       (org-test-with-temp-text "- A\n  B\n\n<point>"
 	(let ((org-adapt-indentation nil)) (org-indent-line))
 	(org-get-indentation))))
+  (should
+   (= 2
+      (org-test-with-temp-text
+	  "- A\n  \begin{cases}    1 + 1\n  \end{cases}\n\n<point>"
+	(let ((org-adapt-indentation nil)) (org-indent-line))
+	(org-get-indentation))))
   ;; Likewise, on a blank line at the end of a footnote definition,
   ;; indent at column 0 if line belongs to the definition.  Otherwise,
   ;; indent like the definition itself.
   (should
    (zerop
-    (org-test-with-temp-text "* H\n[fn:1] Definition\n"
-      (goto-char (point-max))
+    (org-test-with-temp-text "* H\n[fn:1] Definition\n<point>"
       (let ((org-adapt-indentation t)) (org-indent-line))
       (org-get-indentation))))
   (should
    (zerop
-    (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n"
-      (goto-char (point-max))
+    (org-test-with-temp-text "* H\n[fn:1] Definition\n\n\n\n<point>"
       (let ((org-adapt-indentation t)) (org-indent-line))
       (org-get-indentation))))
   ;; After the end of the contents of a greater element, indent like
   ;; the beginning of the element.
   (should
    (= 1
-      (org-test-with-temp-text " #+BEGIN_CENTER\n  Contents\n#+END_CENTER"
-	(forward-line 2)
+      (org-test-with-temp-text
+	  " #+BEGIN_CENTER\n  Contents\n<point>#+END_CENTER"
 	(org-indent-line)
 	(org-get-indentation))))
   ;; On blank lines after a paragraph, indent like its last non-empty
@@ -820,20 +824,18 @@
   ;; according to parent.
   (should
    (= 2
-      (org-test-with-temp-text "A\n\n  B\n\nC"
-	(goto-char (point-max))
+      (org-test-with-temp-text "A\n\n  B\n\nC<point>"
 	(org-indent-line)
 	(org-get-indentation))))
   (should
    (= 1
-      (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC"
-	(goto-char (point-max))
+      (org-test-with-temp-text " A\n\n[fn:1] B\n\n\nC<point>"
 	(org-indent-line)
 	(org-get-indentation))))
   (should
    (= 1
-      (org-test-with-temp-text " #+BEGIN_CENTER\n  Contents\n#+END_CENTER"
-	(forward-line 1)
+      (org-test-with-temp-text
+	  " #+BEGIN_CENTER\n<point>  Contents\n#+END_CENTER"
 	(org-indent-line)
 	(org-get-indentation))))
   ;; Within code part of a source block, use language major mode if
@@ -841,16 +843,16 @@
   ;; according to line above.
   (should
    (= 6
-      (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
-	(forward-line 2)
+      (org-test-with-temp-text
+	  "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
 	(let ((org-src-tab-acts-natively t)
 	      (org-edit-src-content-indentation 0))
 	  (org-indent-line))
 	(org-get-indentation))))
   (should
    (= 1
-      (org-test-with-temp-text "#+BEGIN_SRC emacs-lisp\n (and A\nB)\n#+END_SRC"
-	(forward-line 2)
+      (org-test-with-temp-text
+	  "#+BEGIN_SRC emacs-lisp\n (and A\n<point>B)\n#+END_SRC"
 	(let ((org-src-tab-acts-natively nil)
 	      (org-edit-src-content-indentation 0))
 	  (org-indent-line))
@@ -858,15 +860,16 @@
   ;; Otherwise, indent like the first non-blank line above.
   (should
    (zerop
-    (org-test-with-temp-text "#+BEGIN_CENTER\nline1\n\n  line2\n#+END_CENTER"
-      (forward-line 3)
+    (org-test-with-temp-text
+	"#+BEGIN_CENTER\nline1\n\n<point>  line2\n#+END_CENTER"
       (org-indent-line)
       (org-get-indentation))))
   ;; Align node properties according to `org-property-format'.  Handle
   ;; nicely empty values.
   (should
    (equal "* H\n:PROPERTIES:\n:key:      value\n:END:"
-	  (org-test-with-temp-text "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
+	  (org-test-with-temp-text
+	      "* H\n:PROPERTIES:\n<point>:key: value\n:END:"
 	    (let ((org-property-format "%-10s %s")) (org-indent-line))
 	    (buffer-string))))
   (should