From 3502e6fa7cb304d6b29aef032fe49ea4a79b58f0 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 30 Apr 2017 22:26:10 +0200 Subject: [PATCH] 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. --- lisp/org.el | 12 ++++++------ testing/lisp/test-org.el | 41 +++++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 1a1703265..20f130478 100644 --- a/lisp/org.el +++ b/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) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 3b146be14..fd54b569f 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -785,27 +785,31 @@ (org-test-with-temp-text "- A\n B\n\n" (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" + (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" (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" (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#+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" (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" (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 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\nB)\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\nB)\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 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:key: value\n:END:" + (org-test-with-temp-text + "* H\n:PROPERTIES:\n:key: value\n:END:" (let ((org-property-format "%-10s %s")) (org-indent-line)) (buffer-string)))) (should