0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 19:37:52 +00:00

org-element: Fix property drawers parsing

* lisp/org-element.el (org-element--next-mode): Properly handle first section.
* lisp/org-lint.el (org-lint-obsolete-properties-drawer): Ignore
document-level property drawers.
* testing/lisp/test-org-lint.el (test-org-lint/obsolete-properties-drawer):
Add tests.
This commit is contained in:
Nicolas Goaziou 2020-04-22 16:06:43 +02:00
parent bc90264ac6
commit 4a27b67fd2
3 changed files with 43 additions and 10 deletions

View file

@ -4329,7 +4329,7 @@ located inside the current one. "
(if parent? (if parent?
(pcase type (pcase type
(`headline 'section) (`headline 'section)
(`first-section 'top-comment) ((and `section (guard (eq mode 'first-section))) 'top-comment)
(`inlinetask 'planning) (`inlinetask 'planning)
(`plain-list 'item) (`plain-list 'item)
(`property-drawer 'node-property) (`property-drawer 'node-property)

View file

@ -541,15 +541,16 @@ Use :header-args: instead"
(org-element-map ast 'drawer (org-element-map ast 'drawer
(lambda (d) (lambda (d)
(when (equal (org-element-property :drawer-name d) "PROPERTIES") (when (equal (org-element-property :drawer-name d) "PROPERTIES")
(let ((section (org-element-lineage d '(section)))) (let ((headline? (org-element-lineage d '(headline)))
(unless (org-element-map section 'property-drawer #'identity nil t) (before
(list (org-element-property :post-affiliated d) (mapcar #'org-element-type
(if (save-excursion (assq d (reverse (org-element-contents
(goto-char (org-element-property :post-affiliated d)) (org-element-property :parent d)))))))
(forward-line -1) (list (org-element-property :post-affiliated d)
(or (org-at-heading-p) (org-at-planning-p))) (if (or (and headline? (member before '(nil (planning))))
"Incorrect contents for PROPERTIES drawer" (and (null headline?) (member before '(nil (comment)))))
"Incorrect location for PROPERTIES drawer")))))))) "Incorrect contents for PROPERTIES drawer"
"Incorrect location for PROPERTIES drawer")))))))
(defun org-lint-invalid-effort-property (ast) (defun org-lint-invalid-effort-property (ast)
(org-element-map ast 'node-property (org-element-map ast 'node-property

View file

@ -205,6 +205,32 @@ Paragraph 2"
(ert-deftest test-org-lint/obsolete-properties-drawer () (ert-deftest test-org-lint/obsolete-properties-drawer ()
"Test `org-lint-obsolete-properties-drawer' checker." "Test `org-lint-obsolete-properties-drawer' checker."
(should-not
(org-test-with-temp-text "
* H
:PROPERTIES:
:SOMETHING: foo
:END:"
(org-lint '(obsolete-properties-drawer))))
(should-not
(org-test-with-temp-text "
* H
SCHEDULED: <2012-03-29>
:PROPERTIES:
:SOMETHING: foo
:END:"
(org-lint '(obsolete-properties-drawer))))
(should-not
(org-test-with-temp-text ":PROPERTIES:
:SOMETHING: foo
:END:"
(org-lint '(obsolete-properties-drawer))))
(should-not
(org-test-with-temp-text "# Comment
:PROPERTIES:
:SOMETHING: foo
:END:"
(org-lint '(obsolete-properties-drawer))))
(should (should
(org-test-with-temp-text " (org-test-with-temp-text "
* H * H
@ -218,6 +244,12 @@ Paragraph
* H * H
:PROPERTIES: :PROPERTIES:
This is not a node property This is not a node property
:END:"
(org-lint '(obsolete-properties-drawer))))
(should
(org-test-with-temp-text "Paragraph
:PROPERTIES:
:FOO: bar
:END:" :END:"
(org-lint '(obsolete-properties-drawer))))) (org-lint '(obsolete-properties-drawer)))))