org-indent-line: Fix with line is within blank lines after heading

* lisp/org.el (org-indent-line): Fix when we are within blank lines
after heading.  ELEMENT is then `heading' and looking at :begin - 1
does not make sense.
* testing/lisp/test-org.el (test-org/indent-region): Add test.

Reported-by: Jens Schmidt <jschmidt4gnu@vodafonemail.de>
Link: https://orgmode.org/list/d7129804-1f42-ea2b-85e8-18ea1ee32d73@vodafonemail.de
This commit is contained in:
Ihor Radchenko 2023-06-11 13:16:31 +03:00
parent b29edcaf82
commit 34082ff184
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 15 additions and 5 deletions

View File

@ -19055,13 +19055,16 @@ Also align node properties according to `org-property-format'."
(interactive)
(let* ((element (save-excursion (beginning-of-line) (org-element-at-point-no-context)))
(type (org-element-type element)))
(unless (or (org-at-heading-p)
(unless (or (org-at-heading-p) ; headline has no indent ever.
;; Do not indent first element after headline data.
(and (eq org-adapt-indentation 'headline-data)
(not (org--at-headline-data-p nil element))
(save-excursion
(goto-char (1- (org-element-property :begin element)))
(or (org-at-heading-p)
(org--at-headline-data-p)))))
;; Not at headline data and previous is headline data/headline.
(or (memq type '(headline inlinetask)) ; blank lines after heading
(save-excursion
(goto-char (1- (org-element-property :begin element)))
(or (org-at-heading-p)
(org--at-headline-data-p))))))
(cond ((and (memq type '(plain-list item))
(= (line-beginning-position)
(org-element-property :post-affiliated element)))

View File

@ -1367,6 +1367,13 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46"
(org-test-with-temp-text "* H\nSCHEDULED: <2022-11-03>\nParagraph"
(org-indent-region (point-min) (point-max))
(buffer-string)))))
;; Do not indent empty lines after heading, when no headline data.
(let ((org-adapt-indentation 'headline-data))
(should
(equal "* H1\n\n* H2\n"
(org-test-with-temp-text "* H1\n\n* H2\n<point>"
(org-indent-line)
(buffer-string)))))
(let ((org-adapt-indentation 'headline-data)
(org-log-into-drawer t))
(should