org-lint.el: Add linter checking for independent keywords prior affiliated

* lisp/org-lint.el (org-lint-regular-keyword-before-affiliated):
(combining-keywords-with-affiliated):

Link: https://orgmode.org/list/87ilpj9lv1.fsf@localhost
This commit is contained in:
Ihor Radchenko 2023-12-24 12:43:26 +01:00
parent b8b02e3da3
commit e9ae9dbc54
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 18 additions and 0 deletions

View File

@ -452,6 +452,19 @@ called with one argument, the key used for comparison."
(list (org-element-post-affiliated k)
(format "Orphaned affiliated keyword: \"%s\"" key))))))))
(defun org-lint-regular-keyword-before-affiliated (ast)
(org-element-map ast 'keyword
(lambda (keyword)
(when (= (org-element-post-blank keyword) 0)
(let ((next-element (org-with-point-at (org-element-end keyword)
(org-element-at-point))))
(when (< (org-element-begin next-element) (org-element-post-affiliated next-element))
;; A keyword followed without blank lines by an element with affiliated keywords.
;; The keyword may be confused with affiliated keywords.
(list (org-element-begin keyword)
(format "Independent keyword %s may be confused with affiliated keywords below"
(org-element-property :key keyword)))))))))
(defun org-lint-obsolete-affiliated-keywords (_)
(let ((regexp (format "^[ \t]*#\\+%s:"
(regexp-opt '("DATA" "LABEL" "RESNAME" "SOURCE"
@ -1516,6 +1529,11 @@ AST is the buffer parse tree."
#'org-lint-orphaned-affiliated-keywords
:trust 'low)
(org-lint-add-checker 'combining-keywords-with-affiliated
"Report independent keywords preceding affiliated keywords."
#'org-lint-regular-keyword-before-affiliated
:trust 'low)
(org-lint-add-checker 'obsolete-affiliated-keywords
"Report obsolete affiliated keywords"
#'org-lint-obsolete-affiliated-keywords