From a8a0a45d241d72e174bb72304b25425f7f874c22 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Thu, 7 Dec 2023 14:18:04 +0100 Subject: [PATCH] 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. --- lisp/org-lint.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lisp/org-lint.el b/lisp/org-lint.el index 511490294..3f49ca75f 100644 --- a/lisp/org-lint.el +++ b/lisp/org-lint.el @@ -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