lisp/org-lint.el (misplaced-heading): New linter

* lisp/org-lint.el (org-lint-misplaced-heading): Add new linter
function to detect heading lines accidentally merged with the line
above.
This commit is contained in:
Ihor Radchenko 2023-12-07 14:18:04 +01:00
parent 6003637a4d
commit a8a0a45d24
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 15 additions and 0 deletions

View File

@ -386,6 +386,17 @@ called with one argument, the key used for comparison."
(t (push (cons key (funcall extract-position datum key)) keys))))))
(dolist (e originals reports) (funcall make-report (cdr e) (car e)))))
(defun org-lint-misplaced-heading (ast)
"Check for accidentally misplaced heading lines."
(org-with-point-at ast
(goto-char (point-min))
(let (result)
;; Heuristics for 2+ level heading not at bol.
(while (re-search-forward (rx (not (any "*\n\r ,")) ;; Not a bol; not escaped ,** heading; not " *** words"
"*" (1+ "*") " ") nil t)
(push (list (match-beginning 0) "Possibly misplaced heading line") result))
result)))
(defun org-lint-duplicate-custom-id (ast)
(org-lint--collect-duplicates
ast
@ -1452,6 +1463,10 @@ AST is the buffer parse tree."
;;; Checkers declaration
(org-lint-add-checker 'misplaced-heading
"Report accidentally misplaced heading lines."
#'org-lint-misplaced-heading :trust 'low)
(org-lint-add-checker 'duplicate-custom-id
"Report duplicates CUSTOM_ID properties"
#'org-lint-duplicate-custom-id