From 915e883645a47ba84b8823efa21c859a62f46ed2 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sat, 8 Jun 2024 21:02:40 +0200 Subject: [PATCH] org-lint-misplaced-heading: Reduce false-positive rate * lisp/org-lint.el (org-lint-misplaced-heading): Be more strict matching potential misplaced headings - only do it on another heading and inside paragraphs. Link: https://orgmode.org/list/87a5jv77qs.fsf@gmail.com --- lisp/org-lint.el | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lisp/org-lint.el b/lisp/org-lint.el index 44064fb5c..2d87ae270 100644 --- a/lisp/org-lint.el +++ b/lisp/org-lint.el @@ -388,17 +388,24 @@ called with one argument, the key used for comparison." (dolist (e originals reports) (funcall make-report (cdr e) (car e))))) (defun org-lint-misplaced-heading (ast) - "Check for accidentally misplaced heading lines." + "Check for accidentally misplaced heading lines. +Example: +** Heading 1 +** Heading 2** Oops heading 3 +** Heading 4" (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) - (unless (org-element-type-p - (org-element-at-point) - '(comment-block example-block export-block src-block) - ) ; Inside a block, where the chances to have heading a slim. + ;; Limit false-positive rate by only complaining about + ;; ** Heading** Heading and + ;; ** Oops heading + ;; Paragraph** Oops heading + (when (org-element-type-p + (org-element-at-point) + '(paragraph headline)) (push (list (match-beginning 0) "Possibly misplaced heading line") result))) result)))