mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-21 06:55:35 +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:
parent
bc90264ac6
commit
4a27b67fd2
@ -4329,7 +4329,7 @@ located inside the current one. "
|
||||
(if parent?
|
||||
(pcase type
|
||||
(`headline 'section)
|
||||
(`first-section 'top-comment)
|
||||
((and `section (guard (eq mode 'first-section))) 'top-comment)
|
||||
(`inlinetask 'planning)
|
||||
(`plain-list 'item)
|
||||
(`property-drawer 'node-property)
|
||||
|
@ -541,15 +541,16 @@ Use :header-args: instead"
|
||||
(org-element-map ast 'drawer
|
||||
(lambda (d)
|
||||
(when (equal (org-element-property :drawer-name d) "PROPERTIES")
|
||||
(let ((section (org-element-lineage d '(section))))
|
||||
(unless (org-element-map section 'property-drawer #'identity nil t)
|
||||
(list (org-element-property :post-affiliated d)
|
||||
(if (save-excursion
|
||||
(goto-char (org-element-property :post-affiliated d))
|
||||
(forward-line -1)
|
||||
(or (org-at-heading-p) (org-at-planning-p)))
|
||||
"Incorrect contents for PROPERTIES drawer"
|
||||
"Incorrect location for PROPERTIES drawer"))))))))
|
||||
(let ((headline? (org-element-lineage d '(headline)))
|
||||
(before
|
||||
(mapcar #'org-element-type
|
||||
(assq d (reverse (org-element-contents
|
||||
(org-element-property :parent d)))))))
|
||||
(list (org-element-property :post-affiliated d)
|
||||
(if (or (and headline? (member before '(nil (planning))))
|
||||
(and (null headline?) (member before '(nil (comment)))))
|
||||
"Incorrect contents for PROPERTIES drawer"
|
||||
"Incorrect location for PROPERTIES drawer")))))))
|
||||
|
||||
(defun org-lint-invalid-effort-property (ast)
|
||||
(org-element-map ast 'node-property
|
||||
|
@ -205,6 +205,32 @@ Paragraph 2"
|
||||
|
||||
(ert-deftest test-org-lint/obsolete-properties-drawer ()
|
||||
"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
|
||||
(org-test-with-temp-text "
|
||||
* H
|
||||
@ -218,6 +244,12 @@ Paragraph
|
||||
* H
|
||||
:PROPERTIES:
|
||||
This is not a node property
|
||||
:END:"
|
||||
(org-lint '(obsolete-properties-drawer))))
|
||||
(should
|
||||
(org-test-with-temp-text "Paragraph
|
||||
:PROPERTIES:
|
||||
:FOO: bar
|
||||
:END:"
|
||||
(org-lint '(obsolete-properties-drawer)))))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user