From 4980a9dbb8ff1690abb54066da0827e1c37378c8 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 8 May 2015 10:08:11 +0200 Subject: [PATCH] Fix indentation in empty items * lisp/org.el (org--get-expected-indentation): Fix indentation on in empty items. * testing/lisp/test-org.el (test-org/indent-line): Add test. Reported-by: Leo Ufimtsev --- lisp/org.el | 24 ++++++++++++++---------- testing/lisp/test-org.el | 11 +++++++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 613987699..3f1b6c3ed 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -22747,7 +22747,8 @@ ELEMENT is an element containing point. CONTENTSP is non-nil when indentation is to be computed according to contents of ELEMENT." (let ((type (org-element-type element)) - (start (org-element-property :begin element))) + (start (org-element-property :begin element)) + (post-affiliated (org-element-property :post-affiliated element))) (org-with-wide-buffer (cond (contentsp @@ -22757,14 +22758,8 @@ ELEMENT." (if (not org-adapt-indentation) 0 (let ((level (org-current-level))) (if level (1+ level) 0)))) - (item - (org-list-item-body-column - (org-element-property :post-affiliated element))) - (plain-list - (save-excursion - (goto-char (org-element-property :post-affiliated element)) - (org-get-indentation))) - (otherwise + ((item plain-list) (org-list-item-body-column post-affiliated)) + (t (goto-char start) (org-get-indentation)))) ((memq type '(headline inlinetask nil)) @@ -22825,6 +22820,11 @@ ELEMENT." ((< (line-beginning-position) start) (org--get-expected-indentation (org-element-property :parent element) t)) + ;; Line above is the beginning of an element, i.e., point + ;; was originally on the blank lines between element's start + ;; and contents. + ((= (line-beginning-position) post-affiliated) + (org--get-expected-indentation element t)) ;; POS is after contents in a greater element. Indent like ;; the beginning of the element. ;; @@ -22835,7 +22835,11 @@ ELEMENT." (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) + (let ((last (org-element-at-point))) + (org--get-expected-indentation + last + (memq (org-element-type last) + '(footnote-definition item plain-list)))) (goto-char start) (org-get-indentation))) ;; In any other case, indent like the current line. diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index f490c1052..7d09288f6 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -635,8 +635,9 @@ (let ((org-adapt-indentation t)) (org-indent-line)) (org-get-indentation)))) ;; On blank lines at the end of a list, indent like last element - ;; within it if the line is still in the list. Otherwise, indent - ;; like the whole list. + ;; within it if the line is still in the list. If the last element + ;; is an item, indent like its contents. Otherwise, indent like the + ;; whole list. (should (= 4 (org-test-with-temp-text "* H\n- A\n - AA\n" @@ -649,6 +650,12 @@ (goto-char (point-max)) (let ((org-adapt-indentation t)) (org-indent-line)) (org-get-indentation)))) + (should + (= 4 + (org-test-with-temp-text "* H\n- A\n - \n" + (goto-char (point-max)) + (let ((org-adapt-indentation t)) (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. -- 2.11.4.GIT