diff --git a/lisp/org.el b/lisp/org.el index 27a394944..28025ea94 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -14180,7 +14180,7 @@ only headings." (level 1) (lmin 1) (lmax 1) - limit re end found pos heading cnt) + limit re end found pos heading cnt flevel) (unless buffer (error "File not found :%s" file)) (with-current-buffer buffer (save-excursion @@ -14195,13 +14195,13 @@ only headings." (while (re-search-forward re end t) (setq level (- (match-end 1) (match-beginning 1))) (if (and (>= level lmin) (<= level lmax)) - (setq found (match-beginning 0) cnt (1+ cnt)))) + (setq found (match-beginning 0) flevel level cnt (1+ cnt)))) (when (= cnt 0) (error "Heading not found on level %d: %s" lmax heading)) (when (> cnt 1) (error "Heading not unique on level %d: %s" lmax heading)) (goto-char found) - (setq lmin (1+ level) lmax (+ lmin (if org-odd-levels-only 1 0))) + (setq lmin (1+ flevel) lmax (+ lmin (if org-odd-levels-only 1 0))) (setq end (save-excursion (org-end-of-subtree t t)))) (when (org-on-heading-p) (move-marker (make-marker) (point))))))))